Using Table Valued Functions

In the designer you can map a typed view or an entity onto the resultset of a Table Valued Function. This always results in a Table Valued Function Call being present in the project besides the mapped element being present: the Table Valued Function Call returns the entity or Typed View as return element.

In the generated context class, a method is generated for every Table Valued Function call in the project, with the name equal to the Table Valued Function Call. The method has a parameter for every Table Valued Function parameter, equal to the call methods for normal stored procedure calls.

The generated method returns an IQueryable<EntityName> object if the return element is an entity and an IQueryable<TypedViewNameTypedViewRow> object if the return element is a typed view. The returned element is usable as a source for a linq query.

In the example below a Typed View, called TvfOrders is mapped onto the resultset of the Table Valued Function GetOrdersForCustomer which returns all orders for a given CustomerId

var ctxt = new NorthwindDataContext();
var typedViewRows = ctxt.GetOrdersForCustomer("ALFKI").Where(o=>o.EmployeeId==4);
// typedViewRows is of type IQueryable<TvfOrdersTypedViewRow>
Dim ctxt As New NorthwindDataContext()
Dim typedViewRows = ctxt.GetOrdersForCustomer("ALFKI").Where(Function(o) o.Employee=4)
' typedViewRows is of type IQueryable(Of TvfOrdersTypedViewRow)