0
IQueryable<Patients> patients = db.Patients; 
    
patients = patients.Where(x => x.Status.LastOrDefault().Status != Status.Imported); 

On the 1st line I have a IQueryable data. (1,000+ data)

On the 2nd line The "Status" is a List of object. I wanted to get the last list of Status and have a condition.

But this gives me an error "{document}{Status}.LastOrDefault().Status is not supported."

Is there any workaround to implement this? I cannot perform IEnumerable because it will load too slow.

I'm using MongoDB for my database.

  • Does this thread help you https://stackoverflow.com/questions/3476289/last-method-not-working-on-iqueryable-object – Ivan Gechev Aug 02 '22 at 11:01
  • Nope, I'm trying to access an Array inside a IQueryable which is the Status. And performing LastOrDefault() gives me an error. – Anthony Cuartero Aug 02 '22 at 11:05
  • Does this answer your question? [Last and LastOrDefault not supported](https://stackoverflow.com/questions/7253529/last-and-lastordefault-not-supported) – Dani Aug 02 '22 at 11:18

1 Answers1

0

Try "unwrapping" LastOrDefault:

patients = patients.Where(x => (x.Status.Length == 0 ? default : x.Status[x.Status.Length - 1]).Status != Status.Imported);
Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59