原因:
根据设计,
LINQ to Entities
更具体地说,linqto实体只支持
无参数构造函数
和
初始值设定项
.
解决方案:
因此,为了克服这个异常,需要将子查询合并到主查询中
和
GetHomeFeatures()
而不是直接从LINQ查询中调用方法。另外,在您试图实例化的新实例的行上也有一个问题
懒鬼
使用它的参数化构造函数,就像您在
解决并发冲突
. 为此,解决方案是切换到LINQ查询的客户机评估(LINQ到对象)。这将要求您调用
AsEnumerable
在调用LazyList构造函数之前,用于LINQ to Entities查询的方法。
public IQueryable<Models.Estate> GetEstates()
{
return from e in entity.Estates.AsEnumerable()
let AllCommFeat = from f in entity.CommunityFeatures
select new CommunityFeatures {
Name = f.CommunityFeature1,
CommunityFeatureId = f.CommunityFeatureId
},
let AllHomeFeat = from f in entity.HomeFeatures
select new HomeFeatures() {
Name = f.HomeFeature1,
HomeFeatureId = f.HomeFeatureId
},
select new Models.Estate {
EstateId = e.EstateId,
AllHomeFeatures = new LazyList<HomeFeatures>(AllHomeFeat),
AllCommunityFeatures = new LazyList<CommunityFeatures>(AllCommFeat)
};
}
更多信息:
请看一看
LINQ to Entities, what is not supported?
更多信息。
LINQ to Entities, Workarounds on what is not supported
详细讨论可能的解决方案。
(两个链接都是缓存版本,因为原始网站已关闭)