NHibernate filters do not work with Session.Get

I am trying to implement a soft-deleted repository. This can usually be easily done using the "Delete Event" listener. To filter out deleted objects, I can add the Where attribute to map classes. However, I also need to implement two more methods in the repository for this object: Restore and Clear . Restore will "restore" entities, and Purge will delete them. This means that I cannot use the Where attribute (since it blocks objects with soft deletes for any access)

I tried to use filters . I can create a filter and enable or disable it in a session to achieve the same result. But the problem with the filters does not affect the Session.Get method (they only affect access based on ICriteria).

Any ideas on how to solve this problem?

thanks

+7
nhibernate
source share
2 answers

Quote from Fabio Molo:

By design. Filters do not work with Get or Load, as they mean: I want to load an object with this identifier.

Dynamic filters work with HQL / Criteria and Collection (where it is included for the collection) only when using explicit joins or, more generally, when the QuerySpace filter matches the QuerySpace query.

+2
source share

Will an IInterceptor work for this?

Looking at the EmptyInterceptor, I found that it has OnLoad, which I think you can use to intercept the loading of an object.

0
source share

All Articles