【发布时间】:2016-10-06 21:36:17
【问题描述】:
我有这个问题:
var allValues = from p in _pContext.Persons
where p.Id == currentPerson.Id
from i in p.Items //This is a list that contains "Items"
select i;
我想拥有所有项目和它们包含的所有嵌套值。执行此查询时如何加载这些?我知道我可以在上下文中使用包含语句,但这不会导致任何地方。如果我这样做:
var allValues = from p in _pContext.Persons.Include("Items.Properties")
where p.Id == currentPerson.Id
from i in p.Items //This is a list that contains "Items"
select i;
要加载所有项目及其关联的“属性”,这些属性未加载,它们的列表已实例化但不包含任何内容。
【问题讨论】:
-
不同版本的 Include 方法确实存在于不同的类中。那个接受一个 lamda,您可以在其中指定要包含的相关对象。据我所知,您需要使用:
using System.Data.Entity;才能使用。 -
人与物品之间有一对多的关系吗?
-
对不起,我不能使用 lambda 表达式,因为我正在使用 MySQL 和 EF,据我所知,它不支持包含的 lambda 表达式。
标签: c# entity-framework linq nested-queries