I am using nHibernate 2.1.2.4000 with Asp.Net 4.
I also have a mapping defined for an Entity. The mapping also defines a filter named CultureCode.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Demo.EntityCore.Domain.Option, Demo.EntityCore" table="tbl_options">
<id name="Id" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="optionName" type="String" />
<bag name="OptionTrans" table="tbl_options_trans" cascade="all-delete-orphan" >
<key column="optionId" not-null="true"/>
<one-to-many class="Demo.EntityCore.Domain.OptionTran, Demo.EntityCore"/>
<filter name="cultureFilter" condition=":cultureCode = CultureCode"/>
</bag>
</class>
<filter-def name="cultureFilter">
<filter-param name="cultureCode" type="String" />
</filter-def>
</hibernate-mapping>
The filter works fine if I load the entity as shown below and I get the filtered value in the list 'OptionTrans'
string cultureCode = Thread.CurrentThread.CurrentCulture.Name;
ISession session = GetSession();
session.EnableFilter("cultureFilter").SetParameter("cultureCode", cultureCode);
var option = unitOfWork.Session().CreateCriteria<Option>()
.Add(Restrictions.Eq("Id", 1))
.UniqueResult<Option>();
return product;
However if I change the lazy property of 'OptionTrans' field as false like shown below.
<bag name="OptionTrans" table="tbl_options_trans" cascade="all-delete-orphan" lazy="false">
The filter specified above does not work and I get all the values in 'OptionTrans'.