C# EF选择内部选择
我有以下EF表达式:C# EF选择内部选择,c#,entity-framework,linq-to-entities,C#,Entity Framework,Linq To Entities,我有以下EF表达式: var complexes = db.ResidentialComplexes.AsNoTracking() .Where(rc => rc.MasterEntity == entity) .Select(rc => new CustomComplexObj() { ComplexId = rc.ComplexId,
var complexes = db.ResidentialComplexes.AsNoTracking()
.Where(rc => rc.MasterEntity == entity)
.Select(rc => new CustomComplexObj()
{
ComplexId = rc.ComplexId,
Name = rc.Name,
Region = rc.Region,
Properties = rc.CurrentProperties.Select(p=> new CustomPropertyObj(){
Name = p.Name,
PropertyId = p.PropertyId
}).ToList()
}).ToList();
设置时,我收到一个错误:
Properties = rc.CurrentProperties.Select(p=> new CustomPropertyObj(){
Name = p.Name,
PropertyId = p.PropertyId
}).ToList()
这就是错误:
LINQ to Entities无法识别方法“System.Collections.Generic.List1[CondoTrack.Model.Poco.CustomPropertyObj]ToList[CustomPropertyObj](System.Collections.Generic.IEnumerable
1[CondoTrack.Model.Poco.CustomPropertyObj]),并且无法将此方法转换为存储表达式。
有关如何获得所需结果的任何线索?删除
列表()
,并将属性更改为IEnumerable
,而不是列表。正如错误中所述,ToList
不受Linq to实体的支持。太好了!!非常感谢安德烈!只是等着接受答案。