Here is my code:
            int loanAppFundId = 0;
            var loanAppDb = db.LoanApplications.FirstOrDefault(s => s.LoanId == vm.LoanId);
            if (loanAppDb != null)
            {
                if (vm.FundID != null && loanAppDb.FundID !=0)
                {
                    if (loanAppDb.FundID != vm.FundID)
                    {
                        string oldFund = "", newFund = "";
                        loanAppFundId = loanAppDb.FundID;
                        var oFund = db.Funds.Where(s => s.FundID == loanAppFundId);
                    }
                }
            }
In the last line where I'm trying to retrieve fund based on the loanAppFundId is where the exception happens, if I set there 0 or some other variable it proceeds without any issue but whenever I try to set some variable I'm getting the error.
On purpose I initialized variable loanAppFundId with value 0, but again I'm getting error that the reference object is not set to an instance of an object.
If I set some dummy value in the db.Funds.Where query I'm able to get the loanAppDb.FundID value without any issue.
What am I doing wrong? I have multiple checks for the value if it's null or no.
Edit
I am not sure how this one is duplicate since I'm asking with real example, not a generic question.
 
     
    