great article!
I recently used filters with Monorail controller actions. Instead of an interceptor I created a Filter subclass to pull values from the engine context and apply the filter. works like a charm.
Great article indeed!!
However, unless I've missed a point there, it seems the article is somewhat dated- since NH maps enums to strings automatically nowadays, the current code throws an exception when it tries to convert the Context column value (of type nvarchar - string) into int in order to execute the WHERE @p = Context.
What I had to do in order for it to work was replace the filter parameter type adding with this:
filterParametersType.Add("current", NHibernateUtil.String);
and then the SetSession method was replaced with the following code:
session.EnableFilter("contextFilter").SetParameter("current", Context.Current.ToString());
Not a big change, but in case someone gets stuck on this :)
Otherwise, the only thing that I find a bit of a shame is that when replacing the filtering with something like
":current >= Context"
this works on alphabetical rather than enum/numeric order...
Excellent article!
Just hit a snag with this approach where one of the context-aware objects was referenced by another class. Filters don't seem to be applied to references when the EntityJoinWalker does it's magic. According to the Hibernate folks filters should never apply in associations (see opensource.atlassian.com/.../HHH-4026). Any thoughts?