Use current context transaction if exist for methods
When methods are generated within a C# context, SqlCommand is created without using its current context transaction if existing.
While it is possible manually change this in the template, should it not be either defaulted, or optional with a property set on the method in Entity Developer?
using (DbCommand cmd = connection.CreateCommand())
{
if (this.Database.GetCommandTimeout().HasValue)
cmd.CommandTimeout = this.Database.GetCommandTimeout().Value;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = @"...";
DbTransaction currentTransaction = this.Database.CurrentTransaction?.GetDbTransaction();
if (currentTransaction != null)
{
// The command is now explicitly enlisted in the DbContext's active transaction.
cmd.Transaction = currentTransaction;
}
...
1
vote