.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET 5.0+

IObjectSpace.Committing Event

Occurs before persistent objects are saved to the database.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v21.2.dll

Declaration

event EventHandler<CancelEventArgs> Committing

Event Data

The Committing event's data class is CancelEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled.

Remarks

The IObjectSpace.CommitChanges method call raises the Committing event before the changes are stored in the database. In the Committing event handler, set the CancelEventArgs.Cancel parameter to true to prevent the commit. This parameter’s default value is false.

In the BaseObjectSpace descendant, the BaseObjectSpace.CommitChanges method invokes the BaseObjectSpace.DoCommit method and raises the Committing event. Override the BaseObjectSpace.DoCommit method to implement your logic to persist changes.

The following example prevents commits in the Payment Detail View:

using System.ComponentModel;
using DevExpress.ExpressApp;

// ...
public class CancelCommitController : ObjectViewController<DetailView, MainDemo.Module.BusinessObjects.Payment> {
    protected override void OnActivated() {
        base.OnActivated();
        View.ObjectSpace.Committing += ObjectSpace_Committing;
    }
    private void ObjectSpace_Committing(object sender, CancelEventArgs e) {
        e.Cancel = true;
    }
    protected override void OnDeactivated() {
        View.ObjectSpace.Committing -= ObjectSpace_Committing;
    }
}

The following code shows how to manually save child collection changes made in the parent Detail View:

using DevExpress.ExpressApp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using YourSolutionName.Module.BusinessObjects;

namespace YourSolutionName.Module.Controllers {
    public class MyViewController : ObjectViewController<DetailView, Parent> {
        List<Child> detailObjectsCache = new List<Child>();
        protected override void OnActivated() {
            base.OnActivated();
            ObjectSpace.CustomCommitChanges += ObjectSpace_CustomCommitChanges;
            ObjectSpace.Committing += ObjectSpace_Committing;
            ObjectSpace.Committed += ObjectSpace_Committed;
            ObjectSpace.Reloaded += ObjectSpace_Reloaded;
        }
        protected override void OnDeactivated() {
            ObjectSpace.CustomCommitChanges -= ObjectSpace_CustomCommitChanges;
            ObjectSpace.Committing -= ObjectSpace_Committing;
            ObjectSpace.Committed -= ObjectSpace_Committed;
            ObjectSpace.Reloaded -= ObjectSpace_Reloaded;
            base.OnDeactivated();
        }
        void ObjectSpace_Reloaded(object sender, EventArgs e) {
            detailObjectsCache.Clear();
        }
        void ObjectSpace_Committed(object sender, EventArgs e) {
            detailObjectsCache.Clear();
        }
        void ObjectSpace_Committing(object sender, CancelEventArgs e) {
            IObjectSpace os = (IObjectSpace)sender;
            for (int i = os.ModifiedObjects.Count - 1; i >= 0; i--) {
                object item = os.ModifiedObjects[i];
                if (typeof(Child).IsAssignableFrom(item.GetType())) {
                    detailObjectsCache.Add(item as Child);
                    os.RemoveFromModifiedObjects(item);
                }
            }
        }
        void ObjectSpace_CustomCommitChanges(object sender, HandledEventArgs e) {
            // Implement custom logic to save Detail objects here. 
            foreach (Child detailObject in detailObjectsCache) {
                //...  
            }
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Committing event.

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.

See Also