Using OQL with Visual Designer?

5 posts, 0 answers
  1. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 14 Oct 2010 Link to this post

    I have, maybe a dumb question.  If I create my model from the visual designer, is it still possible to use OQL?

    The examples I see use the ObjectScopeContainer.

    IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
               string query = "SELECT * FROM OrderExtent AS o WHERE o.employee.employeeID=5";
               var result = scope.GetOqlQuery(query).Execute();
               foreach (Order ord in result)
               {
                   Console.WriteLine(ord.OrderID);
               }

    I would like to do something like this if possible:

    using (var context = new MyEntitiesContext())
    {
        string query = "SELECT * FROM OrderExtent AS o WHERE o.employee.employeeID=5";
        ??? Now what??  :^)
    }

    Is this possible?  If so, what is the syntax for this?

    Thanks,

    King Wilder
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 18 Oct 2010 Link to this post

    Hi King Wilder,

      What you have read is correct, we only support as part of the old OpenAccess API built around IObjectScope. However if you are willing to go one extra step you can use it with the new domain model, this is not something that is recommended but it is possible. In order to do so, you have to create a partial class to the domain model and in it expose the inner scope of the context. Your code should look a like this : 

    public partial class YourContextNameHere
    {
        public IObjectScope Scope
        {
            get
            {
                return this.GetScope();
            }
        }
    }



    This way you can use the scope as you would  normally do with older OpenAccess versions. Again this is not recommended and the scope is only exposed for backward compatibility reasons. 


    Sincerely yours,
    Serge
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 18 Oct 2010 Link to this post

    Got it!  I created some examples in my application and it works perfectly. 

    Thanks.
  5. Christian
    Christian avatar
    81 posts
    Member since:
    Aug 2008

    Posted 03 Feb 2011 Link to this post

    Hi,
    OQL is (was?) a very good way to create queries at runtime. Is there an example with the domain model without a scope?
    Thanks
    Christian
  6. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 08 Feb 2011 Link to this post

    Hello Christian,

    When working with an OpenAccess context usually LINQ is used in order to do queries.
    If you want / need to compose queries dynamically you can either use
    • dynamic LINQ as shown in this blog post:
    http://blogs.telerik.com/blogs/posts/09-12-28/dynamic_query_with_telerik_openaccess.aspx
    • or construct parts of the query using the .net expression api like in this forum post:
    http://www.telerik.com/community/forums/orm/linq-questions/dynamic-criteria-problem.aspx

    All the best,
    Jordan
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Back to Top
DevCraft banner