What Changed
In v24.2, we support soft deletion for EF Core (aka XPO's Deferred Deletion) in XAF UI and Web API Service-based apps.
Reasons for Change
With soft or deferred object deletion, ORM marks objects as deleted and does not physically remove them from a database immediately. This technique helps you avoid database exceptions when deleting objects that other entities reference (better usability).
Impact on Existing Apps
Existing EF Core apps need NO changes if you do not want to use this new feature. New EF Core apps created in v24.2+ will have this feature enabled by default and they also need no changes.
If you want to voluntarily use this feature in existing apps (created before v24.2), take into account the following:
- Soft or deferred object deletion in EF Core requires a new database column (much like GCRecord in XPO). To use this feature, you need to update your existing database schema.
- Standard XAF CRUD controllers behave differently, if an object supports soft or deferred object deletion.
How to Update Existing Apps
To voluntarily enable soft or deferred object deletion in an existing app (created before v24.2), do the following:
- Inherit your EF Core entity classes from DevExpress.Persistent.BaseImpl.EF.BaseObject (BaseObject has a GCRecord property):
Codepublic class Supplier : BaseObject {
}
OR
If you cannot inherit from our BaseObject, implement the IDeferredDeletion interface in your EF Core entities (and declare a new persistent GCRecord property of the System.Int32 type):
Codepublic class Supplier : YourCustomBaseObjectIfAny, IDeferredDeletion {
public virtual int GCRecord { get; set; }
}
- In your DbContext descendant (typically in the YourSolutionName.Module/BusinessObjects folder), override the
OnModelCreating()
method and add amodelBuilder.UseDeferredDeletion(this)
call:
C#protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.UseDeferredDeletion(this); //!!!!!!!!!
}
- Run the GCRecordGeneratorTool found in the attachment for easier database update.
How to Revert to Previous Behavior
Use one of the following techniques:
-
Remove the
modelBuilder.UseDeferredDeletion(this)
registration. -
Mark required EF Core entities with the DisableDeferredDeletion attribute:
C#[DisableDeferredDeletion] //!!!!!!!!!
public class Supplier : BaseObject { }
}