Telerik OpenAccess Classic

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

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.

This topic shows how to filter query results. The example returns a collection of Orders objects that represents all orders made from France which have freight more than 100.

The examples in this topic are based on the Northwind Data Model. To run the code in this example, you must have already added the Northwind Data Model to your project and configured your project to use the OpenAccess ORM. 

VB .NET Copy Code
Dim scope As IObjectScope = ObjectScopeProvider1.GetNewObjectScope()
   scope.Transaction.Begin()
   Dim result = From c In scope.Extent(Of Order)() _
                Where c.ShipCountry.Contains("France") AndAlso c.Freight>100 _
                Select c
   scope.Transaction.Commit()
   For Each ord As Order In result
    Console.WriteLine(ord.ShipCountry & " " & ord.Freight)
   Next ord
   scope.Dispose()
   Console.ReadKey()
C# Copy Code
IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           scope.Transaction.Begin();               
           var result = from c in scope.Extent<Order>()
                        where c.ShipCountry.Contains(
"France") && c.Freight>100                       
                        select c;
           scope.Transaction.Commit();
           
foreach (Order ord in result)
           {
               Console.WriteLine(ord.OrderID+
" "+ord.ShipCountry + " " + ord.Freight);
           }
           scope.Dispose();
           Console.ReadKey();

The following is OQL query example

VB .NET Copy Code
 Dim query = "Select * From OrderExtent as x where x.shipCountry =='France' and x.Freight>100"
   Dim scope As IObjectScope = ObjectScopeProvider1.GetNewObjectScope()
   scope.Transaction.Begin()
   Dim result = scope.GetOqlQuery(query).Execute()
   scope.Transaction.Commit()
   For Each ord As Order In result
    Console.WriteLine(ord.OrderID & " " & ord.ShipCountry & " " & ord.Freight)
   Next ord
   Console.ReadKey()
C# Copy Code
var query = "Select * From OrderExtent as x where x.shipCountry =='France' and x.Freight>100";
           IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           scope.Transaction.Begin();
           var result = scope.GetOqlQuery(query).Execute();
           scope.Transaction.Commit();
           
foreach (Order ord in result)
           {
               Console.WriteLine(ord.OrderID +
" " + ord.ShipCountry + " " + ord.Freight);
           }
           Console.ReadKey();

The following is a SQL query

VB .NET Copy Code
Dim query = "select * from orders as x where x.shipCountry = 'France' and x.Freight>100"
   Dim scope As IObjectScope = ObjectScopeProvider1.GetNewObjectScope()
   scope.Transaction.Begin()
   Dim result = scope.GetSqlQuery(query,GetType(Order),Nothing).Execute()
   scope.Transaction.Commit()
   For Each ord As Order In result
    Console.WriteLine(ord.ShipCountry)
   Next ord
   Console.ReadKey()
C# Copy Code
var query = "select * from orders as x where x.shipCountry = 'France' and x.Freight>100";
           IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           scope.Transaction.Begin();           
           var result = scope.GetSqlQuery(query,
typeof(Order),null).Execute();
           scope.Transaction.Commit();
           
foreach (Order ord in result)
           {
               Console.WriteLine(ord.ShipCountry);
           }
           Console.ReadKey();

The following is a parameterized query:

VB .NET Copy Code
Dim query = "select * from orders as x where x.shipCountry = 'France' and x.Freight>?"
   Dim parameters As String = "decimal param"
   Dim scope As IObjectScope = ObjectScopeProvider1.GetNewObjectScope()
   scope.Transaction.Begin()
            Dim result = scope.GetSqlQuery(query, GetType(Order), parameters).Execute(100)
   scope.Transaction.Commit()
   For Each ord As Order In result
    Console.WriteLine(ord.ShipCountry & " " & ord.Freight & " " & ord.OrderID)
   Next ord
   Console.ReadKey()
C# Copy Code
var query = @"select * from orders as x where x.shipCountry = 'France' and x.Freight>?";
           
string parameters = "decimal param";
           IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           scope.Transaction.Begin();           
           var result = scope.GetSqlQuery(query,
typeof(Order),parameters).Execute(100);
           scope.Transaction.Commit();
           
foreach (Order ord in result)
           {
               Console.WriteLine(ord.ShipCountry+
" "+ord.Freight+" "+ord.OrderID);
           }
           Console.ReadKey();