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

ObjectScopeProvider

7 Answers 133 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tevez
Top achievements
Rank 1
Tevez asked on 15 Aug 2011, 01:42 AM
Hi everyone,

I'm trying to do something as in this example: http://www.telerik.com/help/openaccess-orm/openaccess-tasks-howto-execute-sql-query.html

IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           var query = @"select * from employees as x where x.employeeId = 1";
           var result = scope.GetSqlQuery(query,
typeof(Employee), null).Execute();
           
foreach (Employee ord in result)
           {
               Console.WriteLine(ord.EmployeeID);
           }
           Console.ReadKey();


But, what is an ObjectScopeProvider? I have a 'context' , but no scope or objectscope.
How should i setup my scope? So i can use .GetSqlQuery ?

Practically, i just want to execute a stored procedure / query and retrieve objects of a specific type :)

Hope someone can clear things up :)
Thanks!

7 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 15 Aug 2011, 07:41 AM
Hi Tevez,

The ObjectScopeProvider is used in OpenAccess Classic, which uses the Object Scope as the API. As you have a Context, so you use the Context API (with the visual designer). However, in the Context (in the newest version) there are methods to execute arbitrary SQL commands...  I think they are called ExecuteXXXX.

If this doesn't work you can get a hold on the IObjectScope instance beneath the Context by using the protected method GetScope() on the Context. Once you have the Object Scope you can use the classic methods like the GetSqlQuery(.....) to perform your queries.

Regards

Henrik
0
Tevez
Top achievements
Rank 1
answered on 15 Aug 2011, 07:02 PM
Hi Henrik ,

Thanks for you reply, classic and API are a bit more clear now. But still, in my version  (i'm working with 2011.1.510.1 , because that's the same version our Sitefinity install uses, and mixing versions doesn't work) , i cannot find any GetScope() method.
Am i doing something completely wrong? Or is this scope stuff just not in the version we are using?

Best regards,
Tevez
0
IT-Als
Top achievements
Rank 1
answered on 16 Aug 2011, 07:30 AM
Hi Tevez,

The GetScope() method should be there, but it is protected... So you need to expose it to the public with your context, something like this:

public MyContext : OpenAccessContext;
{
   public IObjectScope ObjectScope
   {
      get { return this.GetScope(); }
   }
}


and then use the exposed ObjectScope public property.

Regards

Henrik
0
Serge
Telerik team
answered on 16 Aug 2011, 11:16 AM
Hello Tevez, hello Hernik

 What Hernik suggested with exposing the protected GetScope method will work for you, however I would like to point out that as soon as you get the updated OpenAccess versions it will be good if you could start using the new Execute*** API. 

Retrieving a collection of Categories for example with a simple selected statement is as easy as : 

IEnumerable<Category> categories = dbContext.ExecuteQuery<Category>("select * from categories");

I hope this is helpful, and do let us know should you face further trouble. 
 
Best wishes,
Serge
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
IT-Als
Top achievements
Rank 1
answered on 16 Aug 2011, 11:22 AM
Hi Serge,

Yeah, that's what I also thought of, but Tevez is "stuck" on the version of SiteFinity... so until Sitefinity is updated, this is the only way to do it.

Regards

Henrik
0
Serge
Telerik team
answered on 18 Aug 2011, 04:04 PM
Hello Henrik,

 This is of course correct. I was merely pointing out that as soon as Sitefinity does update their OpenAccess version it will be very wise to update to the new API, in terms of performance and stability. 

All the best,
Serge
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Khoa
Top achievements
Rank 1
answered on 01 Feb 2016, 06:25 AM
Thank you TSE. Very valuable information how to find a ObjectScopeProvider in OpenAccess Classic (a protected property in Open Access Context).
Tags
General Discussions
Asked by
Tevez
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Tevez
Top achievements
Rank 1
Serge
Telerik team
Khoa
Top achievements
Rank 1
Share this question
or