[Issue #1780] Bug: IncludeGraph fails when first entity has null navigation property #1901
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed the case of inserting child entities, when there could be an entity with an empty child entity at the beginning of the array. Because of this, the subsequent insertion of bundles of entities was performed incorrectly.
GroupBybyEntityTypeinExecuteWithGraphAsyncput the type of entity that was the parent in the first place.Example
The main entity is Parent - P, the child entity is Child - C.
If there was an array Parent[]
After sorting, we get: PCPCP
After grouping, we will insert in bundles: Parent[], Child[]. Which is wrong!
If all the Parents had Child, then after sorting we get: CPCPCP
After grouping, we will insert in bundles: Child[], Parent[]. That's right.
Solution
To avoid this problem, an additional sorting by graph depth was added.
For each entity, its depth (length to the vertex) is determined. The maximum depth is determined for each type of entity in order to understand which entities need to be inserted first (the type of entity with the maximum depth) and which last (the type of entity with the minimum depth).
Further, with GroupBy, the groups will be formed correctly and the identifiers for external entities will be entered correctly.
In summary
BulkInsertOrUpdate_EntityWithNestedNullableObjectGraph_SavesGraphToDatabase1)withAdditionalSortinginGraphUtilIt remains to be done