0

WaiverID is an int so I am not sure what the non primitive type in question is.

 var originalWaivers = _context.SurchargeWaivers
.Where(x => updatedWaivers.Select(waiver => waiver.WaiverID).Contains(x.WaiverID));

I am trying to query the db for the original entities so that I can update them.

UPDATE: More specifically, why is this a problem. Why is it that a list will work but an IEnumerable is a problem?

Robert
  • 4,306
  • 11
  • 45
  • 95

1 Answers1

2

It seems updatedWaivers is the problem. Instead of performing an inner query for each item, just store the ids into a List and use it:

var idList = updatedWaivers.Select(waiver => waiver.WaiverID).ToList();
var originalWaivers = _context.SurchargeWaivers
                              .Where(x => idList.Contains(x.WaiverID));
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • Thanks, buy why is this an issue? – Robert Jan 12 '15 at 14:45
  • Because LINQ to Entities is trying to convert `updatedWaivers.Select(waiver => waiver.WaiverID)` into an actual SQL statement, and since `updatedWaivers` is actually in memory, and not in the database, it fails to do so. – Corey Adler Jan 12 '15 at 14:53