System.InvalidOperationException:This.NpgsqlTransaction has completed;it is no longer usable. at Npg...

mac2022-06-30  70

 关于报此异常,原因是事务不能循环提交,一个方法中事务只能提交一次。

System.InvalidOperationException:This.NpgsqlTransaction has completed;it is no longer usable. at Npgsql.NpgsqlTransaction.CheckCompleted() in ...

  正确使用方法

using (var pay = _postgreDbContext.Database.BeginTransaction()) { try { billItem.review_remark = "通过"; foreach (var item in Settlement) { item.status = 2; } _postgreDbContext.SaveChanges(); pay.Commit();//注意放到循环外面 } catch (Exception ex) { throw ex; } }

 

转载于:https://www.cnblogs.com/personblog/p/11419962.html

最新回复(0)