Logical delete and CRUD operations.

Posts   
 
    
x3mka
User
Posts: 6
Joined: 23-Mar-2009
# Posted on: 25-Mar-2009 17:28:02   

Hi.

I have stuck with the following situation. I have a table, say Product. It has a field IsActive with validation rule checking only 1 (active) and 0 (deleted). I made an instead of delete trigger changing IsActive to 0 if the product is deleted.

The question is how to code standard CRUD operations using approach with LLBLGenDataSource and GridView. All operations are performed in grid view.

GridView should display only active products so I have to filter somewhere. I think there are 2 options:

  1. Set LivePersistence=false and make all CRUD stuff in data source event handlers.

  2. Create a view vw_Products as Select * from Product where IsActive=1. But defining an entity mapped to a view causes in no relation fields and some other conveniencies as an entity mapped on a table has.

May be I missed something. Could someone help? Some better aproach?

Thank you in advance.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Mar-2009 03:55:36   

Soft deletes aren't supported by default (and aren't recommended as well, check this article), which means you have to implement it yourself. If you're using adapter, override DeleteEntity() in a subclass of DataAccessAdapter and instead set a Deleted flag and save the entity, in selfservicing, you override the DeleteEntity method in the subclass for the entity in 2-class scenario and do the same thing.

For loading a set of entities, that's a different story. You have to append the filter for deleted entities manually.

You also can set LivePersistence=True, and apply the filter on the load of the page:

if (!IsPostBack)
{
     myLLBLGenProDataSource.FilterToUse = mySoftDeletesPredicate;
}
David Elizondo | LLBLGen Support Team