Is there a way to add criteria to a mapping for NHibernate?
public class Course {
public IList Participants { get; set; }
public IList&l
It seems, that in this case, we would need "dynamic" filtering. The mapped collection will sometimes contain contain all records, sometimes just those which meet some filtering criteria.
Exactly for this, we have:
NHibernate adds the ability to pre-define filter criteria and attach those filters at both a class and a collection level. A filter criteria is the ability to define a restriction clause very similiar to the existing "where" attribute available on the class and various collection elements. Except these filter conditions can be parameterized. The application can then make the decision at runtime whether given filters should be enabled and what their parameter values should be. Filters can be used like database views, but parameterized inside the application.
In order to use filters, they must first be defined and then attached to the appropriate mapping elements. To define a filter, use the element within a element:
Then, this filter can be attached to a class:
...
or, to a collection:
Check more details here (xml)
(fluent mapping)