c#-4.0 - Fluent nHibernate : No row with the given identifier exists. 2个用户删除某些项目时发生错误

标签 c#-4.0 fluent-nhibernate

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 刷新对象?

最佳答案

您收到此异常实际上是一件好事。这就是所谓的乐观并发(google 一下;here 是一个足够简单的解释)。
您需要做的是捕获该异常,并将其转换为某种用户可理解的格式。例如:

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

关于c#-4.0 - Fluent nHibernate : No row with the given identifier exists. 2个用户删除某些项目时发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5580916/

相关文章:

c# - 我如何在 C# 中调用 getter 或 setter

visual-studio-2010 - 获取使用 C# Process.Start 启动的程序的进程 ID

asp.net - 如何防止 ?Area= 添加到生成的 URL 中

vb.net - 如何告诉 Fluent NHibernate 在不进行自动映射的情况下忽略特定属性?

c# - 具有默认值的 DateTime 的 Fluent NHibernate 映射

fluent-nhibernate - 流畅的映射基类 - 尝试在已添加属性时添加属性

c# - 方法的类型推断,具有泛型和类继承

c# - C# 中的菊花链方法

c# - 使用 NHibernate 的 SqlDateTime 溢出

c# - NHibernate 保存或更新,错误 : No persister for