deleteRestriction Impact

Posts   
 
    
PaulW
User
Posts: 3
Joined: 12-May-2010
# Posted on: 12-May-2010 12:38:25   

All,

I'm working on a project where the architectural requirement is to set an "isDeleted" flag on the table rather than actually delete the record. The initial plan for the selfservicing project is simple: To override the "Delete(IPredicate deleteRestriction)" method on CommonEntityBase.

The code thus looks something like this.

    public override bool Delete(IPredicate deleteRestriction)
    {
        bool success = false;
        var isDeleted = this.GetFieldByName("IsDeleted");
        if (isDeleted != null)
        {
            isDeleted.CurrentValue = true;
            this.IsDirty = true;
            success = Save(deleteRestriction);
        }
        else
        {
            success = base.Delete(deleteRestriction);
        }
        return success;
    }

This works well, my question thus, is around how this would work with an update restriction set. Or when multiple items in a collection are deleted.

If an update restriction causes the item not to be changed(or deleted), does it throw an exception or return false?

Are there any other obvious flaws to this plan that anyone can see.

This is my first experience of LLBLGen Pro, and I find the forums to be of an excellent quality and the product seems good too.

Thanks in advance,

Paul

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 12-May-2010 14:14:44   

This is called soft deletes, and it's not recommended at all.

If you can't delete rows, use an archiving catalog and delete triggers. Soft-deletes will eventually bring down your system as the amount of data you've to work with in the DB far outweighs the amount of data in your working set. Plus, FK constraints can't be used.

Please check Frans' post about this issue: Soft-deletes are bad, m'kay?

PaulW
User
Posts: 3
Joined: 12-May-2010
# Posted on: 12-May-2010 14:33:31   

Agreed, soft deletes are not good practice. However, I didn't expand the code very much as we aren't soft deleting.

The row does actually get deleted via a trigger which also updates an audit record. It is designed this way since the majority of the updates are done through the database.

If a row that should get deleted, doesn't due to a delete restriction, how is that handled? Exception, returning false or just returning true since the statement would run correctly?

The broader question, is how does this work with deleting multiple rows through the LLBGen framework.

I was also wondering if this requirement was best implemented in CommonEntityBase or somewhere else?

Thanks for your swift reply,

Paul

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 12-May-2010 16:19:43   

The row does actually get deleted via a trigger which also updates an audit record. It is designed this way since the majority of the updates are done through the database.

If a row that should get deleted, doesn't due to a delete restriction, how is that handled? Exception, returning false or just returning true since the statement would run correctly?

If the query runs fine, then true will be returned.

The broader question, is how does this work with deleting multiple rows through the LLBGen framework.

Calling a DeleteMulti (without predicates) on an entityCollection, calls Delete() on each entity. So if you override Delete() you'd be fine here.

But If you are already using triggers, perhaps you can rely on a trigger here too. a Before Delete Trigger, and let it update the flag and cancel the delete operation.

I was also wondering if this requirement was best implemented in CommonEntityBase or somewhere else?

If it's for all entities, then this is the best place. Otherwise use a partial class of the specific entity to Override the Delete method.