Back to Devexpress

IObjectSpace.IsNewObject(Object) Method

expressappframework-devexpress-dot-expressapp-dot-iobjectspace-dot-isnewobject-x28-system-dot-object-x29.md

latest5.1 KB
Original Source

IObjectSpace.IsNewObject(Object) Method

Indicates whether a specified object has been created but has not been saved to the database.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
bool IsNewObject(
    object obj
)
vb
Function IsNewObject(
    obj As Object
) As Boolean

Parameters

NameTypeDescription
objObject

A object to be tested.

|

Returns

TypeDescription
Boolean

true if the specified object has not yet been saved to the database; otherwise, false.

|

Remarks

The objects that are created both directly via the IObjectSpace.CreateObject method and by means of built-in Actions (for example, the New Action) are not saved to the database immediately. They are saved only when the IObjectSpace.CommitChanges method is called, directly or by means of built-in Actions (for example, the Save Action).

Until an object created within the current Object Space is not saved to the database, the IsNewObject method returns true. After saving, the IsNewObject method returns false. It is presumed that this property must return false if the object passed as the parameter is not persistent, or if it does not belong to the current Object Space.

The following code snippets (auto-collected from DevExpress Examples) contain references to the IsNewObject(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_Non-Persistent-Objects-Reloading-Demo/CS/EFCore/NonPersReloadEF/NonPersReloadEF.Module/BusinessObjects/LiveSummary.cs#L124

csharp
var link = obj as IObjectSpaceLink;
if(link == null || link.ObjectSpace == null || link.ObjectSpace.IsNewObject(obj)) {
    return null;

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

csharp
var sourceObjectSpace = BaseObjectSpace.FindObjectSpaceByObject(obj);
    return sourceObjectSpace == null ? false : sourceObjectSpace.IsNewObject(obj);
}

XAF_Non-Persistent-Objects-Nested-In-Persistent-Objects-Demo/CS/XPO/NonPersistentDemo/NonPersistentDemo.Module/BusinessObjects/NonPersistentObjectAdapter.cs#L94

csharp
else {
    if(link.ObjectSpace.IsNewObject(obj)) {
        if(link.ObjectSpace.Equals(_objectSpace)) {

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

vb
Dim sourceObjectSpace = BaseObjectSpace.FindObjectSpaceByObject(obj)
    Return If(sourceObjectSpace Is Nothing, False, sourceObjectSpace.IsNewObject(obj))
End Function

See Also

EFCoreObjectSpace.IsNewObject(Object)

XPObjectSpace.IsNewObject(Object)

IObjectSpace Interface

IObjectSpace Members

DevExpress.ExpressApp Namespace