Using Typed Lists

When you create a Typed List definition in the designer, it will be generated as a HQL query and a typed class. The HQL query is created and returned by a static method called GetTypedListNameQuery, and which is located in the generated TypedListQueryFactory class in the ProjectName.Persistence VS.NET project.

The typed list methods return an IQuery object. Per typed list there are two overloads generated: one which only accepts the ISession, and one which accepts besides the ISession object also an additional query fragment in HQL format.

Per defined typed list, a class called TypedListNameTypedListRow is generated, in the ProjectName.Model VS.NET project and which are simple classes which contain properties which reflect the fields you added to the typed list definition in the designer. The projection executed is transformed using the AliasToBeanResultTransformer class, shipped with NHibernate.

Aliases

If an entity is aliased in the TypedList definition, the alias is used in the emitted query. If the entity isn’t aliased, the HQL query will use as the alias for the entity: a_entitynamelowercase.

Example

In the example below, the typed list OrderCustomer is fetched and it appends a where clause to the generated query using HQL syntax. It furthermore limits the query to 20 rows max. As the 'Customer' entity in the typed list definition isn't aliased, the reference to that entity has to be done through the alias it receives in the HQL query, which uses the pattern (see above) a_entityname, which results in the alias a_customer.

ISession session = SessionManager.OpenSession();
IList<OrderCustomerTypedListRow> results = 
        TypedListQueryFactory.GetOrderCustomerTypedListQuery(
                    session, 
                    "where a_customer.Address.Country=:country")
            .SetParameter("country", "USA")
            .SetMaxResults(20)
            .List<OrderCustomerTypedListRow>();