EF4 自跟踪实体

发布于 2024-10-22 01:20:52 字数 518 浏览 2 评论 0原文

我目前正在尝试在 n 层场景中使用 STE。我有一个 WCF 服务,它允许我检索对象图和/或更新对象以及客户端 (WPF) 应用程序,该应用程序允许我编辑该图的各个方面并将更改提交回服务。

我的问题是这样的;我检索的对象图非常大 - 有时包括图像 - 但我的更新很少。但是,当我提交更新时,由于对象之间的关系,整个图都会提交回服务。

例如;给定一个客户/订单/订单详细信息场景:我检索客户及其订单和相关的订单详细信息(3 个级别)。然后,我更新单个 OrderDetail 以更改数量。我提交要通过 WCF 方法更新的 OrderDetail,该方法采用 OrderDetail 对象,但序列化遵循通过 Order 到 Customer 的关系属性,并且不仅序列化更改的 OrderDetail,还序列化所有 Orders、OrderDetails 和客户。

当服务调用参数被序列化时,如何阻止所有这些被传回,并且只传回要更新的对象而不遵循关系?

我可以找到的所有 STE 示例(仍然不多)似乎都是为了实际传递所有相关对象而设计的(例如在线博客/帖子示例)。

I am currently trying to use STE's in an n-tier scenario. I have a WCF service that allows me to retrieve a graph of objects and/or update objects along with a client (WPF) application that allows me to edit aspects of that graph and submit the changes back to the service.

My problem is this; the graph of objects that I retrieve is quite large - sometimes including images - but my updates are minimal. However, when I submit an update, the entire graph is submitted back to the service due to the relationships between the objects.

For example; given a Customer/Order/OrderDetail scenario: I retrieve a Customer with their Orders and the related OrderDetails (3 levels). I then update a single OrderDetail to perhaps change the quantity. I submit the OrderDetail to be updated via a WCF method that takes an OrderDetail object but the serialization follows the relationship properties through the Order to the Customer and serializes not only the changed OrderDetail but all Orders, OrderDetails and the customer.

How can I stop all of this from being passed back when the service call parameter is serialized and just pass back the object to be updated without following the relationships?

All of the examples that I can find for STE's (and there are still not many) seem to be designed to actually pass all related objects (such as the blog/postings example online).

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

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

发布评论

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

评论(2

黎歌 2024-10-29 01:20:52

如您所知,ObjectStateManager 管理对象状态,尤其是在 n 绑定应用程序上,要更新特定对象,请使用以下方法:

  1. 首先将其附加到上下文
  2. ChangeObjectState - 接受 EntityState 枚举:已添加/已修改/已删除
  3. SaveChanges

检查链接:http://msdn.microsoft.com/en-us/magazine/ee321569.aspx

As you know the ObjectStateManager manages the objects statuses, especially on n-tied applications, to update specific objects, use below methods:

  1. attach it to context first
  2. ChangeObjectState - accepts an enum of EntityState: Added/Modified/Deleted
  3. SaveChanges

check link: http://msdn.microsoft.com/en-us/magazine/ee321569.aspx

故事灯 2024-10-29 01:20:52

如果您不希望传递所有数据,则必须使用较小的数据集。因此,如果您默认检索客户+其所有订单+所有订单详细信息,那么它就是您的工作集。如果您只想使用单个订单创建操作来仅获取该订单及其详细信息。

它与聚合根有某种关系。订单是订单项目的聚合根,因为在没有订单的情况下使用单个项目没有太大意义。但在没有客户的情况下与 Order 合作可能是可能的,不是吗?

If you don't want all data to be passed you must work with smaller set. So if you by default retrieve Customer + all its order + all order details then it is your working set. If you want to work only with single Order create operation to get only that one and its details.

It is somehow related to aggregate roots. Order is aggregate root for order items because working with single item without its order doesn't make too much sense. But working with Order without its customer is probably possible, isn't it?

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