如果儿童的父对象
问题描述:
我想获得的所有对象,其中孩子的parentId的等于页ID我是在如果儿童的父对象
这对是我想做的事:
public IEnumerable<Route> GetAll(int locationId)
{
_db.Configuration.ProxyCreationEnabled = false;
return _db.Routes.Include(o => o.ConnectionPointRoutes.Select(s => s.Segment))
.Include(o => o.ConnectionPointRoutes.Select(c => c.ConnectionPoint)
.Where(c => c.Location.LocationId == locationId)).ToList();
}
,但我不断收到这个错误:
类型“System.ArgumentException”的一个例外EntityFramework.dll发生,但在用户代码中没有处理
附加信息:包含路径表达式必须引用在该类型上定义的 导航属性。对于 参考导航属性使用虚线路径,对于集合 导航属性使用Select运算符。
有什么想法?
答
我落得这样做:
public IEnumerable<Route> GetAll(int locationId)
{
return _db.Routes
.Include(o => o.ConnectionPointRoutes.Select(s => s.Segment))
.Include(o => o.ConnectionPointRoutes.Select(c => c.ConnectionPoint))
.Where(c => c.ConnectionPointRoutes.Select(s => s.ConnectionPoint.Location)
.FirstOrDefault(q => q.LocationId == locationId).LocationId == locationId)
.ToList();
}
它看起来像c.Location是一个列表对象,所以你需要c.Location.Select(X => ......)。您是否拥有像伟大家长身份证,父母身份证,家长身份证,儿童身份证等多代表?如果是这样,您可能需要使用递归算法来获取所有级别。 Linq只能在单代列表上工作。 – jdweng
我不认为'Include'里面支持Where'。 –
我找到了修复它的方法,如果您感兴趣,请检查答案:) –