Error setting property to related item

4 posts, 0 answers
  1. David
    David  avatar
    66 posts
    Member since:
    Aug 2010

    Posted 11 Sep 2012 Link to this post

    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
  2. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 12 Sep 2012 Link to this post

    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
  3. DevCraft banner
  4. David
    David  avatar
    66 posts
    Member since:
    Aug 2010

    Posted 12 Sep 2012 Link to this post

    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
  5. Ady
    Admin
    Ady avatar
    588 posts

    Posted 13 Sep 2012 Link to this post

    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!
Back to Top