Breaking Change T1247762
Visible to All Users

Core - Database and data model code changes for XAF EF Core apps to support Soft/Deferred Deletion

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:

  1. 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.
  2. 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:

  1. Inherit your EF Core entity classes from DevExpress.Persistent.BaseImpl.EF.BaseObject (BaseObject has a GCRecord property):
Code
public 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):

Code
public class Supplier : YourCustomBaseObjectIfAny, IDeferredDeletion { public virtual int GCRecord { get; set; } }
  1. In your DbContext descendant (typically in the YourSolutionName.Module/BusinessObjects folder), override the OnModelCreating() method and add a modelBuilder.UseDeferredDeletion(this) call:
C#
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.UseDeferredDeletion(this); //!!!!!!!!! }
  1. 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 { } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.