ASP.NET Entity Framework NotSupportedException

I use LINQ to Entities in the Data layer of my application, but in the call to results.ToList (), the NotSupportedException throws me. Here is the function that throws the exception:

public List<Organization> GetByLocation(Location l) { using (Entities entities = new Entities()) { var results = from o in entities.OrganizationSet where o.Location == l select o; return results.ToList<Organization>(); } } 

The point is to return the list of all organizations in a given location to the service level (which returns it to the MVC, which converts it to JSON, and then returns it to the client). The service level expects the list to be returned.

It could be pretty simple ... any help?

+2
source share
1 answer
 public List<Organization> GetByLocation(Location l) { using (Entities entities = new Entities()) { var results = from o in entities.OrganizationSet where o.Location.Id == l.Id select o; return results.ToList<Organization>(); } } 

Since this query will be converted to SQL, you cannot perform a comparative comparison of l . Instead, compare PK.

+8
source

All Articles