Skip to main content
Microsoft Silverlight
Home Forums Silverlight Programming WCF RIA Services Context Submit Changes on Associated entities
5 replies. Latest Post by SteveReconG on October 8, 2009.
(0)
SteveReconG
Member
18 points
26 Posts
10-08-2009 8:39 AM |
I have a scenario of:
Company with 2 employees.
A page loads for a company - and there is an editable grid for the employees.
I want to be able to submit changes for the company in the event of the employees changing.
It appears however, that it requires me to save each employee with it's own domain context method.
The problem with this is, instead of knowing that the company has changed so I can save the company, I get two separate calls to update employees.
For one, I want these saves in one transaction on the server - I don't want two separate update calls. I will take care of cascading my changes on the company on the server (ie I'll let NHibernate save my company and pick up the employee changes) - but I do want RIA to notify me that the company has changed so I can call the RIA UpdateCompany service
make sense?
ColinBlair
Star
11615 points
2,089 Posts
10-08-2009 10:28 AM |
A slight correction here that I hope makes things clearer. The Update, Delete, and Insert methods are not meant to be where each change is actually saved to the database. They are simply the methods where the Domain (i.e. nHibernate) is supposed to be updated. There is a seperate, overrideable method of the DomainService called PersistChangeSet that is called after all of the Update, Delete, Insert, and Custom methods have been called. PersistChangeSet is where you are supposed to tell nHIbernate to actually persist the changes into the database. That is where you put your transaction handling and anything else that you need.
10-08-2009 11:03 AM |
Thank you Colin.
Does this mean each 'UpdateEmployee' call to the domain service is going to be rather chatty isn't it ? Or is that occuring on the client until you call the PersistChangeSet ? Is this 3 calls being made across the wire or just one ?
Let me clarify then: I will want to handle the PersistChange set by mapping my DTO objects to my NHibernate objects and from there be able to transactionally save them within the PersistChangeSet call.
Thanks for the clarification - I was looking for that answer.
10-08-2009 11:06 AM |
double post - see above
10-08-2009 11:49 AM |
When you call SubmitChanges all of the changes in the DomainContext are packed together into a ChangeSet. That ChangeSet is sent to the DomainService as a single communication. The DomainService then reads through all of the actions in the ChangeSet and calls your various updates, inserts, deletes, and custom methods finishing up by calling PersistChangeSet.
10-08-2009 12:38 PM |
Excellent. Thank you Colin.
Just a few minutes before your post I fired up Fiddler and validated that - so I'm good to go.
Thanks - especially for your accurate and timely response to my question.