在NHibernate中的映射级别过滤实体 [英] Filter entities on mapping level in NHibernate

查看:40
本文介绍了在NHibernate中的映射级别过滤实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一个名为People的数据库表,和一个实体People.假设我需要一种快速的方法来从显示在应用程序中的所有位置中删除一部分人.因此,我将IsDeleted列添加到People表中,并将该列中的值设置为1.

Let's say that I have and database table called People, and entity People. Let's say that I need a quick way to remove a subset of people from displaying everywhere in application. So I add IsDeleted column to People table, and set values in that column to 1.

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

In Entity Framework there's a mechanism that specifies that for instans of entities with value in column IsDeleted set to 1 shouldn't be fetched and mapping framework filters data automatically. Is is possible to achieve with NHibernate?

推荐答案

您可以创建抽象类,例如PeopleBase,将从其派生People类并将您的实体映射到该类.
之后,您可以使用像这样的鉴别器(无法检查正确性,但是应该可以):

You can create abstract class, e.g. PeopleBase, from which your People class will be derived and map your entity to it.
After that you can use discriminator like this (didn't check for correctness, but it should work):

 <class name="YourNamespace.PeopleBase,YourNamespace" table="People">
   // ...
   <discriminator column="IsDeleted" type="boolean" /> 
   // Properties...
   // ...
   <subclass name="YourNamespace.People, YourNamespace" discriminator-value="false">
   </subclass>
</class>

这篇关于在NHibernate中的映射级别过滤实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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