NHibernate的过滤器不与Session.Get工作过滤器、不与、工作、NHibernate

2023-09-04 09:35:21 作者:网友

我想实现一个软删除的存储库。通常这可以容易地与一个删除事件侦听器完成。为了筛选出已删除的实体,我可以添加一个其中,属性上我的课的映射。不过,我也需要实现在此实体仓库两个方法:恢复和清除。恢复将恢复删除的实体和清除将难以删除它们。这意味着我不能使用其中的属性(因为它阻止了软删除实体的任何访问)

I'm trying to implement a Soft-deletable repository. Usually this can be easily done with a Delete Event listener. To filter out the deleted entities, I can add a Where attribute to my class mapping. However, I also need to implement two more methods in the repository for this entity: Restore and Purge. Restore will "undelete" entities and Purge will hard-delete them. This means I can't use Where attribute (since it block out soft-deleted entities to any access)

我试图用的过滤器代替。我可以创建一个过滤器,并启用或内会话禁用它以达到相同的结果。但问题是过滤器不会对Session.Get方法没有任何影响(它们只影响的ICriteria的访问)。

I tried using filters instead. I can create a filter and enable or disable it within session to achieve the same result. But the problem is filters don't have any effect on Session.Get method (they only affect ICriteria based access).

任何想法如何解决这个问题?

Any ideas as to how solve this problem?

感谢

推荐答案

引述法比奥Maulo:

quote from Fabio Maulo:

通过design.Filters不获取或负载工作,因为他们的意思是:我想要   加载与此ID的实体。

By design.Filters don't work with Get or Load since they mean: I want load the entity with this ID.

动态滤波器HQL /标准和采集工作(其中启用   对于集合),只有当你使用显式联接,或者更一般的,   当一个查询的QuerySpace一个过滤器匹配,该QuerySpace

Dynamic filters work with HQL/Criteria and Collection(where enabled for a collection) only when you use explicit joins or, more general, when the QuerySpace of a filter match with the QuerySpace of a query.