Is it possible to use NHibernate Filters to filter through references?

后端 未结 1 864
日久生厌
日久生厌 2020-12-19 23:30

Contrived example, but let\'s say I have a these entities:

public class Root
{
    public virtual Customer Customer { get; set; }
}

public class Customer
{
         


        
相关标签:
1条回答
  • 2020-12-20 00:30

    What could be working, is to move the filter to the CustomerData object if possible, or to create "more sophisticated SQL condition" applied on the Customer mapping. But it is about pure SQL, no references. How do the filters work?

    The filters are the same as the where clause, but could be adjusted in a runtime. The extract from documentation 18.1. NHibernate filters

    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.

    The definition of the where:

    where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class

    Other words, these settings act as "add on" to our mapping. They are extending it (both where and filter) with more SQL balast. The filter could be shared among many mappings and applied to all queries inside one session, but it must target the column:

    condition=":myFilterParam = MY_FILTERED_COLUMN"
    
    0 讨论(0)
提交回复
热议问题