This is a migrated thread and some comments may be shown as answers.

Using OQL with Visual Designer?

4 Answers 85 Views
OQL (OQL specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
King Wilder
Top achievements
Rank 2
King Wilder asked on 15 Oct 2010, 01:38 AM
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

4 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 18 Oct 2010, 06:43 PM
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
0
King Wilder
Top achievements
Rank 2
answered on 18 Oct 2010, 08:12 PM
Got it!  I created some examples in my application and it works perfectly. 

Thanks.
0
Christian
Top achievements
Rank 1
answered on 03 Feb 2011, 08:16 PM
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
0
Jordan
Telerik team
answered on 08 Feb 2011, 12:57 PM
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.
Tags
OQL (OQL specific questions)
Asked by
King Wilder
Top achievements
Rank 2
Answers by
Serge
Telerik team
King Wilder
Top achievements
Rank 2
Christian
Top achievements
Rank 1
Jordan
Telerik team
Share this question
or