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




Allows to specify directly storage dependent Sql queries.

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class SqlQuery 
   Implements IQuery 
Visual Basic (Usage)Copy Code
Dim instance As SqlQuery
C# 
public sealed class SqlQuery : IQuery  
Managed Extensions for C++ 
public __gc __sealed class SqlQuery : public IQuery  
C++/CLI 
public ref class SqlQuery sealed : public IQuery  

Example

The following example shows how to use a SqlQuery in a customized searcher class (a class that derives from ObjectSearcher).
C#Copy Code
// A customized User searcher. 
public class UserSearcher : ObjectSearcher<User> 

    public UserSearcher(ObjectContext context) : base(context) 
    { 
    } 
  
    // Returns an ObjectSet with all user that have calls. 
    public ObjectSet<User> FindWithCalls(string userName) 
    { 
        // Extended query. 
        SqlQuery query = new SqlQuery( 
            "select distinct u.* from [USER] u, CALLS c where u.ID = c.USER_ID " + 
            "and u.NAME = {0};", userName); 
  
        return Context.GetObjectSet<User>(query); 
    } 
  
    // Returns an ObjectReader with all users that have calls. 
    public ObjectReader<User> FindWithCallsReader() 
    { 
        // Extended query. 
        SqlQuery query = new SqlQuery( 
            "select distinct u.* from [USER] u, CALLS c where u.ID = c.USER_ID " + 
            "and u.NAME = {0};", userName); 
  
        return Context.GetObjectReader<User>(query); 
    } 

    

Remarks

SqlQuery allows to specify directly storage dependent queries that are then executed on the storage without any kind of parsing. This type of query is used to create complex joins or complex queries.

You should avoid to use SqlQuery in your code. Sometimes it could be better to create a stored procedure or an updatable view (in the storage). It's (in most cases) also faster to create those complex queries directly in the storage.

If you have to use this type of query in your application use it for example in specialized classes that do only execute queries (and NOT directly in your UI). You could for example derive from ObjectSearcher and create a customized searcher class that uses such queries.

When setting parameter have to use the {0}, {1}, ... syntax as shown in the example below.

Inheritance Hierarchy

System.Object
   Chili.Opf3.Query.SqlQuery

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