Skip to main content

Answered Question Context Submit Changes on Associated entitiesRSS Feed

(0)

SteveReconG
SteveReconG

Member

Member

18 points

26 Posts

Context Submit Changes on Associated entities

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
ColinBlair

Star

Star

11615 points

2,089 Posts

Re: Context Submit Changes on Associated entities

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.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

SteveReconG
SteveReconG

Member

Member

18 points

26 Posts

Re: Re: Context Submit Changes on Associated entities

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.

 

 

 

SteveReconG
SteveReconG

Member

Member

18 points

26 Posts

Re: Re: Context Submit Changes on Associated entities

double post - see above

ColinBlair
ColinBlair

Star

Star

11615 points

2,089 Posts

Re: Re: Context Submit Changes on Associated entities

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.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

SteveReconG
SteveReconG

Member

Member

18 points

26 Posts

Answered Question

Re: Re: Re: Context Submit Changes on Associated entities

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.

  • Unanswered Question
  • Answered Question
  • Announcement