nhibernate - 在 NHibernate 中的映射级别过滤实体

标签 nhibernate

假设我有名为 People 的数据库表和实体 People。假设我需要一种快速的方法来删除一部分人,使其不在应用程序中随处显示。因此,我将 IsDeleted 列添加到 People 表,并将该列中的值设置为 1。

在 Entity Framework 中,有一种机制指定不应获取列 IsDeleted 中的值设置为 1 的实体实例,并且映射框架会自动过滤数据。有可能用 NHibernate 实现吗?

最佳答案

您可以在 class mapping 中定义 where 属性.

where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class

<class ... where="IsDeleted = 0">

如果您使用的是 Fluent NHibernate,那么只需在映射类中定义它:

Where("IsDeleted = 0");

NH 的代码映射应该类似于 Fluent NHibernate 的映射。

关于nhibernate - 在 NHibernate 中的映射级别过滤实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10899503/

相关文章:

c# - 为什么 MSDTC 在使用 mstest 进行单元测试时表现不一致?

c# - PropertyDescriptor.SetValue 在 ModelBinder 中不起作用

c# - 默认启用 Nhibernate 过滤器

nHibernate 使用 Criteria API 的多对多查询

winforms - WinForms 的 NHibernate 设计

c# - 使用 NHibernate 在 SQL 数据库中存储字节数组的最佳方法是什么?

asp.net-mvc - 如何分配数据层级过滤器

c# - NHibernate BasicSample 与 Nhibernate 3.3

asp.net - 当 UnitOfWork 是整个请求时,如何最好地通知用户 NHibernate 异常?

c# - nhibernate 不级联删除 child