开发者

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

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 followin开发者_运维知识库g 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?


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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜