Page 1 of 1

Share Transaction between different DataContext

Posted: Mon 04 May 2015 08:03
by Zero-G.
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

Re: Share Transaction between different DataContext

Posted: Wed 06 May 2015 05:13
by MariiaI
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/ ... tions.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.