Entity Validation and DenyDelete

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 16-Oct-2004 11:34:53   

Greetings All,

After the order entity implements the IEntityValidator:

After that, the Save actions or order.Validate() will use the IEntityValidator() instance for validation

This is great BUT what if I want to implemet the validation for the Delete actions as well (without explicitly calling Validate method). Example: I want to delete a GL Account but I should NOT be able to delete it if it has any transactions in some other tables.

In CSLA, I had a BrokenRules collection that I extended to utilize a BrokenRuleType. All my delete actions would consult the object's IsValid(BrokenRuleType.DenyDelete) method to check for the existance of any broken rules that prohibit Delete. The same logic could be extended to implement Warning type broken rules on the object.

How can I implement this sort of functionality with LLBL ?

OMAR

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 16-Oct-2004 12:06:00   

Delete entities on the database can be limited by adding predicates, which work on the same table, for concurrency control for example.

Denying a delete, can be implemented by you by overriding Delete in the derived entity class in the 2-class scenario in selfservicing (do your actions there) or in a derived class of DataAccessAdapter and you override DeleteEntity() there, doing your checks there.

Keep in mind that business rules spanning multiple entities (which this is) can better be implemented in a management class so you know where the rules are located. By using Adapter for example, you can pass an entity for deletion to that class, and that class does checking first, and denies the delete if a rule fails or proceeds if the rule succeeds.

Frans Bouma | Lead developer LLBLGen Pro