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

Dealing with object scope

2 Answers 94 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dilshod
Top achievements
Rank 1
Dilshod asked on 09 Jan 2015, 09:58 AM
Hi,
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 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 12 Jan 2015, 08:52 AM
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.

Regards,
Thomas
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Dilshod
Top achievements
Rank 1
answered on 19 Jan 2015, 10:19 AM
Thanks for your reply,
I actually found the problem. We had a bug on our code. It was creating two different telerik contexts.

Thanks.
Tags
Development (API, general questions)
Asked by
Dilshod
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Dilshod
Top achievements
Rank 1
Share this question
or