Hi all,
I have a problem with saving my entity hierarchy.
The data model has a company with 1:n employees and each employee has 1:n tasks. They are compositions.
Im my company edit screen I have a table with all employees. When I add a new employee, their edit screen opens and there I have a table with all tasks for the employee. So I add a new task as well for the new employee. When I hit ok for the task edit, it is committed to the parent data context. Then I hit ok on the employee edit and they are also committed to the parent data context.
Finally, when I hit ok/save in the company edit, I can see that the company, the new employee and the new task are all in the dataContext as modified instances.
But when the commit happens, I get a foreign key no parent error for the task because it has the employee as parent which is not yet saved to the database. In the data context, the task comes before the employee so the database gives me the error.
How can I influence the order in the dataContext? I always thought the modified instances get inserted in the data base and then the commit happens and only then the contraints are tested but I think I have been wrong there.
So the question would be how to handle those 1:n:n compositions? Do I need to commit the employee as soon as they are created? That maybe would work but then the user could not cancel the creation of the employee anymore.
Thanks for any hints!
p.s. the error seems to be caused because I set the new task in the new employee also as a property “currentTask”, so the employee has a list of tasks but always one that is currently executed. But the WHY remains a mystery to me…