使用 EF 4.1 ObjectContext 在 LINQ 查询中提前加载实体
我的 EDMX 中有一堆实体,我将 LazyLoading 设置为 false
。 据我了解,我现在必须在每个查询中显式加载相关实体。 然而,我发现的大多数引用都指向 DbContext
而不是 ObjectContext
。
代码中的急切加载方式似乎存在很大差异。 就我而言,客户和地址之间存在 1:1 关系。
获取时如何正确加载地址,例如客户#1488?
from c in context.Customers
where c.Id = 1488
select c;
然后我希望能够使用 c.Address.Street
、c.Address.City
等。
如何加载地址?
I have a bunch of entities in my EDMX and I set LazyLoading to false
.
As I understand I now have to explicitly load realted entities with every query.
however most references I found point to DbContext
and not ObjectContext
.
And there seems to be great differences as how eager loading is done in code.
In my case I have Customers and Addresses in a 1:1 relationship.
How do I correctly load the address when fetching, e.g. customer #1488?
from c in context.Customers
where c.Id = 1488
select c;
Then I want to be able to use c.Address.Street
, c.Address.City
etc.
How do I load the Address(es)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其他人可能会给您有关
DbContext
的更准确答案。我通常使用ObjectContext
,其中以下代码将完成这项工作:Somebody else may give you a much more precise answer about
DbContext
. I generally work withObjectContext
where this code will do the job: