I have a web application that uses the Entity Framework - we make use of the TransactionScope class to provide ambient transactions.
Is there any way to tell EF to use a standard T-SQL transaction in preference to DTC transaction? Quite often we make a number of queries to different tables inside one EntityContext and one TransactionScope instance, however this seems to always promote the transaction to DTC
I have put a short example together, see below. The query to the individual table correctly starts a T-SQL transaction and was on connection SPID 54 Then the query to the ContactUs table is made and EF does this on a different connection (SPID 53) which has the knock on effect of promoting the transaction to a DTC transaction.**
using (MyEntities DB = new MyEntities())
{
using (TransactionScope t = new TransactionScope())
{
DB.Individual.First().EmailAddress = "bob" + DateTime.Now.Second.ToString() + "@bob.com"; // done on connection 54
DB.ContactUs.First(); // done on connection 53 thus promoting the transaction!!
DB.SaveChanges();
t.Complete();
}
}