ASP.NET实体框架引发NotSupportedException [英] ASP.NET Entity Framework NotSupportedException
问题描述
我使用LINQ到我的应用程序的数据层实体,但我得到一个NotSupportedException异常在呼叫锤击results.ToList()。这里是造成异常的函数:
公开名单<组织机构> GetByLocation(位置L)
{
使用(实体实体=新的实体())
{
从o在entities.OrganizationSet VAR的结果=
其中,o.Location ==升
选择o; 返回results.ToList<组织机构>();
}
}
问题的关键是在给定位置的服务层(它返回到MVC控制器,将其转换成JSON然后将其返回到客户端)返回所有组织的名单。服务层期望将返回一个列表。
这可能是pretty简单...任何帮助吗?
公开名单<组织机构> GetByLocation(位置L)
{
使用(实体实体=新的实体())
{
从o在entities.OrganizationSet VAR的结果=
其中,o.Location.Id == l.Id
选择o; 返回results.ToList<组织机构>();
}
}
由于此查询将被转换为SQL,你不能这样做→
的参考比较。由PK比较,来代替。
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?
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.
这篇关于ASP.NET实体框架引发NotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!