ObjectScope vs GetNewObjectScope

10 posts, 0 answers
  1. Pilu
    Pilu avatar
    4 posts
    Member since:
    Oct 2008

    Posted 19 Aug 2009 Link to this post

    Hi

    There seems to be very little (or no) documentation regarding the difference between ObjectScope and GetNewObjectScope. The examples provided in the documentations uses both, and it seems to me they are picked randomly (of course I might be wrong) - which is confusing. Please clarify this.

    regards
    Pilu
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 21 Aug 2009 Link to this post

    Hi Pilu,

    The ObjectScope provider holds a static instance of IObjectScope. Whenever you call ObjectScopeProvider.ObjectScope() you will get the same static instance of the IObjectScope. The GetNewObjectScope() method will return you a new instance of the IObjectScope that needs to be disposed every time.

    Kind regards,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. oVan
    oVan avatar
    35 posts
    Member since:
    Apr 2008

    Posted 10 Nov 2009 Link to this post

    Perhaps a silly question, but it is not clear to me when to use one of these in favor of the other...
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 11 Nov 2009 Link to this post

    Hi oVan,

    It depends entirely on the application architecture. If your application performs small and fast CRUD operations with some persistent objects (e.g. read one object, store another) and you do not need to track the changes to these objects anymore, you can freely use the GetNewObjectScope() method and dispose the scope after each operation.
    However, there are more complex scenarios that require a long-living object scope. This could be necessary for lazy loading or tracking the changes of big object graphs. For example, if you read a Person object, dispose its object scope and try to read the Person's collection of addresses (that are not loaded yet), you will get an exception saying that the object scope is already closed. Additionally, if you read an object, dispose the scope and modify the object, you would not be able to persist the changes as they should have been tracked by the object scope which is already disposed. That is why in such cases the scope should not be disposed and you can use the ObjectScope() method to obtain the same object scope every time when you need it.
    Hope that sheds some light on the topic.

    Regards,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 11 Nov 2009 Link to this post

    Hi oVan,

    These are just examples:

    In a web application you will most probably use the getNewObjectScope, since best practice is to have one scope and keep it alive during each request and then dispose it when the request finishes. Doing this you also have a clean transaction demarcation. Either everything you do in the request is committed or rolled back.
    For Windows forms you might use the ObjectScope during application life time, especially if you are not using multiple threads in your application.

    Regards

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

    Posted 11 Nov 2009 Link to this post

    Hi Alexander,

    Sorry... I was writing while your reply came in :-)
  8. oVan
    oVan avatar
    35 posts
    Member since:
    Apr 2008

    Posted 11 Nov 2009 Link to this post

    Thanks Henrik & Alexander. I develop websites, so the getNewObjectScope is what I need.
  9. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 11 Nov 2009 Link to this post

    Hello oVan,

    You can take a look at our articles about the recommended practices of using object scopes in web applications - part one and part two. I think you will find them useful as well.

    Sincerely yours,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. oVan
    oVan avatar
    35 posts
    Member since:
    Apr 2008

    Posted 11 Nov 2009 Link to this post

    Hi Alexander,

    I've had a look at these before, with much frustration... see my unanswered post here: http://www.telerik.com/community/forums/orm/general-discussions/concurrency-problem.aspx

    I downloaded the BestPractices code sample, but that didn't work yet. It is using a 2008-version of OpenAccess. I updated all references to the 2009.3 version but it still won't compile.

    Maybe I can repeat the same question as in the other thread? Why must I go through such a pile of trouble just to get a simple example with a RadListView to work? When using Linq2Sql and a Linq datasource this all works out of the box. I thought that using the OpenAccess Datasource would give me the same productivity boost.

    Perhaps I miss something important here, but I get the feeling that there are more RadControl users that are pleased with Telerik offering the OpenAccess ORM, yet are disappointed with it once they start using it. There is a lot of documentation, videos, demos, etc. yet I don't find what I'm looking for. I hope you see this criticism as constructive, because that's how I intend it.

    Thanks again for your support.
  11. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 12 Nov 2009 Link to this post

    Hello oVan,

    I think that the problem with the non-compiling examples comes from the fact that we have done some changes in the namespace with the IObjectScope.Extent method which is used as an entry point for LINQ with OpenAccesss. We have replaced the code examples with ones using the latest version of OpenAccess. You can try re-downloading them and they should now compile without problems(you may need to upgrade to the version you have installed on your machine but that is easy using the OpenAccess CheckSettings wizard).

    Can you tell us some more specific problems you are confronting in terms of usability as the OpenAccessDataSource also works out of the box with the RadControls for ASP .NET AJAX. We will definitely consider all the suggestions you might give us and improve our product so it suits our customers the best.

    Sincerely yours,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
DevCraft banner