Note: This documentation is preliminary and is subject to change.
Generates a stored function representing the behaviour of a member in the underlying relational database system.
The <StoredFunction> element generates a stored function named stored-function in the underlying relational database system, representing the behaviour of the member. If member is an instance member, the type on which it is declared must be either scalar or persistent. The parameters of the member have to be of either scalar or persistent type.
Since stored functions can only have
parameters, the persistent parameters of
member are represented as a tuple of parameters associated to the persistent fields
of the parameter type. The database type of the stored function parameters is determined by the type
of the member parameters for
parameters or by the database
type of the persistent fields for persistent parameters. The database type assigned to scalar parameters
can be changed by specifying database-type-modifiers on the appropriate
If member is an instance member, the implicit
parameter is represented in the parameter list of stored-function, following
the same rules as are used for parameters. To change the database type assigned to the scalar
this parameter, database-type-modifiers have to be specified on
The return type of stored-function can also be specified by using
database-type-modifiers on the
The parameter list of the generated function is managed by Genome . The only parameters, and fields of the persistent type parameters, that are represented as stored function parameters are those which are referenced from the expression or necessary to execute the member calls within the expression.
The generated stored functions are bound to a specific version of the schema. As a step of schema compilation, SQL scripts that create the stored functions are also generated. The database script file generated by schema compiler contains these scripts and the compiler also supports automatic creation of stored functions on a specific database when compiling a schema. The T-SQL source generated for stored functions contains summary information of the compiled schema that can be used to identify possible version mismatches.
This example shows how to create a stored function for the
Order class, defined in the example of
<Type name="Order"> <Member name="GetSumPrice"> <!-- a stored function "Northwind.Business.Order.GetSumPrice(@fp_this_Order_Id int)" will be created --> <Oql source="Sql.Sum([UnitPrice * Quantity]extentof(OrderDetails)[od: od.Order == this])" StoredFunction="true" /> </Member> <Member name="CalcSum" signature="double, int"> <!-- a stored function "SF_CALCSUM(@fp_this_Order_Id int, @fp_discount float, @fp_shippingCost int)" will be created --> <Oql source="(1 - discount) * GetTotalPrice() + shippingCost"> <StoredFunction name="SF_CALCSUM" /> </Oql> </Member> </Type>
Editions: Professional, Evaluation
Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2