急切加载跟踪的项目?

发布于 2024-08-12 14:42:06 字数 334 浏览 8 评论 0原文

我有一个元素绑定到一个实体(联系人),该实体公开了一些导航属性。

我希望,在某些操作(即“加载子项”按钮)上,联系人应该加载其所有子项和孙子项,就像我在执行之前使用 ObjectQuery.include 所做的那样;示例(伪):

DirectCast(element.DataContext, Contact).SubContacts. _
   Include("Address.State"). _
   Load()

我希望能够通过重新加载项目(如上面的示例)来调整结果,而不仅仅是在查询模型本身时。

我认为这应该以某种方式成为实体框架的一部分。

I have an element bound to an entity (Contact) that exposes some navigation properties.

I want, that on some action (i.e. a "Load children" button), the Contact should load for all its children and grand children like I can do with an ObjectQuery.Include before the execution; example (pseudo):

DirectCast(element.DataContext, Contact).SubContacts. _
   Include("Address.State"). _
   Load()

I want to be able to shape the results also by reloading items like the example above, not only when querying the model itself.

I think this should of been a part of Entity-Framework in some way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫思念不要吵 2024-08-19 14:42:06

我不确定我是否遵循了该问题,但让我检查一下:

您想要获取已加载的实体,然后加载导航属性以及包含该属性的路径。这实际上并不那么困难,只要您使用与加载第一个对象相同的上下文即可。

重要的一点是,每当您执行返回实体的查询时,实体框架都会自动将其与您已有的任何相关对象链接起来。因此,您真正想要的是生成一个返回额外数据的新查询,其中包含一些数据。

实体框架中的每个引用都有一个名为 CreateSourceQuery 的方法。它返回一个对象查询,因此您可以使用它来执行此操作(抱歉,C#):

AlreadyLoadedContact.SubContacts.CreateSourceQuery().Include("Address.State").ToList();

ToList 调用执行查询,实体框架将获取所有结果并自动将它们添加到您的 SubContacts EntityCollection 中。

I'm not positive I follow the question, but let me check:

You want to take an entity that you have already loaded, then load a navigation property with include paths for that property. This isn't actually that difficult, as long as you are using the same context that you used to load the first object.

The important point is that whenever you do a query that returns an entity, Entity Framework will automatically link it up with any of its related objects that you already have. So what you really want is to produce a new query that returns the extra data, with some includes.

Every reference in Entity Framework has a method called CreateSourceQuery. It returns an Object Query, so you can use it to do this (sorry, C#):

AlreadyLoadedContact.SubContacts.CreateSourceQuery().Include("Address.State").ToList();

The ToList call executes the query, and Entity Framework will take all the results and automatically add them to you SubContacts EntityCollection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文