0

I'm adding an object to another object like so:

Foo foo = new Foo();
AnotherClass.bar.add(foo);  // bar is getting assigned with dependency injection in AnotherClass

This causes a DevExpress.Xpo.Exceptions.SessionMixingException as follows:

Initialization method Test.SetUp threw exception. DevExpress.Xpo.Exceptions.SessionMixingException: DevExpress.Xpo.Exceptions.SessionMixingException: The 'Foo' object belongs to a different session.

How does one grab get a hold of the session from AnotherClass to avoid this error?

ThoughtCrhyme
  • 517
  • 3
  • 8
  • 18

1 Answers1

1

You can simply load the foo object within AnotherClass' Session with,

foo = AnotherClass.Session.GetObjectByKey<Foo>(foo.Oid);
AnotherClass.bar.add(foo);

You can read more how the session works at http://www.devexpress.com/Products/NET/ORM/articles/SessionManagementCaching.xml

Apostolis Bekiaris
  • 2,145
  • 2
  • 18
  • 21