WCF Ria Services ChangeSet.GetOriginal (): How does it work?

I have a pretty simple question that I cannot find the answer to. I have a silverlight app with Ria services. In the DomainService class, I have an update method as shown below:

public void UpdateConversationState(ConversationState currentConversationState) { var original = ChangeSet.GetOriginal(currentConversationState); if (original != null) ObjectContext.ConversationStatesRepository.AttachAsModified(currentConversationState, original); else ObjectContext.ConversationStatesRepository.Attach(currentConversationState); currentConversationState.UpdDat = DateTime.Now; if(original.Name != currentConversationState.Name) //Do something extra } 

The problem is that the Name property is always empty. In fact, every field, except for Id, has default values. I tried to find a GetOriginal method, but cannot find any help. It seems that it is trying to restore the original object to the server based on the changes sent from the client to the server.

Or maybe someone knows a better way to check if any property of an object was changed during the update? I could compare it with the value in the database, but it seems to me that I should avoid this extra call to the database.

Any help again is much appreciated :-)

EDIT: Just found out about RoundTripOriginalAttribute. This seems to be a trick. Am I the only one who thinks that the RIA can be documented a little better?

+6
wcf-ria-services changeset domainservices
source share
1 answer

Well, I was also looking for changes to the way track entity with EF4, and after some Google search, I found that you need to apply the RoundTripOriginal attribute to the properties of the object you want to track because the RIA (by default) does not send the original values ​​to the server.

I still have some problems about this, and I asked some of the gurus:

http://forums.silverlight.net/forums/t/218332.aspx

It worked for me, but I still don't think this is the best way out of this.

Hope this helps.

+3
source share

All Articles