Ignore TransactionScope for specific query

后端 未结 3 1650
星月不相逢
星月不相逢 2020-12-13 19:12

I\'m looking for a way to execute a query while a TransactionScope is alive, and ignore the TransactionScope - basically, I want to execute this particular query no matter w

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 19:28

    If you wrap your log call inside of another transaction scope with the suppress option enabled, transaction scope will not be used.

    public override int SaveChanges() {
        try {
            return base.SaveChanges();
        } catch (Exception ex) {
            using (var scope = new TransactionScope(TransactionScopeOption.Suppress)) {
                LogRepo.Log(message); // stuff to log from the context
            }
    
            throw;
        }
    }
    

提交回复
热议问题