选择内部EF选择

时间:2012-11-15 19:29:19

标签: c# entity-framework linq-to-entities

我有以下EF表达式:

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.List 1[CondoTrack.Model.Poco.CustomPropertyObj] ToList[CustomPropertyObj](System.Collections.Generic.IEnumerable 1 [CondoTrack.Model.Poco.CustomPropertyObj])'方法,并且此方法无法转换为商店表达

有关如何获得所需结果的任何线索?

1 个答案:

答案 0 :(得分:0)

删除ToList()并将Properties类型更改为IEnumerable<T>,而不是List<T>。正如错误中所述,Linq to Entities不支持ToList