Immediate delete of an object vs using a command object #4243
Replies: 3 comments 7 replies
-
Hi. Sorry I don't understand the question. Maybe you could write an example for your object graph and the goal you want to achieve or avoid. |
Beta Was this translation helpful? Give feedback.
-
I normally don't perform the delete on an editable root object. It's done via a list of read-only objects. After the user confirms, the delete factory method is called passing in the relevant Id. Any children are usually deleted by cascading with SQL, or with some more complicated SQL if there are multiple cascading paths, which confuses SQL Server. |
Beta Was this translation helpful? Give feedback.
-
We usually implement delete operations to support both techniques via the data portal. An internal method handles the actual delete from the database. A Delete method on the data portal is implemented to call the internal method. The Update method, when it determines the object needs to be deleted, calls the internal method then marks the object as new. The implementation specifics within the data portal methods will depend on the encapsulation model you use for the data portal. But this allows clients to use whichever technique makes the most sense for the business function. Sometimes, we're working with "info" classes and want to support a delete operation. We'll use the DataPortal.Delete(objectID) technique to directly delete the data. In other scenarios, we'll have an instance of the "edit" class, and then the delete is handled by myObject.Delete() followed by myObject = myObject.Save(), or we might not need the "new" object, so we call Save and set the client variable to null. Even if we don't need both techniques when we add a new business class to the project, we always code it to support both techniques. |
Beta Was this translation helpful? Give feedback.
-
We could use a command object if you have to delete a root object (and related data).
We could also use 'immediate delete' instead of a command object.
If we do that, do we still have to set the child objects to 'new' by calling DataPortal.CreateChild (in the delete method of the root object)?
Kind Regards
Beta Was this translation helpful? Give feedback.
All reactions