NHibernate provides an innovative approach to handling data with "visibility" rules. A NHibernate filter is a global, named, parameterized filter that can be enabled or disabled for a particular NHibernate session.
Entity Developer for NHibernate provides the possibility to define filter criteria and assign filters to classes and collections. A filter criterion is a restriction clause very similar to the existing "where" attribute available for the class and various collection elements. Furthermore, filter conditions can be parameterized. The application can then decide at runtime whether the filters should be enabled and what their parameter values should be. Filters can be used like database views, but parameterized inside the application.
Prior to using a filter, the following steps should be performed:
• | The filter must be defined; |
• | The filter must be assigned to the appropriate mapping objects. |
This example illustrates the process of work with filters in Entity Developer for NHibernate.
For the purpose of this example, a model is created having two entities connected with an association:
To edit the filters list of the model, select the model (root) node in the Model Explorer, or click on an empty diagram area to display the properties of the model. In the Properties docking window find the Filters parameter and click the three-dotted button next to it. For the purpose of this example, 2 filters are created.
The parameter declared for the filter is as follows:
The parameter declared for the filter is as follows:
A default condition can be defined for a filter, it will work for filtering in case there is no particular condition defined for an entity or a collection. It is possible to define the default condition for this simple example here, but it will be defined further in this section when considering the means of assigning filters to certain objects of the model. |
To assign a filter to the Department entity, perform the following steps:
To assign a filter to the Employees collection navigation property of the Department entity, perform the following steps:
|