Reputation: 39190
A customer requested a very interesting thing. They'd like to have two operations - an update to the entity in the context and and update to an other entity to be carried out simultaneously.
In SQL, it's pretty straight-forward. One can simply roll-back the whole shabang if needed. However, I've never seen it done in CRM. Is it at all possible?!
Please note that I'm looking for a solution that is based on a supported approach.
Upvotes: 2
Views: 1129
Reputation: 18895
Simultaneously may not be the right word, but you can do it in the same database transaction just by updating the 2nd entity within a plugin operating on the 1st transaction in the pre or post operation event as long you use the IOrganizationService provided in the plugin context.
Throwing any kind of exception will "bubble up" causing the entire transaction to get rolled back (assuming you're not catching and "eating" the exception)
Upvotes: 3
Reputation: 408
If you're using early bound and the OrganizationServiceContext you can add several objects to it and then run a "SaveChanges()" on the context to save all changes in one call.
Upvotes: 0