A newer version of this page is available. Switch to the current version.

XPObjectSpace.FindObjectSpaceByObject(Object) Method

Determines the Object Space used to load and save a specified persistent object.

Namespace: DevExpress.ExpressApp.Xpo

Assembly: DevExpress.ExpressApp.Xpo.v18.2.dll


public static IObjectSpace FindObjectSpaceByObject(
    object obj


Name Type Description
obj Object

The object whose Object Space must be determined.


Type Description

An IObjectSpace object which represents the Object Space used to load and save the specified persistent object.


This method returns null (Nothing in VB.NET) if the object specified by the obj parameter belongs to an XPO Session not managed by the ObjectSpace class. This can be the case, for example, if you create an object using a separate Session as follows.

Session theSession = new Session(theDataLayer); 
MyObject theObject = new MyObject(theSession);

Note that you can access certain Object Spaces used internally by XAF via the FindObjectSpaceByObject method. Such Object Spaces should not be used in your applications. One example of such an Object Space is the Object Space used by the Security System. This Object Space can be accessed, for example, via the following code:

IObjectSpace objectSpace = XPObjectSpace.FindObjectSpaceByObject(SecuritySystem.CurrentUser);
//some code which performs actions using the objectSpace Object Space

Using such code in your applications may lead to undesired side-effects. So, instead of using an internal Object Space, create a new Object Space and perform the required actions with it:

using(ObjectSpace objectSpace = application.CreateObjectSpace(typeof(MyClass))) {
//some code which performs actions using the objectSpace Object Space 

The FindObjectSpaceByObject method is not designed to be used with Domain Components when the Object Space is provided by the SecuredObjectSpaceProvider.

See Also