I have the following EF Expression:
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();
Im getting an error when setting:
Properties = rc.CurrentProperties.Select(p=> new CustomPropertyObj(){
Name = p.Name,
PropertyId = p.PropertyId
}).ToList()
This is the error:
LINQ to Entities does not recognize the method ‘System.Collections.Generic.List1[CondoTrack.Model.Poco.CustomPropertyObj] ToList[CustomPropertyObj](System.Collections.Generic.IEnumerable1[CondoTrack.Model.Poco.CustomPropertyObj])’ method, and this method cannot be translated into a store expression.
Any clue on how to get the desired result?
Remove the
ToList()and change thePropertiestype toIEnumerable<T>instead ofList<T>. As it is stated in the error,ToListis not supported by Linq to Entities.