将对象传递给域方法时出现问题
我有带有 DTO 对象的 WCF Ria 服务应用程序。我定义了 DTO 对象之间的关系:
[Include]
[Association("FK_Items_OrderID", "ID", "OrderID")]
public List<Item> Items { get; set; }
这样我就可以在客户端上查看项目集合并对其进行操作。然后我想保存更改并调用这个方法:
[Invoke]
public void SaveOrderChanges(Order order)
{
_dataManager.SaveOrderChanges(order);
}
它是域服务方法。但我看到这里的 Order 对象中的相关 Items 集合已经是 NULL,但是当我在客户端上调用此方法并将订单传递给此方法时,集合已填充。
有人知道该怎么办吗?谢谢。
I have WCF Ria Services App with DTO objects. I defined relations between my DTO objects:
[Include]
[Association("FK_Items_OrderID", "ID", "OrderID")]
public List<Item> Items { get; set; }
So I can see collection of Items on the client and operate with it. Then I want to save changes and call this method:
[Invoke]
public void SaveOrderChanges(Order order)
{
_dataManager.SaveOrderChanges(order);
}
It is domain service method. But I see than collection of related Items in Order object here is already NULL, but when I call this method on the client and pass order to this method collection is filled.
Does anybody know what to do? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为客户端序列化器不包含关联。 Wcf ria 服务有一种不同的方式来处理这种情况,但这涉及到使用 DomainContext 和标准的 Get/Insert/Update/Delete 方法。
我的建议是将 save 方法的符号更改为类似
Thi`s 的实用程序类,我用它来序列化和反序列化对象,但是应该欺骗它以包含 Items 集合。
当然,您需要在客户端执行相反的操作并序列化您的订单和商品。
这是我知道的最简单的方法,但是您也可以看看 此处。
最终,尝试按照 WCF Ria 的预期方式重构您的代码(基于上下文)
希望这会有所帮助,
马可
That's happen because the client side serializer don't include assocations. Wcf ria services has a different way to handle this kind of scenarious, but this involves the use of DomainContext and the standard Get/Insert/Update/Delete methods.
My advice is to change the sign of your save method to something like
Thi`s is an utilities class that I use to serialize and deserialize objects, however it should be tricked to include the Items collection.
Of course, you need to do the opposite client-side and serialize your order and items.
This is the easiest way to go that I know, however you could also take a look here.
Eventually, try to refactor your code in the way WCF Ria is meant to go (Context based)
Hope this helps,
Marco