Postgre The database operation was expected to affect 1 row(s), but actually affected 0 row

语言C#
框架ABP
最近在开发时, 提交事务时,偶现以下错误:

The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. 

初始的调查方向是:
跨线程操作
异步操作dbcontext

最后确认下来都不是,最后发现是update 的方法中,新建了一个entity, 使用了仓储的 UpdateAsync,
会导致这个问题;

结论: UpdateAsync时,一定要是已经存在的对象, 新建的对象只能用InsertAsync, 切记使用UpdateAsync

你可能感兴趣的:(Postgre,Database,sql,数据库)