Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate filters don't work with Session.Get

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)

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?

Thanks

like image 965
Khash Avatar asked Mar 04 '09 18:03

Khash


1 Answers

quote from Fabio Maulo:

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

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.

like image 145
Peter Avatar answered Oct 02 '22 20:10

Peter