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开发者_如何学Python 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?
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
精彩评论