scaffolded Stored procedure transaction issue
See original GitHub issuethe issue is when i working transaction as context.database.begintransaction() and if i call procedure in this transaction it is throw s exception, i fixed the issue with changing generated dbcontextextension class like this, i hope it works for you
`public static class DbContextExtensions
{
public static async Task<T[]> SqlQuery<T>(this DbContext db, string sql, params object[] parameters) where T : class
{
DbConnection conn = db.Database.GetDbConnection();
using (var db2 = new ContextForQueryType<T>(conn, db.Database.CurrentTransaction))
{
return await db2.Set<T>().FromSqlRaw(sql, parameters).ToArrayAsync();
}
}
public static DbTransaction GetDbTransaction(this IDbContextTransaction source)
{
return (source as IInfrastructure<DbTransaction>).Instance;
}
private class ContextForQueryType<T> : DbContext where T : class
{
private readonly DbConnection connection;
public ContextForQueryType(DbConnection connection, IDbContextTransaction tran)
{
this.connection = connection;
this.Database.UseTransaction(GetDbTransaction(tran));
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(connection);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<T>().HasNoKey().ToView(null);
}
}
}`
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why is part of transaction committed when stored ...
I have a stored procedure that begins by declaring a few variables then contains begin tran; After this it performs some validations on...
Read more >Long running query in stored procedure and transaction
We have several long running MSSQL stored procedures with brief insert expression in begin, after a slow select to collect the results, and ......
Read more >sql - Problems occurring when I use Transactions in Stored ...
Why is it that when I use SQL Transaction commit/rollback into GenerateAnnualPenaltyForProperty , the Stored Procedure doesn't work for the ...
Read more >DarioN1/SPToCore: Stored procedure scaffolding utility for ...
This command line utility has been created to simplify the stored procedures management in new .netcore. It allows you to scaffold a Microsoft...
Read more >Handling Transactions in Nested SQL Server Stored ...
In this tip we look at error message Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in latest daily build, please try it out and let me know if it works for you - and thanks for the contribution!
Thanks, so no need for it to be public, then?