Reputation: 4145
I'm using LINQ to Entities in the Data layer of my application, but am getting hammered by a NotSupportedException in a call to results.ToList(). Here is the function causing 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 a list of all the Organizations at a given Location to the Service Layer (which returns it to the MVC Controller, which converts it to JSON then returns it to the client). The Service Layer is expecting a List to be returned.
This may be pretty simple... any help?
Upvotes: 2
Views: 489
Reputation: 126587
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 can't do a reference comparison of l
. Compare by the PK, instead.
Upvotes: 8