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

ObjectScope vs GetNewObjectScope

9 Answers 186 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pilu
Top achievements
Rank 1
Pilu asked on 19 Aug 2009, 03:59 PM
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

9 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 21 Aug 2009, 11:57 AM
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.
0
oVan
Top achievements
Rank 2
answered on 10 Nov 2009, 09:56 AM
Perhaps a silly question, but it is not clear to me when to use one of these in favor of the other...
0
Alexander
Telerik team
answered on 11 Nov 2009, 09:33 AM
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.
0
IT-Als
Top achievements
Rank 1
answered on 11 Nov 2009, 09:45 AM
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
0
IT-Als
Top achievements
Rank 1
answered on 11 Nov 2009, 09:46 AM
Hi Alexander,

Sorry... I was writing while your reply came in :-)
0
oVan
Top achievements
Rank 2
answered on 11 Nov 2009, 09:52 AM
Thanks Henrik & Alexander. I develop websites, so the getNewObjectScope is what I need.
0
Alexander
Telerik team
answered on 11 Nov 2009, 10:17 AM
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.
0
oVan
Top achievements
Rank 2
answered on 11 Nov 2009, 10:27 AM
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.
0
Zoran
Telerik team
answered on 12 Nov 2009, 09:09 AM
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.
Tags
Getting Started
Asked by
Pilu
Top achievements
Rank 1
Answers by
PetarP
Telerik team
oVan
Top achievements
Rank 2
Alexander
Telerik team
IT-Als
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or