Hi Dave,
DaveW_396 wrote:
I have a followup question based on my testing. Why is there a difference in the deletion criteria when using the DataAccessAdaptor's DeleteEntity() and DeleteEntityCollection()?
DeleteEntityCollection() creates -internally- a UnitOfWork to commit all deletes together. When the UnitOfWork is commited, it internally calls DeleteEntity for each delete call. If one of these calls returns "False" (something went wrong) it raise the exception.
DeleteEntity() doesn't thrown exception but it returns 'true' or 'false' (true if the delete was succesful, otherwise false).
DaveW_396 wrote:
In both cases I tested the IsDirty property is set to true (because I set the PK I assume),
Yes, coz you indeed set the PK.
DaveW_396 wrote:
DeleteEntity() will delete an entity from the DB if the IsNew property is set to true or false on the entity.
DeleteEntityCollection() will delete an entity from the DB only if the IsNew property is set to false.
Well. This is what happens:
At DeleteEntity(), the method doesn't check the _IsNew _flag, but it indeed will returns true or false (it will return false is for example, the entity doesn't exists). It something else happened (failed, due to the delete restriction, for instance) it will throw an ORMConcurrencyException.
Now, DeleteEntityCollection() will add each entityToDelete to a UnitOfWork queue. When some entity is added to the Delete Queue, it indeed checks whether or not the entity "Is New". So if the entity is new, it isn't added, so no deletes are performed.
Hope my explanation was clear.