LightSpeed supports the use of stored procedures and user-defined functions for selecting entities. This support is database-dependent.

Selecting Entities Using a Stored Procedure

To select entities, call IUnitOfWork.Find, passing a ProcedureQuery. The ProcedureQuery must specify the name of the stored procedure in the database, and provide any input or output parameters expected by the stored procedure in the form of ProcedureParameter objects. The Find method returns the list of entities returned by the stored procedure.

Saving Changes Using Stored Procedures

If you wish to use stored procedures for all database access, including inserts, updates and deletes, you must declare your entities as procedure-backed, and specify the stored procedures for each CRUD operation (select, insert, update and delete), plus for select by ID. To do this:

In either case, the Select and Select By Id procedures must adhere to the standard stored procedure requirements and conventions described below. In addition, Select By Id must take a single parameter named Id (the parameter name can be overridden using Identity Column Name or TableAttribute.IdColumnName).

Stored Procedure Requirements and Conventions

The returned record set is treated exactly the same as if it had been returned by performing a table SELECT. Therefore:

Stored Procedures in the Designer

If you model stored procedures in the designer, the designer generates methods on the strong-typed unit of work which create the ProcedureQuery and ProcedureParameter objects for you, and present a conventional .NET method interface such as IList<Product> GetCheapItems(decimal maxPrice).