Back to Devexpress

BaseObjectSpace.FindObjectSpaceByObject(Object) Method

expressappframework-devexpress-dot-expressapp-dot-baseobjectspace-dot-findobjectspacebyobject-x28-system-dot-object-x29.md

latest4.5 KB
Original Source

BaseObjectSpace.FindObjectSpaceByObject(Object) Method

Returns the Object Space used to load and save a specified persistent object. This method is for internal use.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

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

Parameters

NameTypeDescription
objObject

The object whose Object Space this method returns.

|

Returns

TypeDescription
IObjectSpace

An Object Space used to load and save the specified persistent object. null if the specified object does not belong to any Object Space.

|

Remarks

This method is for internal use. It can access certain Object Spaces XAF uses internally (for example, the Object Space used by the Security System). Do not use such Object Spaces in your applications because this may cause unexpected behavior. Instead of this, implement the approaches below.

To access an object’s Object Space in the class code, use one of the following options:

  • Implement the IObjectSpaceLink interface in non-persistent classes.
  • Use the automatically implemented IObjectSpaceLink interface in EF Core classes.
  • Use the object’s Session in XPO persistent classes.

In other cases, create a new Object Space and use the GetObject(Object) method to retrieve an object in the current Object Space.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindObjectSpaceByObject(Object) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

XAF-CRUD-for-Non-Persistent-Objects-Stored-Remotely/CS/NonPersistentObjectsDemo.Module/TransientNonPersistentObjectAdapter.cs#L94

csharp
private static bool IsNewObject(object obj) {
    var sourceObjectSpace = BaseObjectSpace.FindObjectSpaceByObject(obj);
    return sourceObjectSpace == null ? false : sourceObjectSpace.IsNewObject(obj);

XAF-CRUD-for-Non-Persistent-Objects-Stored-Remotely/VB/NonPersistentObjectsDemo.Module/TransientNonPersistentObjectAdapter.vb#L91

vb
Private Shared Function IsNewObject(ByVal obj As Object) As Boolean
    Dim sourceObjectSpace = BaseObjectSpace.FindObjectSpaceByObject(obj)
    Return If(sourceObjectSpace Is Nothing, False, sourceObjectSpace.IsNewObject(obj))

See Also

BaseObjectSpace Class

BaseObjectSpace Members

DevExpress.ExpressApp Namespace