Using the TypedList classes

LLBLGen Pro supports read-only lists based on a selection of entity fields from one or more entities with a relationship, called a TypedList. This section discusses how to generate typed lists as either a Typed Datatable or a POCO class and how to fetch the typed views at runtime.

Choosing the Typed List class type

Which class is generated for a Typed List is determined by its OutputType setting. This setting is found on the Typed List's Code gen. Info tab in the designer and its default value is obtained from the TypedListOutputTypeDefault setting located in the LLBLGen Pro framework section of the Project Settings. There are three values to choose from:

  • TypedDataTable (default)
  • PocoWithLinqQuery
  • PocoWithQuerySpecQuery

The default is TypedDataTable, which will result in what has been the case since the beginning: a DataTable-derived class which is retrievable using the low-level api. The other two are both resulting in a class, typedViewNameRow, and a query to fetch the typed list, either in Linq or in QuerySpec. 

It's recommended to use the TypedListOutputTypeDefault setting to set the output type of your typed lists in one go. You can also set the OutputType setting on individual typed lists in bulk using the Bulk Element Setting Manipulator in the designer.

Instantiating and using a TypedList

Depending on the OutputType chosen for a given typed list, fetching a typed list is done as follows

OutputType: TypedDataTable

Using a TypedList is similar to using a TypedView, both will be generated as typed DataTables. There is a difference however in how you formulate filters and sortclauses for a TypedList. The reason for this is that a TypedList is constructed using existing entity fields, while a TypedView uses its own field definitions.

When you want to construct a filter for a TypedList, you have to specify field indexes of fields in the entities which are the base of the typed list; you can filter on fields which are not included in the typed list itself as in the column set of the typed list.

In the example below, we'll use a TypedList created from the entities Customer and Order and include the following fields in the resultset: Order.OrderID, Order.OrderDate, Order.ShippedDate, Customer.CustomerID, Customer.CompanyName. You can filter on any field in Order or Customer or both.

Also, you can sort on any field in Order or Customer or both. Let's filter this TypedList on all orders from customers from 'Brazil', and sort the list on the field Order.Freight, ascending. The TypedList is called OrderCustomer.

var orderCustomer = new OrderCustomerTypedList();
var filter = new PredicateExpression(CustomerFields.Country.Equal("Brazil"));
var sorter = new SortExpression(OrderFields.Freight.Ascending());
// Set allowDuplicates to true, because we sort on a field that is not in our resultset and we use SqlServer.
orderCustomer.Fill(0, sorter, true, filter);
Dim orderCustomer As New OrderCustomerTypedList()
Dim filter As New PredicateExpression(CustomerFields.Country.Equal("Brazil"))
Dim sorter As New SortExpression(OrderFields.Freight.Ascending())
' Set allowDuplicates to true, because we sort on a field that is not in our resultset and we use SqlServer.
orderCustomer.Fill(0, sorter, True, filter)

The TypedList object is now filled with the rows for the 5 columns we've specified in the TypedList editor, sorted on Order.Freight ascending and filtered on Customer.Country equals "Brazil".

OutputType: PocoWithLinqQuery

When choosing PocoWithLinqQuery as the OutputType of a typed list, a Linq query is generated into the LinqMetaData class in the form of a method: GetTypedListNameTypedList(). This method returns an IQueryable<T> where T is the type of the POCO class generated for the typed list: TypedListNameRow.

To fetch the query, one has to enumerate the returned IQuerable<T>, as is always the case with Linq. The IQueryable<T> can be appended with joins, where calls and e.g. order by calls to further shape the query.

OutputType: PocoWithQuerySpecQuery

For the QuerySpec variant it's similar to the PocoWithLinqQuery variant: the same class as with the Linq variant is generated: TypedListNameRow, and a method is added to the QueryFactory class for QuerySpec, called GetTypedListNameTypedList() which returns a DynamicQuery<T>, where T is the name of the class generated for the TypedList, TypedListNameRow.

To fetch the query, one has to use one of the usual QuerySpec fetch methods for fetching a DynamicQuery<T> . The returned DynamicQuery<T> can be further configured by appending where clauses, order by clauses like one would do with a normal DynamicQuery<T> query.