T
Chili.Opf3 Send comments on this topic.
Generic ObjectQuery Class
See Also  Members   Example 
Chili.Opf3.Query Namespace : Generic ObjectQuery Class




Represents a storage independent query.

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class ObjectQuery(Of T) 
   Implements IQuery 
Visual Basic (Usage)Copy Code
Dim instance As ObjectQuery(Of T)
C# 
public sealed class ObjectQuery<T> : IQuery  
Managed Extensions for C++ 
public __gc __sealed class ObjectQuery<T> : public IQuery  
C++/CLI 
generic<typename T>
public ref class ObjectQuery sealed : public IQuery  

Type Parameters

T

Example

The following example shows how to use ObjectQuery in your application.
C#Copy Code
// ... Other code 
 
// Create an ObjectQuery for User persistent objects. 
// The query contains the following: 
// - Two conditions that check the user name of the objects and load only the matching ones. 
// - A simple join that loads only user with one or more calls of duration 1. 
// - A sort option that sorts the result by UserName. 
ObjectQuery<User> objectQuery = new ObjectQuery<User>( 
    "(UserName Like {0} Or UserName Like {1}) And Call[Duration = {2}] SortBy UserName Asc", 
    "%hri%", "%No%", 1); 
 
// Get an ObjectSet that contains the result of the query. 
ObjectSet<User> objectSet = context.GetObjectSet<User>(query); 
 
// ... Other code.

Remarks

This class represents a storage independent query. The query is then compiled by the framework and executed on a class that implements the IStorage interface. When creating an ObjectQuery you may specify different conditions, simple joins and sort options.

ObjectQueries may be used in any part of your application, since they are storage independent. You should always check if you can use an ObjectQuery before switching to the SqlQuery. Perhaps you can move some of the joins directly to the storage (stored procedure or view) to avoid using SqlQuery.



OPath
OPath is a storage indepentend query language that is transformed to a storage dependent query at runtime. The language understands various different types of statements right now. In a statement you must always use the property names of the corresponding persistent object. All the OPath is translated to a storage depentend query when "compiled" (at runtime).
The following statements are supported:

Condition
A condition is a property name, a comparer and a parameter. You can use inline parameter or tags ({0}, {1}, ...) that are replaced by the parameter at runtime. Using tags is strongly recommended (for dynamic parameters) to avoid injections.
Samples: "UserName = {0}", "Duration < {0}", "UserName = 'Test'", "Duration < 10", "UserName Like {0}"

Simple Joins
Simple joins allow you to join an related object and check some properties of that object. If the properties fullfil the conditions the original object is loaded (obsolete!).
Samples: "Call[Duration < 10]" checks if one of the connected calls of the user is shorter then 10 minutes.

Sort Options
Sort Options allow to sort the result of the query. They consist in a keyword "SortBy", the name of the property that is sorted by and the sort direction. Currently only one property is allowed in a sort option.
Samples: "SortBy UserName Asc", "SortBy UserName Desc"

Concats and brackets
You can concat each condition to another and brackets are also allowed in a OPath statement.
Samples: "UseName = {0} And Password = {1}", "(Duration < 10 And Name = {1}) Or Name = 'Test'"

Custom commands
OPath supports also custom commands. The commands must be understood by the storage to work. The storage itself converts them to a command that is then executed on the storage. The storage gets a OECommand object that contains the name of the command and could also contain arguments. See SubString below, which contains 1 and 3 as arguments.
Samples: "Upper(UserName)" is converted by Oracle to "TO_UPPER({0})" the {0} Tag stands for the name of the field. "SubString(UserName, 1, 3)" is converted to a command that is understood by the storage.

Inheritance Hierarchy

System.Object
   Chili.Opf3.Query.ObjectQuery

Requirements

Namespace: Chili.Opf3.Query

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Chili.Opf3 (in Chili.Opf3.dll)

See Also