|
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
|