Fluent nHibernate:不存在具有给定标识符的行。 2 个用户删除某些项目时发生错误
Fluent nHibernate:不存在具有给定标识符的行。
我有一个对象,它有一个 Items 集合。 我的问题是:当 2 个用户查看该对象并且一个用户删除某些项目时,会发生错误。 其他用户应该看到对象已更新,没有删除的项目,并且没有异常。
我尝试过:
session.Evict(p);
// the following line will throw an exception
session.Refresh(p);
No row with the given identifier exists[Sistema.ERPxx.Pedidos.ItemPedido#74435]
在映射中指定了:
this.HasMany<ItemPedido>(v => v.Items).KeyColumn("numero_pedido").Cascade.All().OrderBy("descricao_produto").LazyLoad().NotFound.Ignore();
我遇到了这个问题,并且不知道如何刷新项目以获取其他用户所做的更新。
如何使用 Items 刷新对象而不出现异常?
Fluent nHibernate: No row with the given identifier exists.
I have an Object, that has a Items collection.
My problem is: Error occurs when 2 users are seeing the object and one user delete some item.
The other user should see the object updated, without the deleted item, and not a Exception.
I tried:
session.Evict(p);
// the following line will throw an exception
session.Refresh(p);
No row with the given identifier exists[Sistema.ERPxx.Pedidos.ItemPedido#74435]
In the mapping it is specified:
this.HasMany<ItemPedido>(v => v.Items).KeyColumn("numero_pedido").Cascade.All().OrderBy("descricao_produto").LazyLoad().NotFound.Ignore();
I am with this problem and does not know how to refresh the Item to get the updates that the other user did.
How to Refresh an object with Items without getting an Exception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到此异常实际上是一件好事。这就是所谓的乐观并发(google一下;这里是一个足够简单的解释)。
您需要做的就是捕获该异常,并将其转换为某种用户可以理解的格式。例如:
it's actually a GOOD thing that you're getting this exception. this is what is called optimistic concurrency (google it; here is a simple enough explanation).
what you need to do is to catch that exception, and translate it into some user-understandable format. for example: