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

OpenAccess Web Developement with HttPModule

1 Answer 96 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.
Robbi
Top achievements
Rank 1
Robbi asked on 09 Sep 2010, 10:44 AM
Hello Telerik,

I built up a web application with OpenAccess as DAL and Forward-Mapping and handling scope by dealing with objects using
custom HttP-Module like it is described in Todd Anglin's blog. It workes fine. But in one szenario I got the following problem:

I have a RadWindow with a RadGrid and a StoreButton in it. In this Grid i want to insert/update rows with PopUp-EditMode. In the PopUp is a RadComboBox which I fill with values from Database. I am dealing with the scope-object stored in HttpContext.Current.Session by HttPModule in the method: PreRequestHandlerExecute. The insert/update works fine. But if I click on the Store-Button I got the exception:

InvalidOperationException: "Object references between two different object scopes are not allowed. The object 'XYObject' is already managed by 'ObjectScopeImpl 0x3139fcd CLOSED' and was tried to be managed again by 'ObjectScopeImpl 0x22497f2 Telerik.OpenAccess.RT.ObjectScope'."

XY-Object is a persistent object whose attributes i use in the RadComboBox.

Ok I think i understand the problem. After every Request the scope is closed and before every request a new scope is initialized. So the XY-object is loaded to RadComboBox with scope 0x3130fcd. after the PopUp is closed, the scope is closed by HttpModule. By clicking on the StoreButton (PostBack) a new scope is created. Now the new scope tries to store the values to database which are loaded with the old scope (Closed).

I understand the problem, but I don't know what is the best way to resolve it.

If you need more information, please let me know. Thx for help.

Robert

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 10 Sep 2010, 03:44 PM
Hi Robbi,

At the moment the only way to avoid this behavior is to load the original object by its id from the scope that you have available, copy the values from the already updated object and commit the transaction. The code would look like this:
XYObject updatedObject;
 
XYObject originalObject = scope.Extent<XYObject>().Where(x => x.Id == updatedObject.Id).First();
 
scope.Transaction.Begin();
originalObject.Property1 = updatedObject.Property1;
originalObject.Property2 = updatedObject.Property2;
originalObject.Property3 = updatedObject.Property3;
 
scope.Transaction.Commit();
Hope that helps.

Regards,
Alexander
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
Tags
Getting Started
Asked by
Robbi
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or