GetAll methods

Topic updated 13-6-2007

The Table Template generates GetAll methods in the Factory Class for retrieval of multiple objects/rows. GetAll methods are implemented  using the NHibernate ICriteria interface. Many GetAll method versions include support for Filtering and Sorting. Every Factory Class has six versions of GetAll:

GetAll()

 

GetAll(ICriteria pCriteria)

 

GetAll(ICriteria pCriteria, System.String pSortExpression)

 

GetAll(System.String pSortExpression,

       System.Int32? pFirstResult, System.Int32? pMaxResult)

 

GetAll(ICriteria pCriteria, System.String pSortExpression,

       System.Int32? pFirstResult, System.Int32? pMaxResult)

 

GetAll(ICriteria pCriteria, System.String pSQLExpression, System.String pSortExpression,

       System.Int32? pFirstResult, System.Int32? pMaxResult)

 

All versions of GetAll rely on a centralized implementation in the GetAll version with the most parameters (the last one listed above) by passing calls on to this version.

A central method called GetBasicCriteria is used in all cases where no ICriteria instance is supplied by the caller of GetAll. This includes cases where null is passed for the pCriteria argument.

The centralized implementations of GetAll and GetBasicCriteria provide opportunities to add business logic to Factory Classes in a concise way by adding custom source code to these methods.

The pFirstResult and pMaxResult arguments are useful for dividing data across pages in the user interface. This feature is used in the ASP.NET 2.0 Templates by the Browse Template.

 

 

Code examples

Example of generated code.

       public ProductsCollection GetAll(ICriteria pCriteria, System.String pSortExpression,

                                        System.Int32? pFirstResult , System.Int32? pMaxResult)

 

Custom code example. Get the first ten products that have a description that starts with an X, ordered by unit price.

       ProductsFactory _factory = new ProductsFactory();

       ICriteria _criteria = _factory.GetBasicCriteria().Add(Expression.Like("Description", "X%"));

       ProductsCollection _products = _factory.GetAll(_criteria, "UnitPrice", 0, 10);