Dealing with object scope

3 posts, 0 answers
  1. Dilshod
    Dilshod avatar
    23 posts
    Member since:
    Feb 2012

    Posted 09 Jan 2015 Link to this post

    I have been having hard time making telerik data access work. So I decided to post my issue here:
    My example:
    I am using fluent mapping and I have few classes. I have Entity A, B and parent of B is A. B has a constructor that takes A in it. Also B references A. In the construcor of B I assign a value to a reference property. Something like this:

    public B(A anchor)
        this.A = anchor;

    After creating a new instance of B if I try Telerik.OpenAccess.OpenAccessContextBase.GetContext(b) it returns null. So then I am doing this. telericContext.Add(b) it is throwing exception: Object references between two different object scopes are not allowed. The object '' is already managed by 'ObjectScopeImpl 0x2 OpenAccessRuntime.EnlistableObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0x1 OpenAccessRuntime.EnlistableObjectScope'.

    If I don't add b to telerikContext after creating a new instance of B it tells it is not tracked. I am very confused. When I try getting the context of b after it is created it says it is null, but when I try to add it to telerikContext it says it already in the scope. What should I do? 

    Help appreciated!
  2. Thomas
    Thomas avatar
    588 posts

    Posted 12 Jan 2015 Link to this post

    Hi Dilshod,

    looks like you A instance is actually managed already by DataAccess. Which means, that by letting the B instance beeing managed from another ObjectContext instance you are creating a cross management reference, which is not supported. Please check that the this. telericContext value is not changed between the load of the A instance and the .Add(b); I suspect that you are using a new instance there. In other words: Is the managing context of instance A at the time that you attempting .Add(b) the same as the this.telericContext? 

    The ObjectScope is an (internal) implementation detail of the OpenAccessContext instance that you are using.

    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  3. DevCraft banner
  4. Dilshod
    Dilshod avatar
    23 posts
    Member since:
    Feb 2012

    Posted 19 Jan 2015 in reply to Thomas Link to this post

    Thanks for your reply,
    I actually found the problem. We had a bug on our code. It was creating two different telerik contexts.

Back to Top