diff --git a/src/EFCore/Query/NavigationExpansion/Visitors/NavigationExpandingVisitor_MethodCall.cs b/src/EFCore/Query/NavigationExpansion/Visitors/NavigationExpandingVisitor_MethodCall.cs index ddc9d80c346..b8102b77ec0 100644 --- a/src/EFCore/Query/NavigationExpansion/Visitors/NavigationExpandingVisitor_MethodCall.cs +++ b/src/EFCore/Query/NavigationExpansion/Visitors/NavigationExpandingVisitor_MethodCall.cs @@ -876,11 +876,11 @@ private Expression ProcessSetOperation(MethodCallExpression methodCallExpression // Extract the includes from each side and compare to make sure they're identical. // We don't allow set operations over operands with different includes. - var pendingIncludeFindingVisitor = new PendingIncludeFindingVisitor(false); + var pendingIncludeFindingVisitor = new PendingIncludeFindingVisitor(skipCollectionNavigations: false); pendingIncludeFindingVisitor.Visit(preProcessResult1.state.PendingSelector.Body); var pendingIncludes1 = pendingIncludeFindingVisitor.PendingIncludes; - pendingIncludeFindingVisitor = new PendingIncludeFindingVisitor(false); + pendingIncludeFindingVisitor = new PendingIncludeFindingVisitor(skipCollectionNavigations: false); pendingIncludeFindingVisitor.Visit(preProcessResult2.state.PendingSelector.Body); var pendingIncludes2 = pendingIncludeFindingVisitor.PendingIncludes; @@ -891,14 +891,8 @@ private Expression ProcessSetOperation(MethodCallExpression methodCallExpression foreach (var (i1, i2) in pendingIncludes1.Zip(pendingIncludes2, (i1, i2) => (i1, i2))) { - if (i1.SourceMapping.RootEntityType != i2.SourceMapping.RootEntityType) - { - throw new NotSupportedException(CoreStrings.SetOperationWithDifferentIncludesInOperands); - } - - if (i1.NavTreeNode.Flatten() - .Zip(i2.NavTreeNode.Flatten(), (n1, n2) => (First: n1, Second: n2)) - .Any(nodes => nodes.First.Navigation != nodes.Second.Navigation)) + if (i1.SourceMapping.RootEntityType != i2.SourceMapping.RootEntityType + || i1.NavTreeNode.Navigation != i2.NavTreeNode.Navigation) { throw new NotSupportedException(CoreStrings.SetOperationWithDifferentIncludesInOperands); }