在与SQL Server相同的Dapper中使用database transaction和Entity Framework 6是否存在任何问题/陷阱?
答案 0 :(得分:1)
using (var db = new MyDbContext())
using (var tran = db.Database.BeginTransaction()){
//EF
var hoge = db.HogeTable.FirstOrDefault();
hoge.Name = "fuga";
db.SaveChanges();
//Dapper
// create query and params
db.Database.Connection.Execute(query, params, tran.UnderlyingTransaction);
tran.Commit();
}