0

I have existing code that uses Ado.Net and am looking at integrating some new code that uses entity frameworks 5. As a proof of concept I wanted to try a transacted operation with BOTH ado.net and EF5.

I tried using TransactionScope but as I was using "two connections", I got an error about the transaction being promoted and DTC not available.

Can I have Ado.Net and EF5 use the same connection to avoid the issue above? If so, any code examples ....

Any other suggestion appreciated.

BTW, I am using EF5 Database First.

Thanks for help in advance.

Regards, Travis

1 Answers1

0

Yes, but only if you have a Distributed Transaction Coordinator (DTC) configured. DTC transactions are much slower than local transactions.

This may help:

How do I enable MSDTC on SQL Server?

Another option is to get the EntityConnection object and get the SqlConnection and use that in your ADO.NET commands, but you have to be careful about that because the connection can be closed if the containing entity is disposed.

Or you can pass an EntityConnection to the context when you create it, thus allowing the same connection to be used for both.

Community
  • 1
  • 1
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291