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

Error setting property to related item

3 Answers 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 2
David asked on 11 Sep 2012, 10:08 PM
Hi

I have setup a basic OA project just two tables 

Activities and Specialties

Activity as a link to Specialty on SpecialtyID

I load my data into ObservableCollection<T>

If i set Activity.SpecialtyID = 1 this works and I can then access the Activity.Specialty Property but if i try to set Activity.Specialty = Specialties[0]; then i get 

Telerik.OpenAccess.Exceptions.InvalidOperationException was unhandled
  HResult=-2146233088
  Message=Object references between two different object scopes are not allowed. The object 'Models.Specialty' is already managed by 'ObjectScopeImpl 0x1 OpenAccessRuntime.EnlistableObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0x2 OpenAccessRuntime.EnlistableObjectScope'.
  Source=Telerik.OpenAccess
  CanRetry=true
  StackTrace:
       at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
       at OpenAccessRuntime.ExceptionWrapper.Throw()
       at OpenAccessRuntime.DataObjects.PCStateMan.handleException(Exception x)
       at OpenAccessRuntime.DataObjects.PCStateMan.setObjectFieldImp(PersistenceCapable _pc, FieldMetaData fmd, Object currentValue, Object newValue, Boolean rec)
       at OpenAccessRuntime.DataObjects.PCStateMan.SetObjectField(PersistenceCapable _pc, Int32 field, Object currentValue, Object newValue)
       at Models.Activity.OpenAccessEnhancedSet_specialty(Activity owner, Specialty value)
       at Models.Activity.set_Specialty(Specialty value) in c:\Users\David\Documents\Visual Studio 2012\Projects\ACEGP\Models\Activity.generated.cs:line 96
       at TestConsole.Program.Main(String[] args) in c:\Users\David\Documents\Visual Studio 2012\Projects\ACEGP\TestConsole\Program.cs:line 34
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

I thought this was possible am i doing something wrong?

thanks David

3 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 12 Sep 2012, 08:26 AM
Hi David,

How do you actually load the Activities and Specialities?

If you use two different Contexts (with different I mean different instances, thus you new it two times), you will not e able to create an association between the two classes.

So to create an association between instances of a persistent class it must be loaded by the same Context instance. That's why it works for the Activity.SpecilityID property, too. In that case you just manipulate the Id of the referenced object directly as one would do in relational databases.

Hope this answers your question.

/Henrik
0
David
Top achievements
Rank 2
answered on 12 Sep 2012, 09:21 AM
Hi,

Thanks, yeah each one was loaded in a new context. I will now look at using one context and hopefully should solve my problem 

Thanks again

David
0
Ady
Telerik team
answered on 13 Sep 2012, 02:47 PM
Hello David,

 As Henkrik rightly mentioned, objects associated with different context instances cannot reference each other. Please ensure that objects that you want to wire up are associated to the same context and that should fix the problem.

Do get back in case you need further assistance.

Greetings,
Ady
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
General Discussions
Asked by
David
Top achievements
Rank 2
Answers by
IT-Als
Top achievements
Rank 1
David
Top achievements
Rank 2
Ady
Telerik team
Share this question
or