Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a fairly simple question to which I cannot seem to find the answer for. I have a silverlight app with Ria Services. In the DomainService class I have an update method like 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 the Id has default values. I've tried searching for how the GetOriginal method works, but cannot find any help. It seems to mee like it tries to rebuild the original object on the server, based on the changes that are sent back from client to server.

Or maybe anyone knows a better way to check if a certain property of an object has been changed during an update? I could off course compare it to the value in the database, but it seems like I should avoid this extra call to the database.

Any help is again much appreciated :-)

EDIT: Just found out about the RoundTripOriginalAttribute. This seems to do the trick. Am I the only one by the way that think RIA could be documented a little bit better?

like image 803
Sander_V Avatar asked Oct 15 '10 06:10

Sander_V


1 Answers

Well, I've been also looking for a way track entity changes with EF4 and after some googling I've found that you need to apply the "RoundTripOriginal" attribute to the properties of the entity you want to track, because RIA (by default) does not send the original values back to the server.

I still have some concerns on this and I asked some of the gurus:

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

This worked for me, but I still don´t think is the best way out of it.

Hope this helps.

like image 69
Jportelas Avatar answered Nov 12 '22 04:11

Jportelas