我将一个对象添加到另一个对象中,如下所示:
Foo foo = new Foo();
AnotherClass.bar.add(foo); // bar is getting assigned with dependency injection in AnotherClass这将导致DevExpress.Xpo.Exceptions.SessionMixingException如下所示:
初始化方法Test.SetUp抛出异常。DevExpress.Xpo.Exceptions.SessionMixingException: DevExpress.Xpo.Exceptions.SessionMixingException:'Foo‘对象属于不同的会话。
如何从AnotherClass获取会话以避免此错误?
发布于 2011-08-04 10:24:22
您可以简单地在AnotherClass的会话中加载foo对象,
foo = AnotherClass.Session.GetObjectByKey<Foo>(foo.Oid);
AnotherClass.bar.add(foo);您可以更多地阅读会话在http://www.devexpress.com/Products/NET/ORM/articles/SessionManagementCaching.xml中的工作方式。
https://stackoverflow.com/questions/6919907
复制相似问题