2018年11月28日 星期三

entity framework transaction 用法

using (var scope = db.Database.BeginTransaction())
{
  ...
  db.SaveChanges();
  scope.Commit();
}

※ 跳出 exception 不須特別呼叫 Rollback()
※ 使用 TransactionScope 對同一個資料庫也會造成 msdtc 相關錯誤,不予採用

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...