EF6 同一DB不同DbContext的事务控制
作者:互联网
1.
using (Db1Context db = new Db1Context()) { using (var tran = db.Database.BeginTransaction()) { //db operation result = db.SaveChanges(); using (Db2Context db2 = new Db2Context(db.Database.Connection,false))//必须false { db2.Database.UseTransaction(db.Database.GetDbTransaction()); //db2 operation db2.SaveChanges(); } tran.Commit(); } }
2. TransactionScope
标签:Db2Context,false,Database,DB,db,EF6,DbContext,using,db2 来源: https://www.cnblogs.com/wuxuefeng/p/14550915.html