通过服务更新大型实体 [英] Update of large entity through service

查看:60
本文介绍了通过服务更新大型实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在基于WCF(而不是Entity Framework)构建n层系统,并且我们已经讨论了实现大型实体更新的最佳方法。
我们已经创建了DTO,并在将数据发送给客户端时将域模型中的数据映射到了eseese中。
然后,客户端在我们当前的实现中进行一些更改,并使用相同的DTO将其发送回去。
我们的某些实体可能具有80-100个属性,但也许客户只对其中一个或几个属性进行了更改。填充整个DTO并将其发送回,然后尝试在服务器端找出实际上已被修改的属性,效率似乎很低。
是否有更好的方法来实现这一目标,还是应该采用蛮力方法?
将来,我们需要支持非.Net客户,因此我们不想将解决方案与特定于.NET的事物联系在一起。

We're building an n-tier system based on WCF (but not Entity Framework) and we've run into a discussion of the best way to implement updates of large entities. We've created DTOs and map data from our domain model into theese when data is sent to the client. The client then makes some changes and sends them back using the same DTO, in our current implementation. Some of our entities might have 80-100 properties, but perhaps the client only makes changes to one or a few of them. It seems inefficient to populate the whole DTO and send it back and then try to figure out on the server side wich properties were actually modified. Is there a better way to implement this or should we go with the "brute force" method? In the future we need to support non .Net clients so we don't want to tie our solution to something .net-specific.

推荐答案

我们通过在每个DTO上包含一个更改属性名称的字符串数组来解决此问题。服务中的更新代码仅验证并写入名称在此数组中的属性。

We solved this problem by including a string array of changed property names on every DTO. The update code in the service only validates and writes properties whose names are in this array.

为了简化编码,我们将此字符串数组放在抽象基类中并继承所有可变的 DTO。例如:

To make coding easier, we put this string array in an abstract base class and inherited all "changeable" DTOs from that. For example:

<DataContract>
Public MustInherit Class ChangeTrackableObject
    <DataMember> Public Property Changes As HashSet(Of String)
End Class

没有< KnownType> 属性,因为在这种情况下不需要DTO多态。 DataContractSerializer 仅使用继承关系来获取基类属性,仅此而已。

There are no <KnownType> attributes because DTO polymorphism is not required in this case. The DataContractSerializer simply uses the inheritance relationship to pull in the base class property, nothing more.

该系统似乎.NET和Java客户端代码同样可以很好地工作。 Java客户端将其视为字符串数组。我们为.NET客户端提供了扩展方法库,使填充数据变得更加容易。

This system seems to work equally well from .NET and Java client code. Java clients see this as a string array. We have a library of extension methods for .NET clients to make it easier to populate the data.

这篇关于通过服务更新大型实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆