Share Transaction between different DataContext

Share Transaction between different DataContext

Postby Zero-G. » Mon 04 May 2015 08:03

Hey
I think, the subject says all, I want to achieve.
I want to share a Transaction within different DataContext.
To get an idea, what I try to do:
I work with Dependency Injection. And I have a different contracts for customer, offer and so on.
Each of the contract has a "Save" Method. But, when within one of the Saves somesthing happens, None of the save methods is allowed to commit.
So, I thought having a Transaction object, which I can share would be the right Thing.
And there is one more Thing what you should have to know: I can't create a "new" object to run within. So, I have to late bind the Transaction - only when the save is called.
THX for any ideas to this
Zero-G.
 
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Re: Share Transaction between different DataContext

Postby MariiaI » Wed 06 May 2015 05:13

Every DataContext object has its connection. LinqConnect starts a local DbTransaction and uses it to execute generated SQL commands if there is no open transaction in the LinqConnect connection instance. When all SQL commands have been successfully completed, LinqConnect commits the transaction and returns. Thus, it is impossible to share local transaction between several DataContext objects.
However, the functionality of the distributed transactions may be suitable in this case. For example, you can try wrapping all separate calls of the Save() method in the TransactionScope and commit it. Please refer here: http://www.devart.com/linqconnect/docs/?Transactions.html

If you'll encounter any issues with this, please provide us with a small test project so that we are able to investigate your scenario more clearly and find the most suitable solution for you.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to LinqConnect (LINQ to SQL support)