OpenAccess Web Developement with HttPModule

2 posts, 1 answers
  1. Robbi
    Robbi avatar
    4 posts
    Member since:
    Apr 2009

    Posted 09 Sep 2010 Link to this post

    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
  2. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 10 Sep 2010 Link to this post

    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
  3. DevCraft banner
Back to Top