New Posts New Posts RSS Feed: public override void Delete() no more
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

public override void Delete() no more

 Post Reply Post Reply
Author
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Topic: public override void Delete() no more
    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.
 
Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post 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
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down