The requested page is not available for the requested platform. You are viewing the content for Default platform.

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

Declaration

public static IObjectSpace FindObjectSpaceByObject(
    object obj
)
Public Shared Function FindObjectSpaceByObject(
    obj As Object
) As IObjectSpace

Parameters

Name Type Description
obj Object

The object whose Object Space must be determined.

Returns

Type Description
IObjectSpace

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

Remarks

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