EFCore cross context transaction support

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
ggercman
Posts: 5
Joined: Tue 20 Aug 2019 12:40

EFCore cross context transaction support

Post by ggercman » Tue 20 Aug 2019 12:58

Hi,
I'm trying to create transaction and use it for cross database context as in this article https://docs.microsoft.com/en-us/ef/cor ... ansactions.
On line t.Commit() an exception is beeing thrown. After inspecting, I think it is because connection is beeing closed after disposing db2. db2 does not own connection, so this behavior is incorrect.
Comparing other provider (sqlserver) con.State is Open after disposing db2.

Code: Select all

using (var con = new Devart.Data.Oracle.OracleConnection(connection))
            {
                con.Open();
                var options1 = new DbContextOptionsBuilder<Db1>();
                options1.UseOracle(con);

                using (var db1 = new Db1(options1.Options))
                {
                    await db1.SaveChangesAsync();
                    using (var t = await db1.Database.BeginTransactionAsync())
                    {

                        var options2 = new DbContextOptionsBuilder<Db2>();
                        //options2.UseOracle((db1.Database.GetDbConnection() as Devart.Data.Oracle.Entity.IOracleConnectionAdapter).Connection);
                        options2.UseOracle(con);

                        using (var db2 = new Db2(options2.Options))
                        {
                            db2.Database.UseTransaction(db1.Database.CurrentTransaction.GetDbTransaction());
                            await db2.SaveChangesAsync();
                        }

                        await db1.SaveChangesAsync();
                        t.Commit();
                    }
                }
            }
            
            

    public class A1
    {
        public int Id { get; set; }
    }
    public class A2
    {
        public int Id { get; set; }
    }
    public class Db1 : DbContext
    {
        public Db1(DbContextOptions<Db1> options) : base(options) { }
        public DbSet<A1> A1 { get; set; }
    }
    public class Db2 : DbContext
    {
        public Db2(DbContextOptions<Db2> options) : base(options) { }
        public DbSet<A2> A1 { get; set; }
    }            

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EFCore cross context transaction support

Post by Shalex » Fri 23 Aug 2019 17:46

Thank you for your report. We have reproduced the issue with throwing "This OracleTransaction has completed; it is no longer usable." and are investigating it. We will notify you about the result.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EFCore cross context transaction support

Post by Shalex » Sat 14 Sep 2019 11:20

The bug with using the same database connection in several EF Core contexts is fixed: viewtopic.php?f=1&t=39337.

Post Reply