【发布时间】:2016-10-17 20:02:43
【问题描述】:
我遇到以下错误:
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
Parametername: path
使用以下代码:
return _context.Section.Include(x => x.Leagues.Select(y => y.Games.Where(v=>v.GameStart > DateTime.Now))).ToList();
我正在尝试选择所有具有活跃比赛的联赛的所有部分。 我就是无法绕过这个错误,也没有设法在 SF 上找到合适的解决方案。
感谢您的帮助
问候,玛丽安
【问题讨论】:
-
我想这就是你想要的。
return _context.Section.Where(x => x.Leagues.Any(y => y.Games.Any(v => v.GameStart > DateTime.Now))).ToList();Include用于预加载。Select是表达您想要返回的内容,而不是如何过滤它,这是Where的用途。Where需要布尔表达式,这是Any发挥作用的地方。 -
Include不用于过滤。它实现了所谓的“急切加载”(reference)。要过滤结果,请在Include之外使用普通的Where。 -
你好,伊戈尔。几乎。我需要所有部分。我需要有活跃比赛的联赛。抱歉解释不好。
-
@MarianneMarkwardt - 更新了下面的答案。
标签: c# entity-framework linq