IObjectSpace.ModifiedObjects Property
Returns a collection of objects that have been created, modified or deleted after they were retrieved or committed.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Property Value
Type | Description |
---|---|
IList | An IList collection that contains the modified objects belonging to the current Object Space. |
Remarks
When you create, modify or delete an object, you should then call the IObjectSpace.CommitChanges method. This method saves all the changes made to the current Object Space’s persistent objects to the database. The ModifiedObjects method is intended to get the list of objects to be committed. After calling the IObjectSpace.CommitChanges method, this list is empty until creating, modifying or deleting an object.
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) {
//...
}
}
}
}