开发者

Silverlight RIA: Server-side extension properties on model are not ignored by RIA

开发者 https://www.devze.com 2023-01-24 00:06 出处:网络
In my SilverLight app I have a simple entity-model containing one table: [Memo]. The memo table definition/class layout:

In my SilverLight app I have a simple entity-model containing one table: [Memo]. The memo table definition/class layout:

pseudo-code-mode

Partial Class Memo
  ID      [int autonumbering]
  Memo    [string]
  UserID  [int]
End Class

For my client I need to see a normal name, and not a [UserID] number in the UI so we need to translate that number in field/property [UserID] to a readable [UserName].

to accomplish that we'll extend the [Memo] Class SERVER-SIDE with this:

pseudo-code-mode

Partial Class Memo
  UserName  [string]
End Class

So now we have one complete class containing both the UserID and the UserName (Very usefull for like when you use binding to a datagrid)

At the CLIENT-SIDE we have a cached list of users, so at the CLIENT-SIDE we'll fill the UserName property after the EntitySet has been uploaded to the client. This is where my problem occurs: After setting the property, the Entity object is tracked as being changed by the DomainService engine (DomainContext.HasChanges = true).

So when loading a datagrid with 100 records, all records are tagged changed because of setting the UserName property in the client, and after editing 1 record, all 100 records are posted back to the server as being 'changed' instead of just 1 record.

Since this property is an extension property and I do not want to t开发者_开发知识库rack changes for the UserName, I thought: Lets add the [Ignore] attribute, but no dice. The DomainService keeps tracking the UserName changes. I also tried the [IgnoreDataMember] attribute, no Dice. The [Exclude] attribute does not work, since then it's no longer projected to the client-side.

So I need to be able to reset the DomainService's object tracking state after loading and extending the data from database. Another solution is to extend the data at the server-side, but this is not an option for now.


If your new property is only required client-side, then add your Partial class extension to the client side. Not to the server side.

We often add new helper properties (like Fullname, which returns LastName+FirstName) to our Client-side RIA services project.

0

精彩评论

暂无评论...
验证码 换一张
取 消