System.InvalidOperationException:This.NpgsqlTransaction has completed;it is no longer usable. at Npg
Posted personblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了System.InvalidOperationException:This.NpgsqlTransaction has completed;it is no longer usable. at Npg相关的知识,希望对你有一定的参考价值。
关于报此异常,原因是事务不能循环提交,一个方法中事务只能提交一次。
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;
以上是关于System.InvalidOperationException:This.NpgsqlTransaction has completed;it is no longer usable. at Npg的主要内容,如果未能解决你的问题,请参考以下文章