I have seen many solution about this error but still I am unable to apply it in my query. Kindly help. Below is my code:
public ActionResult Index()
{
var viewModels = (from pp in db.PlanPackages
//let checkplandurationidifnull = (double?)pp.PlanDuration1 ?? 0
let planduration1 = (from pd in db.PlanDetail
where pp.PlanDuration1 == pd.PlanDetailID
select pd).FirstOrDefault()
let planduration2 = (from pd in db.PlanDetail
where pp.PlanDuration2 == pd.PlanDetailID
select pd).FirstOrDefault()
let planduration3 = (from pd in db.PlanDetail
where pp.PlanDuration3 == pd.PlanDetailID
select pd).FirstOrDefault()
let planduration4 = (from pd in db.PlanDetail
where pp.PlanDuration4 == pd.PlanDetailID
select pd).FirstOrDefault()
select new _PlanDetailPackageDisplay()
{
PlanID1 = pp.PlanID1,
PlanID2 = pp.PlanID2,
PlanID3 = pp.PlanID3,
PlanID4 = pp.PlanID4,
PlanDuration1 = planduration1.durationInMonths,
PlanDuration2 = planduration2.durationInMonths,
PlanDuration3 = planduration3.durationInMonths,
PlanDuration4 = planduration4.durationInMonths,
PlanPrice1 = planduration1.price,
PlanPrice2 = planduration2.price,
PlanPrice3 = planduration3.price,
PlanPrice4 = planduration4.price,
PackageDiscout = pp.discount,
PackageStatus = pp.StatusPlanID
}).ToList();
return View(viewModels);
}
The problem is when pp.PlanDuration1 = 0 then there is no any matching row to check in the table db.PlanDetail:
where pp.PlanDuration1 == pd.PlanDetailID
I was trying to use .Any() and also
let checkplandurationidifnull = (double?)pp.PlanDuration1 ?? 0
But still I am unable to figure it out. Kindly help.