简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM