0

I get an error from this code:

var b = content.FormMasterLists.Where(x => x.FormMasterStatus == "pending");

var c = b.Where(x => JsonConvert.DeserializeObject<ApprovalCCB>(x.FormMasterApprovalCcb).Group.SelectMany(x => x.Department).SelectMany(x => x.ApprovalCCBLevel).SelectMany(x => x.Approver).Where(x => x.ApproverEmail == "christ").Any());

But this code runs successfully:

var b = content.FormMasterLists.Where(x => x.FormMasterStatus == "pending").ToList();

var c = b.Where(x => JsonConvert.DeserializeObject<ApprovalCCB>(x.FormMasterApprovalCcb).Group.SelectMany(x => x.Department).SelectMany(x => x.ApprovalCCBLevel).SelectMany(x => x.Approver).Where(x => x.ApproverEmail == "christ").Any());

Is there any way to declare .Where without List()?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Is there any way to declare .Where without List()?

No way in such implementation. EF Core cannot convert JsonConvert.DeserializeObject to the SQL and provide needed filtering on the server side.

So you have to materialise objects to IEnumerable and use client side filtering.

Anyway some databases provide filtering based on JSON content but then you have to create appropriate extension function for EF Core.

Svyatoslav Danyliv
  • 21,911
  • 3
  • 16
  • 32