object scope confliction

6 posts, 1 answers
  1. amir sherafatian
    amir sherafatian avatar
    42 posts
    Member since:
    Aug 2009

    Posted 17 Sep 2009 Link to this post

    i have more than one class library + MyWebApplication(UI) that all of these have own object scope provide when i enable OA for each of them.
    in one of the class library that is "EandE.Organization.BSL" i have 3 Entity class and their manager class that i used in UI to assign selected ORGPersonJob(s) by User to a specific ORGRole,
    class No1 : OrgPersonJob (many-to-many Join Table between 2 class ( OrgPerson and OrgJob ) )
    Class No2 : OrgRole
    Class No3 : OrgUser (many-to-many Join Table between 2 class ( ORGPersonJob and OrgRole ) )

    their Manager :
    Manager Class No1 : OrgPersonJobManager
    Manager Class No2 : OrgRoleManager
    Manager Class No3 : OrgUserManager

    after the user select ORGPersonJob(s), in a loop i assign those ORGPersonJob(s) To a Specific ORGRole one by one

    that Code that i used for,in my UI like this :

        protected void ButtonAssign_Click(object sender, EventArgs e)
        {
            ORGPersonJob PersonJob;
            List<ORGUser> UsersList = new List<ORGUser>();
            ORGUser User;
            ORGRole Role = new ORGRole();

            UserControl userControl = (UserControl)FindControl("ucInternalPersonnel1");
            RadGrid RadGridInternalPersonnel = (RadGrid)userControl.FindControl("RadGridInternalPersonnel");

            int selectedItemsCount = RadGridInternalPersonnel.SelectedItems.Count;
            for (int i = 0; i < selectedItemsCount; i++)
            {
                User = new ORGUser();

                int personJobId = Convert.ToInt32(RadGridInternalPersonnel.SelectedItems[i].OwnerTableView.DataKeyValues[i]["Id"]);
                PersonJob = orgPersonJonManager.RetrieveOrgPersonJobById(personJobId);

                int roleId = Convert.ToInt32(RadComboBoxDocumentRoles.SelectedValue);
                Role = orgRoleManager.RetrieveORGRoleById(roleId);

                User.ORGPersonJob = PersonJob;
                User.ORGRole = Role;

                UsersList.Add(User);

            }

            if (selectedItemsCount != 0)
            {
    ****        orgRoleManager.RegisterNewRoleUsers(Role, UsersList);
            }

        }

    i have no problem until Marked Line that i call a manager Role Class that is in My Business Class Library "EandE.Organization.BSL" :
    the code of function "orgRoleManager.RegisterNewRoleUsers" is like This :

                public void RegisterNewRoleUsers(ORGRole role, List<ORGUser> usersList)
                {
                    scope.Transaction.Begin();

                    for (int i = 0; i < usersList.Count; i++)
                    {
    ****                role.ORGUsers.Add(usersList[i]);
                    }

                    scope.Transaction.Commit();
                }

    but when i achieve to marked line i have an exception that i shown below :

    " Object references between two different object scopes are not allowed. The object 'EandE.Organization.BSL.Entities.ORGPersonJob' is already managed by 'ObjectScopeImpl 0xa4b12 Telerik.OpenAccess.RT.ObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0x1cf3235 Telerik.OpenAccess.RT.ObjectScope'. "

    also for test i add a property ro classes that i used with name "GetObjectScope" which returned the related Class`s objectscope like this

            public IObjectContext Scope
            {
                get
                {
                    return Database.GetContext(this);
                }
            }

    and in my business function i use this :

    public void RegisterNewRoleUsers(ORGRole role, List<ORGUser> usersList)
                {
                    //scope = (IObjectScope)role.Scope;

                    scope.Transaction.Begin();

                    for (int i = 0; i < usersList.Count; i++)
                    {
    ****                role.ORGUsers.Add(usersList[i]);
                    }

                    scope.Transaction.Commit();
                }

    but i have mentioned exception again in marked line

    what is your solution?
    tanks

  2. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 18 Sep 2009 Link to this post

    Hello amir sherafatian,

    The exception you are reporting indicates that you are trying to modify a single persistent object with more than one object scope. OpenAccess does not allow this kind of cross-scope operations e.g. a persistent object can be managed only by the object scope that was used for loading it.

    This pattern is best described in a blog-post I have written on the Telerik OpenAccess ORM team blog. I strongly suggest you use the HttpContext.Items approach as it allows you a generic access to your IObjectScope instance in all layers of your application.

    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.
  3. DevCraft banner
  4. amir sherafatian
    amir sherafatian avatar
    42 posts
    Member since:
    Aug 2009

    Posted 19 Sep 2009 Link to this post

    tanks zoran
  5. KFS
    KFS avatar
    4 posts
    Member since:
    Feb 2014

    Posted 22 Jul 2014 in reply to amir sherafatian Link to this post

    Dear, Zoran
    your blog-post link is unavailable,

    please i need to see your answer asap.

    Thanks,
  6. KFS
    KFS avatar
    4 posts
    Member since:
    Feb 2014

    Posted 22 Jul 2014 in reply to Zoran Link to this post

    Dear, Zoran
    your blog-post link is unavailable,

    please i need to see your answer asap.

    Thanks,
  7. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 22 Jul 2014 Link to this post

    Hello KFS,

    Thank you reporting this issue to us. Let me assure you that the link will be redirected to the correct content.

    Regarding the subject it handles, this section in our documentation describes the different approaches for handling the context in web scenarios. Note that the context is the concept currently used by Telerik Data Access for management of the persistent classes and the operations executed against the database. It was introduced with the modern API of the product and basically is an abstraction above the object scope.


    I hope this helps. If you need additional information do not hesitate to get back to us.


    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner