Intercept Delete (SelfServicing)

Posts   
 
    
CSharpner
User
Posts: 28
Joined: 03-Jun-2007
# Posted on: 26-Aug-2007 07:20:36   

LLBLGen Pro 2.5

SelfServicing

I'm trying to find a method to override (or any other means) to block an entity from being deleted.

I've tried overriding:

  • OnValidateEntityBeforeDelete
  • OnDelete
  • OnAuditDeleteOfEntity

But it seems the only way to block the deletion from happenning is to intentionally throw an Exception in one of those (OnValidateEntityBeforeDelete, I think is the one that worked for me). Obviously, I'd prefer a cleaner way. For example: A lot of events in .NET can be blocked in the event handler by setting the Cancel property of the EventArgs to false like so:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { e.Cancel = false; //Don't let the delete happen. }

In case I'm going about this the wrong way, what I'm trying to ultimately accomplish is to have a stored procedure called instead of a direct delete. Perhaps overriding one of the delete events is the wrong path?

TIA

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 26-Aug-2007 08:54:17   

Perhaps you could do that with a "before"/"instead of" trigger? You can then raise an error and catch it from your app to know that the delete has been cancelled.

At least it will work everytime, not only when you call YourEntity.delete() but also when you're using other ways like caliing deleteMulti() with a predicate expression.

CSharpner
User
Posts: 28
Joined: 03-Jun-2007
# Posted on: 26-Aug-2007 09:29:44   

Do you mean a trigger on the table in the database? If so, that's what I originally had. I had triggers for insert, update, and delete that wrote a history record in a history table and a record into an audit table. A key piece of information is the logged on user ID, which I pass via a field in the table. Unfortunately, on delete, there's no way to get this down to the table to pass through to the trigger that puts it in the audit table. As a work around, I'm wanting to intercept LLBLGen's delete and call my own delete stored proc to do the work. From there, I can pass the logged on user ID to the SP.

CSharpner
User
Posts: 28
Joined: 03-Jun-2007
# Posted on: 26-Aug-2007 09:41:13   

Never mind... I solved it.

I just overrode the entity's OnDelete and called my delete stored proc from there and allowed the delete to continue (and deleted my delete trigger from the table).

Overriding OnDelete didn't work for me at first because of how my database was set up (the way I had the triggers and the stored procedures set up). I changed those around and OnDelete became feasible.