开发者

Resolving a DevExpress.Xpo.Exceptions.SessionMixingException

开发者 https://www.devze.com 2023-03-25 00:40 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号