question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scaffolded Stored procedure transaction issue

See original GitHub issue

the 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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Aug 17, 2020

Fixed in latest daily build, please try it out and let me know if it works for you - and thanks for the contribution!

1reaction
ErikEJcommented, Aug 17, 2020

Thanks, so no need for it to be public, then?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found