Transaction Problem with generated Stored Procedure Call
Posted: Mon 04 Jun 2018 13:36
Hi,
I tried to make a stored proc method call inside a transaction. This ran into a runtime error. So I had to do two small changes in the ef core template. Perhaps you can add them as well to the standard template:
Line 1028 add: using Microsoft.EntityFrameworkCore.Storage;
Line 1909 add: cmd.Transaction = Database.CurrentTransaction?.GetDbTransaction();
For your understanding of the correct place:
try
{
using (DbCommand cmd = connection.CreateCommand())
{
if (this.Database.GetCommandTimeout().HasValue)
cmd.CommandTimeout = this.Database.GetCommandTimeout().Value;
cmd.Transaction = Database.CurrentTransaction?.GetDbTransaction();
<#+
if (!string.IsNullOrEmpty(method.Procedure) && !method.TableValuedFunction) {
#>
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = @"<#= codeProvider.GetQuotedString(method.Procedure) #>";
<#+
} else {
#>
Best Regards
Helmut Joost
I tried to make a stored proc method call inside a transaction. This ran into a runtime error. So I had to do two small changes in the ef core template. Perhaps you can add them as well to the standard template:
Line 1028 add: using Microsoft.EntityFrameworkCore.Storage;
Line 1909 add: cmd.Transaction = Database.CurrentTransaction?.GetDbTransaction();
For your understanding of the correct place:
try
{
using (DbCommand cmd = connection.CreateCommand())
{
if (this.Database.GetCommandTimeout().HasValue)
cmd.CommandTimeout = this.Database.GetCommandTimeout().Value;
cmd.Transaction = Database.CurrentTransaction?.GetDbTransaction();
<#+
if (!string.IsNullOrEmpty(method.Procedure) && !method.TableValuedFunction) {
#>
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = @"<#= codeProvider.GetQuotedString(method.Procedure) #>";
<#+
} else {
#>
Best Regards
Helmut Joost