Update of large entity through service

只谈情不闲聊 提交于 2019-12-06 14:14:58

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.

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

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.

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.

One thing you can do is allow the client to send delta updates. All your objects could have a unique guid that the server mananges.

You could have a WCF method like so to send the delta

  void UpdateProperty( Guid objguid ,
            string propertyname , string propertyvalue );

On the server side you can locate the object using the guid and update the corresponding property.

If you're schema is that large, you could try using XML as a web method parameter along with an XSD that has optional elements. This wouldn't be tied to a particular platform. You could just send in the elements that have changed along with the unique key identifier.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!