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

object scope confliction

5 Answers 238 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
amir sherafatian
Top achievements
Rank 1
amir sherafatian asked on 17 Sep 2009, 09:04 AM

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

5 Answers, 1 is accepted

Sort by
0
Accepted
Zoran
Telerik team
answered on 18 Sep 2009, 03:48 PM
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.
0
amir sherafatian
Top achievements
Rank 1
answered on 19 Sep 2009, 06:51 AM
tanks zoran
0
KFS
Top achievements
Rank 1
answered on 22 Jul 2014, 08:53 AM
Dear, Zoran
your blog-post link is unavailable,

please i need to see your answer asap.

Thanks,
0
KFS
Top achievements
Rank 1
answered on 22 Jul 2014, 09:04 AM
Dear, Zoran
your blog-post link is unavailable,

please i need to see your answer asap.

Thanks,
0
Doroteya
Telerik team
answered on 22 Jul 2014, 11:50 AM
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.
 
Tags
Databases and Data Types
Asked by
amir sherafatian
Top achievements
Rank 1
Answers by
Zoran
Telerik team
amir sherafatian
Top achievements
Rank 1
KFS
Top achievements
Rank 1
Doroteya
Telerik team
Share this question
or