Using Typed Views

For Linq to Sql, LLBLGen Pro supports Typed View definitions mapped onto tables, views and stored procedure resultset. You can map a Typed View on a single resultset, and the stored procedure returning the resultset can return a single resultset or multiple resultsets.

If you map a typed view on a resultset of a stored procedure which returns more than one resultset and you don't map a typed view on the other resultsets, you'll get a validation error. The class name of a row in the typed view is TypedViewNameTypedViewRow.

Typed views mapped onto a table or view

A typed view mapped onto a table or view is retrievable like an entity and usable in queries like entities, with one difference: the property on the DataContext class has the suffix TypedView.

Example: a typed view called Invoices which is mapped onto the view Invoices of the Northwind database is accessable and retrievable through the property InvoicesTypedView on the generated DataContext class.

Typed View mapped onto a Table Valued Function

See for more information about a Typed View mapped onto a Table Valued Function Using Table Valued Functions.

Typed views mapped onto a stored procedure resultset

In the generated context class, a method is generated for every stored procedure which returns one or more resultsets and where at least one typed view definition is mapped onto these stored procedure resultsets. The method name is GetTypedViewName.

If the stored procedure returns more than one resultset, every resultset has to have a typed view mapped onto it. There can be more than one typed view mapped onto a resultset, which can give multiple combinations of typed view definitions for the set of resultsets returned by the stored procedure. For every combination a method is generated called GetTypedViewName1TypedViewName2...TypedViewNamen.

Each generated method has a parameter for every stored procedure parameter, equal to the call methods for normal stored procedure calls. If the stored procedure returns a single resultset, the return value of the stored procedure is ISingleResult<TypedViewNameTypedViewRow>.

If the stored procedure returns multiple resultsets, the return type is IMultipleResults. The returned object in that case contains the sets of typed view row instances in the same order as the stored procedure returns them.

In the example below two typed views are mapped onto the resultsets of a single stored procedure. The stored procedure returned for the given country parameter value all customers in the first resultset and all orders of these customers in the second resultset.

The typed view mapped onto the first resultset is called Customers and the typed view mapped onto the second resultset is called Orders.

var ctxt = new NorthwindDataContext();
var results = ctxt.GetCustomersOrders("USA");
var customers = results.GetResult<CustomersTypedViewRow>();
var orders = results.GetResult<OrdersTypedViewRow>();
Dim ctxt As New NorthwindDataContext()
Dim results = ctxt.GetCustomersOrders("USA")
Dim customers = results.GetResult(Of CustomersTypedViewRow)()
Dim orders = results.GetResult(Of OrdersTypedViewRow)()