c# - Entity Framework 6 deadlock on multiple inserts with the same context -
i 3 inserts in wcf service. 2 of them inside library [class library project] , 1 inside service itself. use same context 3 inserts can roll 3 if 3rd fails example.
my dbcontext set based on unity , dependency injection:
[microsoft.practices.unity.dependency, registerdependency(typeof(employeeentities))] public employeeentities employeedb { get; set; } and here's how code looks performing inserts.
using (transactionscope tr = new transactionscope(transactionscopeoption.required,new transactionoptions{isolationlevel=system.transactions.isolationlevel.readuncommitted})) { using (dbcontexttransaction dbtransaction = employoeedb.database.begintransaction()) library.insertone(employeedb) library.inserttwo(employeedb) employeedb.add(something); employeedb.savechanges() now works fine if call service sequentially. when simulate load test, introduce concurrent calls, service starts fail.
here's error see on traces:an error occurred while updating entities. see inner exception details: transaction (processid 128) deadlocked on lock resources process , has been chosen deadlock victim. rerun transaction
adding important point. selects in class library compare against existing data. selects guessing taking lot of time. don't have transactionscope readuncommited on libraries. pass context, selects , inserts it.
blockquote
Comments
Post a Comment