Here's my query:
var x = db
.Users
.Where(u => u.Locations.Any(l => searchedLocation.Counties.Any(c => c.LocationId == l.LocationId));
Context:
Users
is IQueryable<User>
. (EF object set)searchedLocation
is a Location
object.Counties
is a ICollection<MiniLocation>
.What i'm trying to do:
Return all users, where any of the Counties for those locations have a locationId of any of the counties belonging to the searched location.
Example:
Search for New York City (LocationId = 1. County1LocationId = 2)
User: Bob. Locations: Soho. County1LocationId = 2. County2 LocationId = 3.
So that's a match. (because Soho have a County with a LocationId of 2, and so does NYC)
Error i receive:
Unable to create a constant value of type 'xxx.xxx.Locations.MiniLocation'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
Any ideas?
This MSDN page states that this construct is not supported. You can use this method for .Net 3.5 Linq to Entities to help replace the use of Any
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With