Reputation: 1688
What Im trying to do is this: http://www.janblaha.net/blog/nhibernate-multitenancy-in-shared-database
This is my filter definition:
public class MultitenancyFilter : FilterDefinition
{
public MultitenancyFilter()
{
WithName("multitenancy").WithCondition("TenantId= :tenantId").AddParameter("tenantId", NHibernate.NHibernateUtil.Int32);
}
}
Then, I do my query like this:
_session.EnableFilter("multitenancy").SetParameter("tenantId", tenantId);
var people = _session.QueryOver<Person>().List().ToList();
where tenantId is some int.
But the NHibernate never generates the filter in the query. The query is generated without 'where' clausure at all.
Am I missing some configuration or some concept?
NHibernate Version 4.0.0.4000.
PS. When debuggin, the _session has a property called EnabledFilter, and my filter is listed there. So, whats wrong?
Upvotes: 1
Views: 566
Reputation: 2879
According with NHibernate documentation you can attach the filter to your class after having the definition:
<class name="MyClass" ...>
...
<filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
</class>
If you are using Fluent NHibernate you can also use this reference.
Upvotes: 1