Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Execute a Query Using a Stored Procedure
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Querying a Data Model > How to: Execute a Query Using a Stored Procedure

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

Currently OpenAccess ORM only supports stored procedure calls and SELECT statements. Statements such as : "DELETE FROM Table WHERE ..." or "INSERT INTO Table ..." are not supported. This is to ensure consistency between the IObjectScope content and the database content. It also implies that all query expressions not starting with "SELECT" are treated as stored procedure names.
An example calling SQL stored procedure

VB .NET Copy Code
Dim scope As IObjectScope = ObjectScopeProvider1.GetNewObjectScope()
Dim resultQuery As IQuery = scope.GetSqlQuery("Ten Most Expensive Products", Nothing, Nothing)
Dim result As IQueryResult = resultQuery.Execute()
For Each pr As Object() In result
 Console.WriteLine(pr(1) + " " + pr(0))
Next
C# Copy Code
           IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           IQuery resultQuery = scope.GetSqlQuery("Ten Most Expensive Products", null, null);
           IQueryResult result = resultQuery.Execute();
           
foreach (object[] pr in result)
           {
               Console.WriteLine(pr[1] +
" " + pr[0]);
           }
For the above example the Northwind Database is used.
The result that is returned from the "Ten Most Expensive Products" returns only the product name and product price,thus making it impossible for us to cast the result to specific type. Instead we will need to retrieve every record in the result set using array of objects. Each object from this array will have one of the values returned from the stored procedure.