I'm working with EFCore for the first time, after moving from EF6, and for some reason I keep getting this error:
System.InvalidOperationException: 'Lambda expression used inside Include is not valid.'
Here is my Controller:
public class HomeController : Controller
{
public ActionResult Index()
{
using (var IJ = IJContext.CreateNew(false))
{
var ChargeList = iJ.Charges.Where(charge => charge.CourtCase.CaseNumber == "13457894561")
.Include(charge => charge.ChargeDate)
.ToList();
return View(ChargeList);
}
}
}
Am I missing something important here? Does EFCore handle Lambdas totally differently or something?
Charge
class to the question?ChargeDate
a complex type or just aDateTime
? if it is a datetime why do you whant to include it ?Include
is meant for navigation properties to indicate that you want EF to pull the related data from those tables. IfChargeDate
is just a regular property (and thus just a column in a table) then you don't need to useInclude
..Inlcude()
for pulling in additional complex types/tables?ChargeDate
wouldn't, from a first glance, appear to be a complex type. Edit: I think we all just said the same thing.