流利nHibernate:没有具有给定标识符的行存在。 2个用户删除某个项目时发生错误 [英] Fluent nHibernate: No row with the given identifier exists. Error occurs when 2 users delete some item

查看:579
本文介绍了流利nHibernate:没有具有给定标识符的行存在。 2个用户删除某个项目时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

流利nHibernate:没有具有给定标识符的行存在。



我有一个Object,它有一个Items集合。
我的问题是:当2个用户看到对象和一个用户删除一些项目时发生错误。
其他用户应该看到对象更新,没有删除的项目,而不是异常。



我试过:

  session.Evict(p); 
//下面一行会抛出异常
session.Refresh(p);

没有指定标识符的行[Sistema.ERPxx.Pedidos.ItemPedido#74435]

在映射中指定:

  this.HasMany< ItemPedido>(v => v.Items ).KeyColumn(numero_pedido)。Cascade.All()。OrderBy(descricao_produto)。LazyLoad()。NotFound.Ignore(); 

我遇到这个问题,不知道如何刷新项目,


$ b h2_lin>解决方案

这是一个很好的事情,你得到这个异常。这就是所谓的乐观并发(google it; 这里是一个简单的解释)。

您需要做的是捕获该异常,并将其转换为一些用户可理解的格式。例如:

  catch(WhateverConcurrencyException ex)
{
throw new UserReadableException( + id +不再存在);
}


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?

解决方案

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

这篇关于流利nHibernate:没有具有给定标识符的行存在。 2个用户删除某个项目时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆