TechTalk Genome v4.2

<StoredFunction> Element

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.

<Member name=" member ">
<Oql source=" oql-expression " StoredFunction="(true|false)">


<Member name=" member ">
<Oql source=" oql-expression " >
<StoredFunction [name="stored-function"] >
[<This [database-type-modifiers] />]
[<Return [database-type-modifiers] />]
(<Param name="parameter" [database-type-modifiers] />)*
A member name specifying a property or a method that has a scalar return type. 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 either of scalar or persistent type.
An OQL expression returning a value that is compatible with the return type of the member.
An identifier specifying the name of the stored function to be generated. The fully qualified name of member is used if stored-function is omitted.
Name of a member parameter.
An optional list of database type modifiers that can change the type of the stored function parameter. The default mapping for the type of the parameter, the object instance or the return type is used if no modifier is specified. The defaults can be found in the description of the Database Type Modifiers.


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 scalar 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 scalar 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 <Param> element.

If member is an instance member, the implicit this 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 <This> element.

The return type of stored-function can also be specified by using database-type-modifiers on the <Return> element.

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 GetSumPrice and CalcSum methods of the Order class, defined in the example of <Oql> element .

<Type name="Order">

    <Member name="GetSumPrice">
        <!-- a stored function "Northwind.Business.Order.GetSumPrice(@fp_this_Order_Id int)" will be created -->
            source="Sql.Sum([UnitPrice * Quantity]extentof(OrderDetails)[od: od.Order == this])"
            StoredFunction="true" />
    <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" />


Type: TechTalk.Genome.Mapping.StoredFunctionXmlData

Assembly: TechTalk.Genome.dll

Version: 4.2.11

Editions: Professional, Evaluation

Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2

See Also

Member Mappings | <Oql> Element