Generated code - Using the TypedList classes, Adapter

Preface

LLBLGen 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.  To fetch a TypedList, the DataAccessAdapter.FetchTypedList() method is used.

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();
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
	PredicateExpression additionalFilter = new PredicateExpression(CustomerFields.Country == "Brazil");
	ISortExpression sorter = new SortExpression(OrderFields.OrderId | SortOperator.Ascending);
	adapter.FetchTypedList(orderCustomer, additionalFilter, 0, sorter, false);
}
' [VB.NET]
Dim orderCustomer As New OrderCustomerTypedList()
Using adapter As New DataAccessAdapter()
	Dim additionalFilter As new PredicateExpression(CustomerFields.Country = "Brazil")
	Dim sorter As ISortExpression = New SortExpression(OrderFields.OrderId Or SortOperator.Ascending)
	adapter.FetchTypedList(orderCustomer, additionalFilter, 0, sorter, False)
End Using

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".

note Note:
If you're using one of the FetchTypedList overloads of DataAccessAdapter which accepts IEntityFields2 and an IRelationPredicateBucket, you have to pass the object you get from typedlist.GetFieldsInfo() as the fieldCollectionToFetch value and the object you get from typedlist.GetRelationInfo() as the filterBucket parameter. Otherwise relations of the TypedList aren't detected. If you don't want to filter the typedlist, use the overloads of FetchTypedList which accept a typedListToFill parameter. See the reference manual for details.

When you need to add additional relationships to the filter because you want to filter on entity data related to entities in the TypedList, you need to use the more low-level overloads of FetchTypedList. A TypedList contains code to help you construct the RelationPredicateBucket objects for filtering. Use the GetRelationInfo() method of the TypedList object to get an initial bucket with essential information for fetching the data of the TypedList. Because RelationPredicateBucket objects contain an already existing PredicateExpression object you can start adding filter predicates to the bucket as well as the extra relationship objects. To fetch the TypedList in this case, use the overload which accepts entity fields. See for details about the DataAccessAdapterBase.FetchTypedList methods the LLBLGen Pro runtime framework reference manual.


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