Fluent nHibernate: No row with the given identifier exists. Error occurs when 2 users delete some item

♀尐吖头ヾ 提交于 2019-12-22 11:20:47

问题


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?


回答1:


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:

catch (WhateverConcurrencyException ex)
{
   throw new UserReadableException("The object with id "+id+" no longer exists");
}


来源:https://stackoverflow.com/questions/5580916/fluent-nhibernate-no-row-with-the-given-identifier-exists-error-occurs-when-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!