Deleting a record that is required by another record

XAF will generate a button to delete records using the UI.
However if the record is required by some other record then the delete will fail with an error message.

There are at least 3 ways to work around this…

The easy way:

Declare the relationship with CascadeOnDelete = true
XAF will then be able to delete the required record along with the records that require it.

2) The hard way

Write your own Delete actions and hide the XAF actions

3 The pragmatic way

Inherit from the DeleteObjectsViewController
Declare an Interface and write your own actions to use it
Note this button will require you to add your own delete action and hide the XAF action

public interface IDeleteMe
void DeleteMe(IObjectSpace os);

Use the interface on the business object, then in the implementation of the interface delete the related records.
For example

public class SalesOrder : IDeleteRelated
public void DeleteRelated(IObjectSpace os)
foreach (var orderLine in Lines.ToList())
orderLine.DeleteRelated(os) // removes attached workflow
os.Delete(orderLine); // marks orderLine and it’s aggregated objects as deleted from persistent storage

public partial class DeleteController : DeleteObjectsViewController

    protected override void Delete(SimpleActionExecuteEventArgs args)
        var rec = args.CurrentObject as IDeleteRelated;

@kirsten.greed test