Further to question Can EF automatically delete data that is orphaned, where the parent is not deleted?
I checked the solution, as @Ladislav suggested here https://stackoverflow.com/a/10838228/54801 Unfortunately I noticed that the solution works partially.
If we take the following code:
for (int k = 0; k < 2; k++)
{
var parentObject= _context.Parents.Get(1704);
parentObject.ChildObjects.Clear();
var childObject= _context.ChildObjects.Get(1000*k /*diffrent child for each iteration*/ );
parentObject.ChildObjects.Add(childObject);
_context.Commit();
}
The first iteration (k=0) was carried out deletion. But the second iteration will not delete!
Does anyone have a solution to the problem?
The problem can be "solved" as shown here:
if(k == 1)
{
foreach (var project in tender.TenderProjects)
{
_context.Projects.Remove(project);
}
}
But it's definitely not ideal I want my services out of any ORM logic..
EDIT:
The Iteration is just an example of the real scenario. Real scenario, the user can add the parent entity's first child. save the data and go again to remove the first child and add two other childs in his place