Generated code - Using the TypedList classes, SelfServicing

Preface

LLLBLGen Pro supports read-only lists based on a selection of entity fields from one or more entities with a relationship, called a TypedList. A TypedList is generated as a typed DataTable, which is a variant of the typed DataSet concept included in Visual Studio.NET. A typed DataTable is a class which derives from the .NET DataTable and defines properties and a row class to access the individual fields in a typed fashion.

In this section the TypedList classes are briefly discussed and their usage is illustrated using examples.

Instantiating and using a TypedList

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.

// [C#]
OrderCustomerTypedList orderCustomer = new OrderCustomerTypedList();
IPredicateExpression filter = new PredicateExpression(CustomerFields.Country == "Brazil");
ISortExpression sorter = new SortExpression(OrderFields.Freight | SortOperator.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);
' [VB.NET]
Dim orderCustomer As New OrderCustomerTypedList()
Dim filter As New PredicateExpression(CustomerFields.Country="Brazil")
Dim sorter As New SortExpression(OrderFields.Freight Or SortOperator.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".

LLBLGen Pro Runtime Framework v4.1 documentation. ©2013 Solutions Design bv