From a522e1e443d3ce51ef63ce3cb46188cbb3489d04 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 6 Jun 2019 09:45:27 -0700 Subject: [PATCH] Query: Set reference navigation loaded when referenced entity is null in tracking query Resolves #15949 --- .../Pipeline/IncludeCompilingExpressionVisitor.cs | 10 +++++++++- .../Query/IncludeTestBase.cs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Relational/Query/Pipeline/IncludeCompilingExpressionVisitor.cs b/src/EFCore.Relational/Query/Pipeline/IncludeCompilingExpressionVisitor.cs index 5eaae56c9c4..bee96f1ba58 100644 --- a/src/EFCore.Relational/Query/Pipeline/IncludeCompilingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Pipeline/IncludeCompilingExpressionVisitor.cs @@ -46,7 +46,15 @@ private static void IncludeReference( { var relatedEntity = innerShaper(queryContext, dbDataReader, resultCoordinator); - if (!trackingQuery) + if (trackingQuery) + { + // For non-null relatedEntity StateManager will set the flag + if (ReferenceEquals(relatedEntity, null)) + { + queryContext.StateManager.TryGetEntry(entity).SetIsLoaded(navigation); + } + } + else { SetIsLoadedNoTracking(entity, navigation); if (!ReferenceEquals(relatedEntity, null)) diff --git a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs index 4726835d6fc..4a27abe1baa 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs @@ -4099,7 +4099,7 @@ public virtual async Task Include_empty_collection_sets_IsLoaded(bool useString, } } - [ConditionalTheory(Skip = "#15949")] + [ConditionalTheory] [InlineData(false, false)] [InlineData(true, false)] public virtual async Task Include_empty_reference_sets_IsLoaded(bool useString, bool async)