NHibernate Class Level Filtering
Nov 02 2008 01:09 PM Filed in: .NET
While this information is available in the NHibernate
documentation, it’s easy to overlook. If you
have a filter you apply to all of your queries
through a ‘Where’ clause in NHibernate, you can
place that ‘Where’ clause in your HBM file at
the class level.
For example, we don’t delete data where I work, we need it for historical reporting and for searching. Instead of deleting we usually have an active indicator. What this causes is all of our queries always have “WHERE ACTIVE_IND = ‘Y’” tacked onto the end. Instead of doing that we can just place this in our HBM and it will automatically be applied to any query.
<class name=”className” table=”tableName” where=”ACTIVE_IND = ‘Y’”>
...
</class>
I want to thank my co-worker Kevin Brill for pointing this out.
For example, we don’t delete data where I work, we need it for historical reporting and for searching. Instead of deleting we usually have an active indicator. What this causes is all of our queries always have “WHERE ACTIVE_IND = ‘Y’” tacked onto the end. Instead of doing that we can just place this in our HBM and it will automatically be applied to any query.
<class name=”className” table=”tableName” where=”ACTIVE_IND = ‘Y’”>
...
</class>
I want to thank my co-worker Kevin Brill for pointing this out.
|