I'm interested if opening an Entity Framework's DbContext
connection within an existing ADO.NET SqlConnection
should be discouraged, provided that they both use the same connection string, i.e. operate on the exactly same database?
For example:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new System.TimeSpan(0, 30, 0)))
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
DoStuffWithEF(connectionString);
...
}
}
void DoStuffWithEF(string connectionString)
{
using (var context = new MyCodeFirstDbContext(connectionString))
{
// basic LINQ queries ...
}
}
- Is the connection being reused in both cases, given that the connection string refers to the same SQL Server 2012 database in both cases?
- Is there any danger that such operation will require MSDTC?