开发者

Resolving a DevExpress.Xpo.Exceptions.SessionMixingException

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜