【发布时间】:2016-04-06 20:18:43
【问题描述】:
我有一种方法可以过滤表并返回与文件管理器匹配的那些行。 方法如下:
public List<RealEstate> GetMatchingRealestatesQuery(RealestateFilter f, RealestateSiteDbContext context)
{
IQueryable<RealEstate> realestates = context.RealEstates.Where(x => x.Status == RealEstateStatus.Open);
realestates = realestates.Where(x => f.Cities.Any( y => x.ZipCode.City.Id == y.Id));
if (f.MaxRent > 0)
realestates = realestates.Where(x => x.Rent <= f.MaxRent);
if (f.MinArea > 0)
realestates = realestates.Where(x => x.Area >= f.MinArea);
if (f.MinRooms > 0)
realestates = realestates.Where(x => x.Rooms <= f.MinRooms);
realestates = realestates.Where(x => f.RealestateTypes.Has(x.Type));
realestates = realestates.Where(x => f.RentalPeriod.Has(x.RentalPeriod));
return realestates.ToList();
}
但是,每当我调用该方法时,都会出现以下异常:
无法创建“RealestateSiteModel.City”类型的常量值。 仅支持原始类型或枚举类型 上下文。
我只是构建一个 IQueryable,然后通过调用 .ToList 来执行查询。这个异常的原因是什么?
【问题讨论】:
标签: .net database entity-framework linq entity-framework-6