I have the table A and Table B:
TableA(IDTableA,...) TableB(IDTableB, IDTableA,...)
I know that I can delete on cascada if I set this on the database, but if I haven't defined this in the database and I want to delete the children with EF, which is the best way to do that?
Imagine this situation: user A add to the context the parent, user A add the childs to context, mark the parent and the children as deleted and save the changes. But if an user B add a new child between the time user A loads the children and confirm the changes, the new child added by the user B is not deleted, or I get an exception because of reference integrity.
I try to use a transaction, to set the parent as deleted, then, in the next step, when I make the savechanges
, the parent register is locked, so can't be load by other user. But the problem is the same, other user can make changes in the parent between the parent is load and the save changes.
So my question is, if I want to delete the parent and all its children with EF, which is the best way? The best way is try N times delete the parent? is this a good option when I wnat a good performance?
Thanks. Daimroc.