Error with Entity Framework.Any () filter

Here is my request:

var x = db
   .Users
   .Where(u => u.Locations.Any(l => searchedLocation.Counties.Any(c => c.LocationId == l.LocationId));

Context:

  • Users- IQueryable<User>. (EF Object Set)
  • searchedLocation- object Location.
  • Counties- ICollection<MiniLocation>.

What am I trying to do:

Return all users where any of the counties for these places has a locationId of any of the counties belonging to the found place.

Example:

New York Search (LocationId = 1. County1LocationId = 2)

User: Bob. Locations: Soho. County1LocationId = 2. County2 LocationId = 3.

So to coincidence. (because Soho has a county with LocationId 2 as well as NYC)

The error I get is:

Unable to create a constant value of type 'xxx.xxx.Locations.MiniLocation'. In this context, only primitive types (such as Int32, String, and Guid) are supported.

Any ideas?

+5
2

MSDN , . .Net 3.5 Linq to Entities, Any.

+1

, .

var idsToSearch = "1,2,3,4,5...";    

Contains :

var x = db
       .Users
       .Where(u => idsToSearch.Contains(u.LocationId));
0

All Articles