Entity Framework 6: Multiple contexts from same database in 1 transaction -


with 2 different context classes use same database best way include changes both in same transaction?

you can use transactionscope distributed transaction. concept:

using(var transaction = new transactionscope()) {    using (var context1 = new dbcontext1())    {       ...       context1.savechanges();    }     using (var context2 = new dbcontext2())    {       ...       context2.savechanges();    }     transaction.complete(); } 

only when transactionscope completed (committed), changes reflect in database.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -