Entity Framework 6 prevent transaction escalation when using multiple contexts that refer to the same database

771 Views Asked by At

I've stubled upon a problem, and I'm unable to find an answer (or my google skills are really rubbish).

Our solution is an ASP MVC4 C# website and multiple class libraries. We use MS SQL2008 and EntityFramework 6.

Let's say I've got Foo and Bar object types. Foo contains a Bar object. Upon saving Foo I have to save Bar. Methods to save Foo and Bar are defined in different class libraries, each library has its own Entity model that contains tables from relevant schemas of the same base. Now the problem is I use transactions, and calling method that saves Bar leads to transaction level escalating "MSDTC disabled" exception.

Is there a way to avoid having to use MSDTC and still use different Entity Models that refer to the same base?

1

There are 1 best solutions below

0
On

Okay, so we found a solution. First of all, the strings must be exactly equal (excluding metadata). If that does not help, try making businesslogic classes that handle saving FOO and BAR into the database use the same instance of the TransactionHandler.