我下面举个例子:如何包括物业
using (MyContext context = new MyContext())
{
var query = from entityA in context.EntityA.Include("TestProperty")
join entityB in context.EntityB on entityA.Id equals entityB.EntityAId
join entityC in context.EntityC on entityB.Id equals entityC.EntityBId
where entityC.Id == id
select entityA;
List<EntityA> toReturn = query.ToList();
return toReturn;
}
我的加入都工作正常,但是,我的“TestProperty”导航属性加载不正确。我看,在运行时,它是空的。
当我做到以下几点:
context.LoadProperty(toReturn, "TestProperty");
它正确地加载 'TestProperty' 属性。在我的LINQ-to-SQL语句中是否有错误?
更新: 我改的第一行是:
from entityA in context.EntityA.Include("TestProperty").ToList()
地抛在下面的线相同的其余部分,它正确地装入我的财产。这是解决问题的恰当方法吗?
这看起来像一个LINQ到实体问题,而不是LINQ到SQL。如果你编辑并重新标记你的问题,你可能会有更多的运气。 :) – Peter 2010-08-20 20:29:48