最佳答案
我看到这段代码与 LINQtoSQL 一起工作,但是当我使用实体框架时,它抛出了这个错误:
LINQ 到实体不识别方法的系统。IQueryable’1[ MyProject。模特。CommunityFeatures ] GetCommunityFeatures ()的方法,此方法不能转换为存储表达式。`
存储库代码如下:
public IQueryable<Models.Estate> GetEstates()
{
return from e in entity.Estates
let AllCommFeat = GetCommunityFeatures()
let AllHomeFeat = GetHomeFeatures()
select new Models.Estate
{
EstateId = e.EstateId,
AllHomeFeatures = new LazyList<HomeFeatures>(AllHomeFeat),
AllCommunityFeatures = new LazyList<CommunityFeatures>(AllCommFeat)
};
}
public IQueryable<Models.CommunityFeatures> GetCommunityFeatures()
{
return from f in entity.CommunityFeatures
select new CommunityFeatures
{
Name = f.CommunityFeature1,
CommunityFeatureId = f.CommunityFeatureId
};
}
public IQueryable<Models.HomeFeatures> GetHomeFeatures()
{
return from f in entity.HomeFeatures
select new HomeFeatures()
{
Name = f.HomeFeature1,
HomeFeatureId = f.HomeFeatureId
};
}
LazyList 是一个扩展了 IQueryable 能力的 List。
有人能解释一下为什么会出现这种错误吗?