I'm having a strange problem with new Entity Framework for .NET 4
I have a SQL Server 2005 (EXPRESS) database and my service writes data to two tables using entity framework. Let's say tables are TableA and TableB. TableB has foreign key to TableA. In my program there are several threads that writes data in parallel. Each thread has its own ObjectContext. The program creats TableA object and puts it in the object context. Then objects for TableB are created and put to object context. This repeats for several TableA items.
Finally when ObjectContext.Save method is called I see a deadlock error in the log:
System.Data.SqlClient.SqlException: Transaction (Process ID 56) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
It seems that it somehow depends on database options as it is reproduces on particular database only. One new database the issue is not reproduced. What database\table settings can influence on deadlock while Entity Framework performs batch insert? Or may be the problem somewhere else?
Per your comment: