【发布时间】:2010-08-19 18:53:34
【问题描述】:
我有以下例子:
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 to Entities 问题,而不是 Linq-to-SQL。如果您编辑并重新标记您的问题,您可能会有更多的运气。 :)
标签: c# .net linq entity-framework linq-to-entities