EF4 自跟踪实体
我目前正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如您所知,ObjectStateManager 管理对象状态,尤其是在 n 绑定应用程序上,要更新特定对象,请使用以下方法:
检查链接: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:
check link: http://msdn.microsoft.com/en-us/magazine/ee321569.aspx
如果您不希望传递所有数据,则必须使用较小的数据集。因此,如果您默认检索客户+其所有订单+所有订单详细信息,那么它就是您的工作集。如果您只想使用单个订单创建操作来仅获取该订单及其详细信息。
它与聚合根有某种关系。订单是订单项目的聚合根,因为在没有订单的情况下使用单个项目没有太大意义。但在没有客户的情况下与 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?