I don't see errors. I have debugged up to the DetermineActionQueues.
DetermineActionQueues is called for every element in elementsToProcess in ConstructSaveProcessQueues in UnitOfWork2.
List _entitiesToInsert is updated as variable queue in ObjectGraphUtils. Items are added. And at the end the list is cleared and then have to be added again from elementsPerType from sortedTypesList.
But in my second run of this call the queue has 3 items, are added to elementsPerType. queue is cleared, and in the last for each it is not again added.
Then I think the sortedTypesList is produced from the current Entity in ProduceTopologyOrderedList.
My guess is that the sortedTypesList can vary from entity to entity(type) when not all of the same types exist in the hierarchies. If so, then the code below will only add those new entities if the entity in the last run of DetermineActionQueues also has all these entities. A bit cryptive maybe, sorry for that, but I dont know how else to describe all of this else.
So if the sortedTypesList does not contain one (or more) types in the queue, the queue is not complete or even empty, in my case.
// now we have to sort the insert queue based on the sorted types list, so all entities belonging to a given type have to be placed in the slot of the type.
// meaning, if we have as sorted types: Customer, Employee, Order, and as entities in the insert queue: Customer1, Order1, Customer2, Order2, Employee1, Order3,
// the insert queue will become: Customer1, Customer2, Employee1, Order1, Order2, Order3.
// we can skip this step if there's just 1 type or we're processing updates as we'll leave those alone.
if(sortedTypesList.Count > 1 && forInserts && queue.Count > 1)
{
var elementsPerType = new Dictionary<Type, List<ActionQueueElement<TEntity>>>();
foreach(var e in queue)
{
var entityType = e?.Entity.GetType();
if(entityType == null)
{
continue;
}
var elements = elementsPerType.GetValue(entityType);
if(elements == null)
{
elements = new List<ActionQueueElement<TEntity>>();
elementsPerType.Add(entityType, elements);
}
elements.Add(e);
}
// clear the destination as we're going to restore it with the elements in the right order
queue.Clear();
foreach(var type in sortedTypesList)
{
var elementsOfType = elementsPerType.GetValue(type);
if(elementsOfType == null)
{
continue;
}
queue.AddRange(elementsOfType);
}
}
Could you shed your light on this?