Asimov wrote:
in the following code
_Evenement = new EvenementEntity(Ident);
transaction.Add(_Evenement);
transaction.Add(_Evenement.EvenementEquipes);
transaction.Add(_Evenement.PublicationEvenements);
_Evenement.EvenementEquipes.DeleteMulti();
_Evenement.PublicationEvenements.DeleteMulti();
succeed = _Evenement.Delete();
transaction.Commit();
- am I right to put the children collections in the transaction if the parent entity is already in the transaction?
Yes, as Delete actions aren't recursive.
- I get an error on the line ** succeed = _Evenement.Delete();** about foreign key constraint. It says I can't delete the entity referenced by _Evenement because it would violate the foreign key constraint in _Evenement.PublicationEvenements (the table that links publications Evenement and Publication in a nxn relationship. But I don't understand why the error occurs at all (because I delete the content from the linkage table before deleting the entity, and why the error occurs on the Delete(); instead of the line with Commit() (when the sql is executed) ?
Deletes are executed when you call them. You confuse UnitOfWork behavior with this I think. The Commit() is for finalizing the transaction, so the RDBMS will commit the transaction, however the commands are already executed. So you have to first delete the FK side, then the PK side.