ObjectScopeProvider

8 posts, 0 answers
  1. Tevez
    Tevez avatar
    10 posts
    Member since:
    Aug 2011

    Posted 14 Aug 2011 Link to this post

    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!
  2. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 15 Aug 2011 Link to this post

    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
  3. DevCraft banner
  4. Tevez
    Tevez avatar
    10 posts
    Member since:
    Aug 2011

    Posted 15 Aug 2011 Link to this post

    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
  5. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 16 Aug 2011 Link to this post

    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
  6. Serge
    Admin
    Serge avatar
    375 posts

    Posted 16 Aug 2011 Link to this post

    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 >>

  7. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 16 Aug 2011 Link to this post

    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
  8. Serge
    Admin
    Serge avatar
    375 posts

    Posted 18 Aug 2011 Link to this post

    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 >>

  9. Khoa
    Khoa avatar
    1 posts
    Member since:
    Jan 2016

    Posted 01 Feb in reply to TSE Link to this post

    Thank you TSE. Very valuable information how to find a ObjectScopeProvider in OpenAccess Classic (a protected property in Open Access Context).
Back to Top
DevCraft banner