Print Page | Close Window

public override void Delete() no more

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=988
Printed Date: 11-Apr-2026 at 1:56pm


Topic: public override void Delete() no more
Posted By: sebma
Subject: public override void Delete() no more
Date Posted: 06-Nov-2008 at 6:08am
I was overriding the Delete() method to implement soft deletes, which basically set my database-table-row status flag to inactive.
 
With the release of DevForce EF Version 4.2.1.5, there is no longer an overrideable Delete() method on an entity.
From the release notes, we would configure our entities to handle EntityChangingEventArgs and EntityAction.Delete, in which it is still possible to direct the handler to set my database-table-row status flag to inactive. However, the database-table-row is still being physically deleted. To prevent it from being physically deleted from database, I would need to have something like this in my handler
 
        protected void OnMyEntityChanging<T>(object sender, EntityChangingEventArgs e) where T : Entity
        {
            if (e.Action == EntityAction.Delete)
            {
                T thisObj = (T)e.Entity;
                if (this.Equals(thisObj)) // because this handler is registered to EntityGroup of a Type, I need to ignore the event if it does not belong to this instance
                {
                    Delete(); // calls my derived class delete which actually sets my own status flag to inactive
                    e.Cancel = true; // Cancel the delete action to prevent physical delete
                }               
            }
        }
 
Another simple way is just simply my own public DeleteMe() method on my entities which basically does an update (setting database-table-row status flag to inactive).
 
In both cases, the entity's EntityAspect.EntityState is not in a state of Deleted. Is this as designed?
 
Thanks and best regards,
Sebastian
 
 



Replies:
Posted By: GregD
Date Posted: 06-Nov-2008 at 6:27am
Originally posted by sebma

In both cases, the entity's EntityAspect.EntityState is not in a state of Deleted. Is this as designed?
 
I'm not positive I understand your question, but...
 
EntityState.Deleted means the entity is marked for physical deletion and that the corresponding row in the back-end database will be physically deleted as of the next save.  If you're implementing a "soft delete" scheme, then delete doesn't really mean delete in the physical sense; so you would not want the EntityState to be Deleted after the operation.
 
If, by your question "Is this as designed?" you mean the fact that EntityState != Deleted after calling Cancel within the handler, then yes, that is as designed.
 



Print Page | Close Window