From de0e190b6592dd2ca3db53e3df7eac1b96dae536 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Sun, 7 Nov 2021 15:05:24 +0000 Subject: [PATCH] No skipped complex navigation tests Part of #26088 --- ...NavigationsCollectionsQueryInMemoryTest.cs | 15 +- ...sCollectionsSharedTypeQueryInMemoryTest.cs | 13 +- .../ComplexNavigationsQueryInMemoryTest.cs | 8 + ...xNavigationsSharedTypeQueryInMemoryTest.cs | 6 + .../NorthwindGroupByQueryInMemoryTest.cs | 3 - ...mplexNavigationsQueryRelationalTestBase.cs | 9 +- .../TestUtilities/TestSqlLoggerFactory.cs | 50 +- ...plexNavigationsCollectionsQueryTestBase.cs | 1272 +-- ...tionsCollectionsSharedTypeQueryTestBase.cs | 53 +- .../Query/ComplexNavigationsQueryTestBase.cs | 1899 ++-- ...exNavigationsSharedTypeQueryFixtureBase.cs | 4 +- ...mplexNavigationsSharedTypeQueryTestBase.cs | 75 +- .../Query/GearsOfWarQueryTestBase.cs | 756 +- .../Query/NorthwindGroupByQueryTestBase.cs | 375 +- .../NorthwindMiscellaneousQueryTestBase.cs | 257 +- .../Query/QueryTestBase.cs | 30 + ...avigationsCollectionsQuerySqlServerTest.cs | 217 +- ...CollectionsSharedTypeQuerySqlServerTest.cs | 3988 +++++++- ...tionsCollectionsSplitQuerySqlServerTest.cs | 119 +- ...ctionsSplitSharedTypeQuerySqlServerTest.cs | 12 +- .../ComplexNavigationsQuerySqlServerTest.cs | 513 +- ...NavigationsSharedTypeQuerySqlServerTest.cs | 8145 ++++++++++++++++- .../NorthwindGroupByQuerySqlServerTest.cs | 98 +- ...avigationsCollectionsQuerySqlServerTest.cs | 2394 ++++- ...exNavigationsCollectionsQuerySqliteTest.cs | 46 +- ...onsCollectionsSharedTypeQuerySqliteTest.cs | 43 +- ...igationsCollectionsSplitQuerySqliteTest.cs | 46 +- ...llectionsSplitSharedTypeQuerySqliteTest.cs | 43 +- .../ComplexNavigationsQuerySqliteTest.cs | 20 + ...lexNavigationsSharedTypeQuerySqliteTest.cs | 28 +- 30 files changed, 17496 insertions(+), 3041 deletions(-) diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs index 66d15c9c5e7..50b8a797dd7 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsQueryInMemoryTest.cs @@ -1,16 +1,27 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Threading.Tasks; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsQueryInMemoryTest : ComplexNavigationsCollectionsQueryTestBase + public class ComplexNavigationsCollectionsQueryInMemoryTest + : ComplexNavigationsCollectionsQueryTestBase { - public ComplexNavigationsCollectionsQueryInMemoryTest(ComplexNavigationsQueryInMemoryFixture fixture, ITestOutputHelper testOutputHelper) + public ComplexNavigationsCollectionsQueryInMemoryTest( + ComplexNavigationsQueryInMemoryFixture fixture, + ITestOutputHelper testOutputHelper) : base(fixture) { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + // Nested collection with ToList. Issue #23303. + => await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs index 3ab248099fa..47e588dedd5 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest.cs @@ -1,14 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Threading.Tasks; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest : - ComplexNavigationsCollectionsSharedTypeQueryTestBase + public class ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest + : ComplexNavigationsCollectionsSharedTypeQueryTestBase { - // ReSharper disable once UnusedParameter.Local public ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest( ComplexNavigationsSharedTypeQueryInMemoryFixture fixture, ITestOutputHelper testOutputHelper) @@ -16,5 +18,10 @@ public ComplexNavigationsCollectionsSharedTypeQueryInMemoryTest( { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } + + public override Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + // Nested collection with ToList. Issue #23303. + => Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsQueryInMemoryTest.cs index a07ce9acf8b..075fe172da8 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsQueryInMemoryTest.cs @@ -1,6 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Threading.Tasks; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -12,5 +15,10 @@ public ComplexNavigationsQueryInMemoryTest(ComplexNavigationsQueryInMemoryFixtur { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } + + public override Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) + // Expression cannot be used for return type. Issue #23302. + => Assert.ThrowsAsync( + () => base.Join_with_result_selector_returning_queryable_throws_validation_error(async)); } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsSharedTypeQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsSharedTypeQueryInMemoryTest.cs index 3119c63585c..0492939ab84 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsSharedTypeQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/ComplexNavigationsSharedTypeQueryInMemoryTest.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; @@ -18,5 +19,10 @@ public ComplexNavigationsSharedTypeQueryInMemoryTest( { //TestLoggerFactory.TestOutputHelper = testOutputHelper; } + + public override Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) + // Expression cannot be used for return type. Issue #23302. + => Assert.ThrowsAsync( + () => base.Join_with_result_selector_returning_queryable_throws_validation_error(async)); } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs index ba042a34245..b49fef76bd3 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindGroupByQueryInMemoryTest.cs @@ -1,9 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestUtilities; -using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -12,7 +10,6 @@ public class NorthwindGroupByQueryInMemoryTest : NorthwindGroupByQueryTestBase fixture, - // ReSharper disable once UnusedParameter.Local ITestOutputHelper testOutputHelper) : base(fixture) { diff --git a/test/EFCore.Relational.Specification.Tests/Query/ComplexNavigationsQueryRelationalTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/ComplexNavigationsQueryRelationalTestBase.cs index 47dc5b64a4c..cf12690e113 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/ComplexNavigationsQueryRelationalTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/ComplexNavigationsQueryRelationalTestBase.cs @@ -1,13 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Linq; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; using Microsoft.EntityFrameworkCore.TestUtilities; -using Xunit; namespace Microsoft.EntityFrameworkCore.Query { @@ -20,9 +15,7 @@ protected ComplexNavigationsQueryRelationalTestBase(TFixture fixture) } public override Task Complex_query_with_optional_navigations_and_client_side_evaluation(bool async) - { - return AssertTranslationFailed(() => base.Complex_query_with_optional_navigations_and_client_side_evaluation(async)); - } + => AssertTranslationFailed(() => base.Complex_query_with_optional_navigations_and_client_side_evaluation(async)); protected virtual bool CanExecuteQueryString => false; diff --git a/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs b/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs index 247e0a29f34..7bd61d51f1b 100644 --- a/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs +++ b/test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs @@ -22,6 +22,7 @@ public class TestSqlLoggerFactory : ListLoggerFactory private static readonly string _eol = Environment.NewLine; private static readonly object _queryBaselineFileLock = new(); + private static readonly HashSet _overriddenMethods = new(); public TestSqlLoggerFactory() : this(_ => true) @@ -89,14 +90,17 @@ public void AssertBaseline(string[] expected, bool assertOrder = true) 0, currentDirectory.LastIndexOf( $"{Path.DirectorySeparatorChar}artifacts{Path.DirectorySeparatorChar}", - StringComparison.Ordinal) + 1) + StringComparison.Ordinal) + + 1) + "QueryBaseline.txt"; var testInfo = testName + " : " + lineNumber + FileNewLine; const string indent = FileNewLine + " "; + var sql = string.Join( + "," + indent + "//" + indent, SqlStatements.Take(9).Select(sql => "@\"" + sql.Replace("\"", "\"\"") + "\"")); var newBaseLine = $@" AssertSql( - {string.Join("," + indent + "//" + indent, SqlStatements.Take(9).Select(sql => "@\"" + sql.Replace("\"", "\"\"") + "\""))}); + {sql}); "; @@ -110,9 +114,47 @@ public void AssertBaseline(string[] expected, bool assertOrder = true) var contents = testInfo + newBaseLine + FileNewLine + "--------------------" + FileNewLine; + var indexSimpleMethodEnding = methodCallLine.IndexOf('('); + var indexSimpleMethodStarting = methodCallLine.LastIndexOf('.', indexSimpleMethodEnding) + 1; + var methodName = methodCallLine.Substring(indexSimpleMethodStarting, indexSimpleMethodEnding - indexSimpleMethodStarting); + + var manipulatedSql = string.IsNullOrEmpty(sql) + ? "" + : @$" +{sql}"; + + var overrideString = testName.Contains("Boolean async") + ? @$" public override async Task {methodName}(bool async) + {{ + await base.{methodName}(async); + + AssertSql({manipulatedSql}); + }} + +" + : @$" public override void {methodName}() + {{ + base.{methodName}(); + + AssertSql({manipulatedSql}); + }} + +"; + lock (_queryBaselineFileLock) { File.AppendAllText(logFile, contents); + + // if (!_overriddenMethods.Any()) + // { + // File.Delete(logFile); + // } + // + // if (!_overriddenMethods.Contains(methodName)) + // { + // File.AppendAllText(logFile, overrideString); + // _overriddenMethods.Add(methodName); + // } } throw; @@ -147,8 +189,8 @@ protected override void UnsafeLog( Exception exception) { if ((eventId.Id == RelationalEventId.CommandExecuted.Id - || eventId.Id == RelationalEventId.CommandError.Id - || eventId.Id == RelationalEventId.CommandExecuting.Id)) + || eventId.Id == RelationalEventId.CommandError.Id + || eventId.Id == RelationalEventId.CommandExecuting.Id)) { if (_shouldLogCommands) { diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs index 1300d69f959..0d0c1f9882d 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsQueryTestBase.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; @@ -18,8 +20,8 @@ public abstract class ComplexNavigationsCollectionsQueryTestBase : Que protected ComplexNavigationsContext CreateContext() => Fixture.CreateContext(); - public ComplexNavigationsCollectionsQueryTestBase(TFixture fixture) - : base(fixture) + protected ComplexNavigationsCollectionsQueryTestBase(TFixture fixture) + : base(fixture) { } @@ -29,20 +31,17 @@ protected override Expression RewriteExpectedQueryExpression(Expression expected [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_nav_prop_collection_one_to_many_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(e => e.Id).Select(e => e.OneToMany_Required1.Select(i => i.Id)), assertOrder: true, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l4 in ss.Set().SelectMany( l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) @@ -87,25 +86,21 @@ orderby l2.OneToOne_Optional_FK2.MaybeScalar(x => x.Id) AssertCollection(e.Collection, a.Collection); Assert.Equal(e.Property, a.Property); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select l1.OneToMany_Optional1, elementSorter: e => e != null ? e.Count : 0, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation_nested(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select l1.OneToOne_Optional_FK1.OneToMany_Optional2, @@ -113,13 +108,11 @@ public virtual Task Project_collection_navigation_nested(bool async) select l1.OneToOne_Optional_FK1.OneToMany_Optional2 ?? new List(), elementSorter: e => e.Count, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation_nested_with_take(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select l1.OneToOne_Optional_FK1.OneToMany_Optional2.Take(50), @@ -127,13 +120,11 @@ select l1.OneToOne_Optional_FK1.OneToMany_Optional2.Take(50), select (l1.OneToOne_Optional_FK1.OneToMany_Optional2 ?? new List()).Take(50), elementSorter: e => e?.Count() ?? 0, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation_using_ef_property(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select EF.Property>( @@ -143,13 +134,11 @@ select EF.Property>( "OneToMany_Optional2"), elementSorter: e => e?.Count ?? 0, elementAsserter: (e, a) => AssertCollection(e ?? new List(), a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation_nested_anonymous(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select new { l1.Id, l1.OneToOne_Optional_FK1.OneToMany_Optional2 }, @@ -159,13 +148,11 @@ public virtual Task Project_collection_navigation_nested_anonymous(bool async) Assert.Equal(e.Id, a.Id); AssertCollection(e.OneToMany_Optional2 ?? new List(), a.OneToMany_Optional2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation_composed(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.Id < 3 @@ -176,13 +163,11 @@ where l1.Id < 3 Assert.Equal(e.Id, a.Id); AssertCollection(e.collection, a.collection); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_and_root_entity(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select new { l1, l1.OneToMany_Optional1 }, @@ -192,13 +177,11 @@ public virtual Task Project_collection_and_root_entity(bool async) Assert.Equal(e.l1.Id, a.l1.Id); AssertCollection(e.OneToMany_Optional1, a.OneToMany_Optional1); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_and_include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set().Include(l => l.OneToMany_Optional1) select new { l1, l1.OneToMany_Optional1 }, @@ -208,13 +191,11 @@ public virtual Task Project_collection_and_include(bool async) Assert.Equal(e.l1.Id, a.l1.Id); AssertCollection(e.OneToMany_Optional1, a.OneToMany_Optional1); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_navigation_and_collection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select new { l1.OneToOne_Optional_FK1, l1.OneToOne_Optional_FK1.OneToMany_Optional2 }, @@ -224,14 +205,11 @@ public virtual Task Project_navigation_and_collection(bool async) Assert.Equal(e.OneToOne_Optional_FK1?.Id, a.OneToOne_Optional_FK1?.Id); AssertCollection(e.OneToMany_Optional2 ?? new List(), a.OneToMany_Optional2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_inside_subquery(bool async) - { - // can't use AssertQuery here, see #18191 - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l1 => l1.Id < 3) @@ -239,13 +217,11 @@ public virtual Task Include_inside_subquery(bool async) .Select(l1 => new { subquery = ss.Set().Include(l => l.OneToMany_Optional2).Where(l => l.Id > 0).ToList() }), assertOrder: true, elementAsserter: (e, a) => AssertCollection(e.subquery, a.subquery)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_check_in_anonymous_type_projection_should_not_be_removed(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Select( l1 => new @@ -263,13 +239,11 @@ public virtual Task Null_check_in_anonymous_type_projection_should_not_be_remove e.Level2s, a.Level2s, elementSorter: ee => ee?.Level3.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_check_in_Dto_projection_should_not_be_removed(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Select( l1 => new @@ -288,7 +262,6 @@ public virtual Task Null_check_in_Dto_projection_should_not_be_removed(bool asyn a.Level2s, elementSorter: ee => ee.Level3?.Value, elementAsserter: (ee, aa) => Assert.Equal(ee.Level3?.Value, aa.Level3?.Value))); - } private class ProjectedDto { @@ -298,8 +271,7 @@ private class ProjectedDto [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_followed_by_select_collection_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Optional1).Select(l2 => new { l2.Id, l2.OneToMany_Optional2 }), elementSorter: e => e.Id, @@ -308,13 +280,11 @@ public virtual Task SelectMany_navigation_property_followed_by_select_collection Assert.Equal(e.Id, a.Id); AssertCollection(e.OneToMany_Optional2, a.OneToMany_Optional2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_navigation_property_followed_by_select_collection_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Optional1).SelectMany(l2 => l2.OneToMany_Optional2) .Select(l2 => new { l2.Id, l2.OneToMany_Optional3 }), @@ -324,13 +294,11 @@ public virtual Task Multiple_SelectMany_navigation_property_followed_by_select_c Assert.Equal(e.Id, a.Id); AssertCollection(e.OneToMany_Optional3, a.OneToMany_Optional3); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_with_include_and_followed_by_select_collection_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) @@ -343,13 +311,11 @@ public virtual Task SelectMany_navigation_property_with_include_and_followed_by_ AssertCollection(e.l2.OneToMany_Required2, a.l2.OneToMany_Required2); AssertCollection(e.OneToMany_Optional2, a.OneToMany_Optional2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Lift_projection_mapping_when_pushing_down_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Take(25) @@ -367,13 +333,11 @@ public virtual Task Lift_projection_mapping_when_pushing_down_subquery(bool asyn Assert.Equal(e.c1?.Id, a.c1?.Id); AssertCollection(e.c2, a.c2, elementSorter: i => i.Id, elementAsserter: (ie, ia) => Assert.Equal(ie.Id, ia.Id)); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_subquery_single_nested_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Select( l1 => new @@ -394,13 +358,11 @@ public virtual Task Select_subquery_single_nested_subquery(bool async) AssertCollection(e.Level2.Level3s, a.Level2.Level3s, ordered: true); } }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_subquery_single_nested_subquery2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Select( l1 => new @@ -433,32 +395,31 @@ public virtual Task Select_subquery_single_nested_subquery2(bool async) } }); }); - } - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Queryable_in_subquery_works_when_final_projection_is_List(bool async) - { - return AssertQuery( - async, - ss => from l1 in ss.Set() - orderby l1.Id - let inner = (from l2 in l1.OneToMany_Optional1 - where l2.Name != "Foo" - let innerL1s = from innerL1 in ss.Set() - where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id) - select innerL1.Name - select innerL1s).FirstOrDefault() - select inner.ToList(), - assertOrder: true, - elementAsserter: (e, a) => AssertCollection(e, a)); - } + => AssertInvalidMaterializationType( + () => + AssertQuery( + async, + ss => from l1 in ss.Set() + orderby l1.Id + let inner = (from l2 in l1.OneToMany_Optional1 + where l2.Name != "Foo" + let innerL1s = from innerL1 in ss.Set() + where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id) + select innerL1.Name + select innerL1s).FirstOrDefault() + select inner.ToList(), + assertOrder: true, + elementAsserter: (e, a) => AssertCollection(e, a)), + typeof(IQueryable).ShortDisplayName()); - [ConditionalTheory(Skip = "issue #23303")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() orderby l1.Id @@ -471,13 +432,11 @@ select innerL1s.ToList()).FirstOrDefault() select inner.ToList(), assertOrder: true, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() orderby l1.Id @@ -490,28 +449,48 @@ select innerL1s.ToList()).FirstOrDefault() select inner, assertOrder: true, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async) - { - return AssertQuery( + => AssertQuery( async, - ss => from l4 in ss.Set().SelectMany(l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) - join l2 in ss.Set().SelectMany(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Optional_FK_Inverse3.OneToMany_Required_Self2.DefaultIfEmpty()) on l4.Id equals l2.Id - join l3 in ss.Set().SelectMany(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToMany_Required2.DefaultIfEmpty()) on l2.Id equals l3.Id into grouping + ss => from l4 in ss.Set().SelectMany( + l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) + join l2 in ss.Set().SelectMany( + l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Optional_FK_Inverse3.OneToMany_Required_Self2 + .DefaultIfEmpty()) on + l4.Id equals l2.Id + join l3 in ss.Set().SelectMany( + l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToMany_Required2.DefaultIfEmpty()) on + l2.Id equals l3.Id into grouping from l3 in grouping.DefaultIfEmpty() where l4.OneToMany_Optional_Inverse4.Name != "Foo" orderby l2.OneToOne_Optional_FK2.Id - select new { Entity = l4, Collection = l2.OneToMany_Optional_Self2.Where(e => e.Id != 42).ToList(), Property = l3.OneToOne_Optional_FK_Inverse3.OneToOne_Required_FK2.Name }, - ss => from l4 in ss.Set().SelectMany(l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) - join l2 in ss.Set().SelectMany(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Optional_FK_Inverse3.OneToMany_Required_Self2.DefaultIfEmpty()) on l4.Id equals l2.Id - join l3 in ss.Set().SelectMany(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToMany_Required2.DefaultIfEmpty()) on l2.Id equals l3.Id into grouping + select new + { + Entity = l4, + Collection = l2.OneToMany_Optional_Self2.Where(e => e.Id != 42).ToList(), + Property = l3.OneToOne_Optional_FK_Inverse3.OneToOne_Required_FK2.Name + }, + ss => from l4 in ss.Set().SelectMany( + l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) + join l2 in ss.Set().SelectMany( + l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Optional_FK_Inverse3.OneToMany_Required_Self2 + .DefaultIfEmpty()) on + l4.Id equals l2.Id + join l3 in ss.Set().SelectMany( + l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToMany_Required2.DefaultIfEmpty()) on + l2.Id equals l3.Id into grouping from l3 in grouping.DefaultIfEmpty() where l4.OneToMany_Optional_Inverse4.Name != "Foo" orderby l2.OneToOne_Optional_FK2.MaybeScalar(e => e.Id) - select new { Entity = l4, Collection = l2.OneToMany_Optional_Self2.Where(e => e.Id != 42).ToList(), Property = l3.OneToOne_Optional_FK_Inverse3.OneToOne_Required_FK2.Name }, + select new + { + Entity = l4, + Collection = l2.OneToMany_Optional_Self2.Where(e => e.Id != 42).ToList(), + Property = l3.OneToOne_Optional_FK_Inverse3.OneToOne_Required_FK2.Name + }, assertOrder: true, elementAsserter: (e, a) => { @@ -519,35 +498,36 @@ orderby l2.OneToOne_Optional_FK2.MaybeScalar(e => e.Id) AssertCollection(e.Collection, a.Collection); AssertEqual(e.Property, a.Property); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Take_Select_collection_Take(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Take(1) - .Select(l1 => new - { - Id = l1.Id, - Name = l1.Name, - Level2s = l1.OneToMany_Required1.OrderBy(l2 => l2.Id).Take(3) - .Select(l2 => new - { - Id = l2.Id, - Name = l2.Name, - Level1Id = EF.Property(l2, "OneToMany_Required_Inverse2Id"), - Level2Id = l2.Level1_Required_Id, - Level2 = l2.OneToOne_Required_FK_Inverse2 - }) - }), + .Select( + l1 => new + { + l1.Id, + l1.Name, + Level2s = l1.OneToMany_Required1.OrderBy(l2 => l2.Id).Take(3) + .Select( + l2 => new + { + l2.Id, + l2.Name, + Level1Id = EF.Property(l2, "OneToMany_Required_Inverse2Id"), + Level2Id = l2.Level1_Required_Id, + Level2 = l2.OneToOne_Required_FK_Inverse2 + }) + }), assertOrder: true, elementAsserter: (e, a) => { Assert.Equal(e.Id, a.Id); Assert.Equal(e.Name, a.Name); - AssertCollection(e.Level2s, a.Level2s, ordered: true, + AssertCollection( + e.Level2s, a.Level2s, ordered: true, elementAsserter: (ee, aa) => { Assert.Equal(ee.Id, aa.Id); @@ -557,35 +537,36 @@ public virtual Task Take_Select_collection_Take(bool async) AssertEqual(ee.Level2, aa.Level2); }); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_Select_collection_Skip_Take(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Skip(1).Take(1) - .Select(l1 => new - { - Id = l1.Id, - Name = l1.Name, - Level2s = l1.OneToMany_Required1.OrderBy(l2 => l2.Id).Skip(1).Take(3) - .Select(l2 => new - { - Id = l2.Id, - Name = l2.Name, - Level1Id = EF.Property(l2, "OneToMany_Required_Inverse2Id"), - Level2Id = l2.Level1_Required_Id, - Level2 = l2.OneToOne_Required_FK_Inverse2 - }) - }), + .Select( + l1 => new + { + l1.Id, + l1.Name, + Level2s = l1.OneToMany_Required1.OrderBy(l2 => l2.Id).Skip(1).Take(3) + .Select( + l2 => new + { + l2.Id, + l2.Name, + Level1Id = EF.Property(l2, "OneToMany_Required_Inverse2Id"), + Level2Id = l2.Level1_Required_Id, + Level2 = l2.OneToOne_Required_FK_Inverse2 + }) + }), assertOrder: true, elementAsserter: (e, a) => { Assert.Equal(e.Id, a.Id); Assert.Equal(e.Name, a.Name); - AssertCollection(e.Level2s, a.Level2s, ordered: true, + AssertCollection( + e.Level2s, a.Level2s, ordered: true, elementAsserter: (ee, aa) => { Assert.Equal(ee.Id, aa.Id); @@ -595,151 +576,110 @@ public virtual Task Skip_Take_Select_collection_Skip_Take(bool async) AssertEqual(ee.Level2, aa.Level2); }); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToMany_Optional1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(e => e.OneToMany_Optional1).ThenInclude(e => e.OneToMany_Optional2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, + new ExpectedInclude(l1 => l1.OneToMany_Optional1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times( bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToMany_Optional1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1"), - new ExpectedInclude(l3 => l3.OneToMany_Required_Inverse3, "OneToMany_Optional1.OneToMany_Optional2"), - new ExpectedInclude( - l2 => l2.OneToMany_Optional2, "OneToMany_Optional1.OneToMany_Optional2.OneToMany_Required_Inverse3") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(e => e.OneToMany_Optional1).ThenInclude(e => e.OneToMany_Optional2) .ThenInclude(e => e.OneToMany_Required_Inverse3.OneToMany_Optional2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, + new ExpectedInclude(l1 => l1.OneToMany_Optional1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1"), + new ExpectedInclude(l3 => l3.OneToMany_Required_Inverse3, "OneToMany_Optional1.OneToMany_Optional2"), + new ExpectedInclude( + l2 => l2.OneToMany_Optional2, "OneToMany_Optional1.OneToMany_Optional2.OneToMany_Required_Inverse3"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_includes(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l1 => l1.OneToMany_Optional1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1) .ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToMany_Optional1) .ThenInclude(e => e.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, + new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l1 => l1.OneToMany_Optional1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_includes_self_ref(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_Self1), - new ExpectedInclude(l2 => l2.OneToMany_Optional_Self1, "OneToOne_Optional_Self1"), - new ExpectedInclude(l1 => l1.OneToMany_Optional_Self1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_Self1, "OneToMany_Optional_Self1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_Self1) .ThenInclude(e => e.OneToMany_Optional_Self1) .Include(e => e.OneToMany_Optional_Self1) .ThenInclude(e => e.OneToOne_Optional_Self1), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_Self1), + new ExpectedInclude(l2 => l2.OneToMany_Optional_Self1, "OneToOne_Optional_Self1"), + new ExpectedInclude(l1 => l1.OneToMany_Optional_Self1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_Self1, "OneToMany_Optional_Self1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_and_collection_order_by(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1.OneToMany_Optional2) .OrderBy(e => e.Name), assertOrder: true, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_ThenInclude_collection_order_by(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1) .ThenInclude(e => e.OneToMany_Optional2) .OrderBy(e => e.Name), assertOrder: true, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_then_reference(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToMany_Optional1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToMany_Optional1) .ThenInclude(e => e.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToMany_Optional1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_conditional_order_by(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToMany_Optional1) @@ -747,128 +687,87 @@ public virtual Task Include_collection_with_conditional_order_by(bool async) .Select(e => e), elementSorter: e => e.Id, elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(ee => ee.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_include_select(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l1 => l1.OneToMany_Optional1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1) .ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToMany_Optional1) .ThenInclude(e => e.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l1 => l1.OneToMany_Optional1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_nested_with_optional_navigation(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l1 => l1.OneToMany_Required2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l1 => l1.OneToOne_Required_FK3, "OneToOne_Optional_FK1.OneToMany_Required2") - }; - - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() .Include(e => e.OneToOne_Optional_FK1.OneToMany_Required2) .ThenInclude(e => e.OneToOne_Required_FK3) where l1.OneToOne_Optional_FK1.Name != "L2 09" select l1, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l1 => l1.OneToMany_Required2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l1 => l1.OneToOne_Required_FK3, "OneToOne_Optional_FK1.OneToMany_Required2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_multi_include_with_order_by_and_paging(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), - new ExpectedInclude(l1 => l1.OneToMany_Optional2, "OneToOne_Required_FK1"), - new ExpectedInclude(l1 => l1.OneToMany_Required2, "OneToOne_Required_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Required2) .OrderBy(t => t.Name) .Skip(0).Take(10), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), + new ExpectedInclude(l1 => l1.OneToMany_Optional2, "OneToOne_Required_FK1"), + new ExpectedInclude(l1 => l1.OneToMany_Required2, "OneToOne_Required_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Required2, "OneToOne_Required_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1).ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Required2) .OrderBy(t => t.Name) .Skip(0).Take(10), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Required2, "OneToOne_Required_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key2(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Required_FK2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l3 => l3.OneToMany_Optional3, "OneToOne_Optional_FK1.OneToOne_Required_FK2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1.OneToOne_Required_FK2).ThenInclude(e => e.OneToMany_Optional3) .OrderBy(t => t.Name) .Skip(0).Take(10), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Required_FK2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l3 => l3.OneToMany_Optional3, "OneToOne_Optional_FK1.OneToOne_Required_FK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_include_with_multiple_optional_navigations(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Required_FK1"), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Required_FK1"), - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Optional2) @@ -876,164 +775,132 @@ public virtual Task Multiple_include_with_multiple_optional_navigations(bool asy .Include(e => e.OneToOne_Optional_FK1).ThenInclude(e => e.OneToOne_Optional_FK2) .Where(e => e.OneToOne_Required_FK1.OneToOne_Optional_PK2.Name != "Foo") .OrderBy(e => e.Id), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Required_FK1"), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Required_FK1"), + new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1")), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToMany_Optional2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Orderby_SelectMany_with_Include1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id) .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToMany_Optional2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToOne_Required_FK2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Required_FK2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include_ThenInclude(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l2 => l2.OneToOne_Required_FK2), - new ExpectedInclude(l3 => l3.OneToMany_Optional3, "OneToOne_Required_FK2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToOne_Required_FK2) .ThenInclude(l3 => l3.OneToMany_Optional3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l2 => l2.OneToOne_Required_FK2), + new ExpectedInclude(l3 => l3.OneToMany_Optional3, "OneToOne_Required_FK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_with_Include(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l3 => l3.OneToOne_Required_FK3), new ExpectedInclude(l3 => l3.OneToMany_Optional3) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .SelectMany(l2 => l2.OneToMany_Optional2) .Include(l3 => l3.OneToOne_Required_FK3) .Include(l3 => l3.OneToMany_Optional3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l3 => l3.OneToOne_Required_FK3), + new ExpectedInclude(l3 => l3.OneToMany_Optional3))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_with_Include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l3 => l3.OneToOne_Required_FK_Inverse3.OneToMany_Required_Inverse2) .Select(l3 => l3.OneToOne_Required_FK_Inverse3), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Required_Inverse2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_with_Include_ThenInclude(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l3 => l3.OneToMany_Required_Inverse3), - new ExpectedInclude(l2 => l2.OneToMany_Optional_Inverse2, "OneToMany_Required_Inverse3") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l4 => l4.OneToOne_Required_FK_Inverse4.OneToMany_Required_Inverse3) .ThenInclude(l2 => l2.OneToMany_Optional_Inverse2) .Select(l4 => l4.OneToOne_Required_FK_Inverse4), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l3 => l3.OneToMany_Required_Inverse3), + new ExpectedInclude(l2 => l2.OneToMany_Optional_Inverse2, "OneToMany_Required_Inverse3"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_Include_ThenInclude(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2), - new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToMany_Optional2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3) .Select(l1 => l1.OneToOne_Optional_FK1), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2), + new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToMany_Optional2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_optional_navigation_with_Include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2.OneToMany_Optional3) .Select(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional3))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_optional_navigation_with_string_based_Include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include("OneToOne_Optional_FK1.OneToOne_Optional_PK2.OneToMany_Optional3") .Select(l1 => l1.OneToOne_Optional_FK1) .Select(l2 => l2.OneToOne_Optional_PK2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional3))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_order_by_and_Include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) @@ -1041,13 +908,11 @@ public virtual Task Optional_navigation_with_order_by_and_Include(bool async) .OrderBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_Include_and_order(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) @@ -1055,13 +920,11 @@ public virtual Task Optional_navigation_with_Include_and_order(bool async) .OrderBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_order_by_and_Include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) @@ -1069,13 +932,11 @@ public virtual Task SelectMany_with_order_by_and_Include(bool async) .Include(l2 => l2.OneToMany_Optional2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include_and_order_by(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) @@ -1083,38 +944,38 @@ public virtual Task SelectMany_with_Include_and_order_by(bool async) .OrderBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_navigation_and_Distinct(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set().Include(l => l.OneToMany_Optional1) from l2 in l1.OneToMany_Optional1.Distinct() where l2 != null select l1, elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_navigation_and_Distinct_projecting_columns_including_join_key(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set().Include(l => l.OneToMany_Optional1) - from l2 in l1.OneToMany_Optional1.Select(x => new { x.Id, x.Name, FK = EF.Property(x, "OneToMany_Optional_Inverse2Id") }).Distinct() + from l2 in l1.OneToMany_Optional1.Select( + x => new + { + x.Id, + x.Name, + FK = EF.Property(x, "OneToMany_Optional_Inverse2Id") + }).Distinct() select l1, elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_member(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) @@ -1122,13 +983,11 @@ public virtual Task Include_collection_with_multiple_orderbys_member(bool async) .ThenBy(l2 => l2.Level1_Required_Id), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_property(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) @@ -1136,13 +995,11 @@ public virtual Task Include_collection_with_multiple_orderbys_property(bool asyn .ThenBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_methodcall(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) @@ -1150,13 +1007,11 @@ public virtual Task Include_collection_with_multiple_orderbys_methodcall(bool as .ThenBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_complex(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) @@ -1164,13 +1019,11 @@ public virtual Task Include_collection_with_multiple_orderbys_complex(bool async .ThenBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_complex_repeated(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) @@ -1178,7 +1031,6 @@ public virtual Task Include_collection_with_multiple_orderbys_complex_repeated(b .ThenBy(l2 => -l2.Level1_Required_Id).ThenBy(l2 => l2.Name), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -1200,21 +1052,18 @@ public virtual Task Include_collection_with_multiple_orderbys_complex_repeated_c [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_groupby_in_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_groupby_in_subquery_and_filter_before_groupby(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) @@ -1222,13 +1071,11 @@ public virtual Task Include_collection_with_groupby_in_subquery_and_filter_befor .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_groupby_in_subquery_and_filter_after_groupby(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) @@ -1236,13 +1083,11 @@ public virtual Task Include_collection_with_groupby_in_subquery_and_filter_after .Where(g => g.Key != "Foo") .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_collection_order_by_reference_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) @@ -1252,49 +1097,36 @@ public virtual Task Include_reference_collection_order_by_reference_navigation(b new ExpectedInclude(e => e.OneToOne_Optional_FK1), new ExpectedInclude(e => e.OneToMany_Optional2, "OneToOne_Optional_FK1")), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Include_after_Select(bool async) - { - var message = (await Assert.ThrowsAsync(() => AssertQuery( - async, - ss => ss.Set().Select(l1 => l1.OneToOne_Optional_FK1).Include(l2 => l2.OneToMany_Optional2)))).Message; - - Expression>> expr = l2 => l2.OneToMany_Optional2; - Assert.Equal(Diagnostics.CoreStrings.IncludeOnNonEntity(expr), message); - } + public virtual Task Include_after_Select(bool async) + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set().Select(l1 => l1.OneToOne_Optional_FK1).Include(l2 => l2.OneToMany_Optional2))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Include_after_SelectMany_and_reference_navigation(bool async) - { - var message = (await Assert.ThrowsAsync(() => - AssertQuery( + public virtual Task Include_after_SelectMany_and_reference_navigation(bool async) + => AssertIncludeOnNonEntity( + () => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Required1).Select(l2 => l2.OneToOne_Optional_FK2) - .Include(l3 => l3.OneToMany_Optional3)))).Message; - - Expression>> expr = l3 => l3.OneToMany_Optional3; - Assert.Equal(Diagnostics.CoreStrings.IncludeOnNonEntity(expr), message); - } + .Include(l3 => l3.OneToMany_Optional3))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_SelectMany(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Required1).Include(l2 => l2.OneToMany_Optional2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(x => x.OneToMany_Optional2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_multiple_SelectMany_and_reference_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Required1) @@ -1302,13 +1134,11 @@ public virtual Task Include_after_multiple_SelectMany_and_reference_navigation(b .Include(l3 => l3.OneToOne_Required_FK3.OneToMany_Required_Self4) .Select(l3 => l3.OneToOne_Required_FK3), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l4 => l4.OneToMany_Required_Self4))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_SelectMany_and_multiple_reference_navigations(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Required1) @@ -1316,66 +1146,48 @@ public virtual Task Include_after_SelectMany_and_multiple_reference_navigations( .Select(l2 => l2.OneToOne_Optional_FK2) .Select(l3 => l3.OneToOne_Required_FK3), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l4 => l4.OneToMany_Optional_Self4))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_followed_by_include_reference(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToMany_Optional1), - new ExpectedInclude(e => e.OneToOne_Optional_PK2, "OneToMany_Optional1"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToMany_Optional1), + new ExpectedInclude(e2 => e2.OneToOne_Optional_PK2, "OneToMany_Optional1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_followed_by_include_collection(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToOne_Optional_FK1), - new ExpectedInclude(e => e.OneToMany_Optional2, "OneToOne_Optional_FK1"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).ThenInclude(l2 => l2.OneToMany_Optional2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToOne_Optional_FK1), + new ExpectedInclude(e2 => e2.OneToMany_Optional2, "OneToOne_Optional_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_followed_by_projecting_the_included_collection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).Include(l1 => l1.OneToMany_Optional1).Select(l1 => l1.OneToMany_Optional1), assertOrder: true, elementAsserter: (e, a) => AssertCollection(e, a)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_and_ThenInclude_collections_followed_by_projecting_the_first_collection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.Id) @@ -1387,19 +1199,11 @@ public virtual Task Include_and_ThenInclude_collections_followed_by_projecting_t e, a, elementAsserter: (ee, aa) => AssertInclude(ee, aa, new ExpectedInclude(x => x.OneToOne_Optional_PK2)))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_and_another_navigation_chain_followed_by_projecting_the_first_collection(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToOne_Optional_PK2), - new ExpectedInclude(e => e.OneToOne_Optional_FK3, "OneToOne_Optional_PK2"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.Id) @@ -1411,98 +1215,78 @@ public virtual Task Include_collection_and_another_navigation_chain_followed_by_ elementAsserter: (e, a) => AssertCollection( e, a, - elementAsserter: (ee, aa) => AssertInclude(ee, aa, expectedIncludes))); - } + elementAsserter: (ee, aa) => AssertInclude( + ee, aa, new ExpectedInclude(e1 => e1.OneToOne_Optional_PK2), + new ExpectedInclude(e2 => e2.OneToOne_Optional_FK3, "OneToOne_Optional_PK2")))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_ThenInclude_two_references(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToMany_Optional1), - new ExpectedInclude(e => e.OneToOne_Optional_PK2, "OneToMany_Optional1"), - new ExpectedInclude(e => e.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .ThenInclude(l2 => l2.OneToOne_Optional_PK2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToMany_Optional1), + new ExpectedInclude(e2 => e2.OneToOne_Optional_PK2, "OneToMany_Optional1"), + new ExpectedInclude(e3 => e3.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2"))); [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Include_collection_followed_by_complex_includes_and_projecting_the_included_collection(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToOne_Optional_PK2), - new ExpectedInclude(e => e.OneToOne_Optional_FK3, "OneToOne_Optional_PK2"), - new ExpectedInclude(e => e.OneToOne_Optional_FK2), - new ExpectedInclude(e => e.OneToMany_Optional3, "OneToOne_Optional_FK2"), - }; - - return AssertQuery( + [MemberData(nameof(IsAsyncData))] + public virtual Task Include_collection_followed_by_complex_includes_and_projecting_the_included_collection(bool async) + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.Id) - .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2).ThenInclude(l3 => l3.OneToOne_Optional_FK3) - .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_FK2).ThenInclude(l3 => l3.OneToMany_Optional3) + .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2) + .ThenInclude(l3 => l3.OneToOne_Optional_FK3) + .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_FK2) + .ThenInclude(l3 => l3.OneToMany_Optional3) .Select(l1 => l1.OneToMany_Optional1), assertOrder: true, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToOne_Optional_PK2), + new ExpectedInclude(e2 => e2.OneToOne_Optional_FK3, "OneToOne_Optional_PK2"), + new ExpectedInclude(e3 => e3.OneToOne_Optional_FK2), + new ExpectedInclude(e4 => e4.OneToMany_Optional3, "OneToOne_Optional_FK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_multiple(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToMany_Optional1), - new ExpectedInclude(e => e.OneToOne_Optional_PK2, "OneToMany_Optional1"), - new ExpectedInclude(e => e.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2"), - new ExpectedInclude(e => e.OneToOne_Optional_FK2, "OneToMany_Optional1"), - new ExpectedInclude(e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToOne_Optional_FK2"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() - .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2).ThenInclude(l3 => l3.OneToOne_Optional_FK3) - .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_FK2).ThenInclude(l3 => l3.OneToMany_Optional3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2) + .ThenInclude(l3 => l3.OneToOne_Optional_FK3) + .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_FK2) + .ThenInclude(l3 => l3.OneToMany_Optional3), + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToMany_Optional1), + new ExpectedInclude(e2 => e2.OneToOne_Optional_PK2, "OneToMany_Optional1"), + new ExpectedInclude(e3 => e3.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2"), + new ExpectedInclude(e4 => e4.OneToOne_Optional_FK2, "OneToMany_Optional1"), + new ExpectedInclude(e5 => e5.OneToMany_Optional3, "OneToMany_Optional1.OneToOne_Optional_FK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_ThenInclude_ThenInclude_followed_by_two_nested_selects(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.Id) - .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2).ThenInclude(l3 => l3.OneToOne_Optional_FK3) + .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2) + .ThenInclude(l3 => l3.OneToOne_Optional_FK3) .Select(l1 => l1.OneToMany_Optional1.Select(l2 => l2.OneToOne_Optional_PK2)), assertOrder: true, - elementAsserter: (e, a) => AssertCollection(e, a, elementAsserter: (ee, aa) => AssertInclude(ee, aa, new ExpectedInclude(x => x.OneToOne_Optional_FK3)))); - } + elementAsserter: (e, a) => AssertCollection( + e, a, elementAsserter: (ee, aa) => AssertInclude(ee, aa, new ExpectedInclude(x => x.OneToOne_Optional_FK3)))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_ThenInclude_reference_followed_by_projection_into_anonmous_type(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToMany_Optional1), - new ExpectedInclude(e => e.OneToOne_Optional_PK2, "OneToMany_Optional1"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.Id) @@ -1511,40 +1295,34 @@ public virtual Task Include_collection_ThenInclude_reference_followed_by_project assertOrder: true, elementAsserter: (e, a) => { - AssertInclude(e.l1, a.l1, expectedIncludes); + AssertInclude( + e.l1, a.l1, new ExpectedInclude(e1 => e1.OneToMany_Optional1), + new ExpectedInclude(e2 => e2.OneToOne_Optional_PK2, "OneToMany_Optional1")); AssertCollection( e.OneToMany_Optional1, a.OneToMany_Optional1, elementAsserter: (ee, aa) => AssertInclude(ee, aa, new ExpectedInclude(e => e.OneToOne_Optional_PK2))); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_multiple_with_filter(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToMany_Optional1), - new ExpectedInclude(e => e.OneToOne_Optional_PK2, "OneToMany_Optional1"), - new ExpectedInclude(e => e.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .ThenInclude(l2 => l2.OneToOne_Optional_PK2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3) .Where(l1 => l1.OneToMany_Optional1.Where(l2 => l2.OneToOne_Optional_PK2.Name != "Foo").Count() > 0), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToMany_Optional1), + new ExpectedInclude(e2 => e2.OneToOne_Optional_PK2, "OneToMany_Optional1"), + new ExpectedInclude(e3 => e3.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Including_reference_navigation_and_projecting_collection_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Required_FK1) @@ -1556,7 +1334,6 @@ public virtual Task Including_reference_navigation_and_projecting_collection_nav OneToOne_Required_FK1 = e.OneToOne_Required_FK1, OneToMany_Required1 = e.OneToMany_Required1 })); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -1576,8 +1353,7 @@ from l2 in l2s.DefaultIfEmpty() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_Where(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.Where(l2 => l2.Id > 5)), elementAsserter: (e, a) => AssertInclude( @@ -1585,13 +1361,11 @@ public virtual Task Filtered_include_basic_Where(bool async) new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.Where(l2 => l2.Id > 5)))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_OrderBy(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name)), elementAsserter: (e, a) => AssertInclude( @@ -1600,13 +1374,11 @@ public virtual Task Filtered_include_OrderBy(bool async) e => e.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Name), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_ThenInclude_OrderBy(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToMany_Optional2.OrderBy(x => x.Name)), elementAsserter: (e, a) => AssertInclude( @@ -1617,13 +1389,11 @@ public virtual Task Filtered_ThenInclude_OrderBy(bool async) "OneToMany_Optional1", includeFilter: x => x.OrderBy(x => x.Name), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_ThenInclude_OrderBy(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name)) @@ -1639,13 +1409,11 @@ public virtual Task Filtered_include_ThenInclude_OrderBy(bool async) "OneToMany_Optional1", includeFilter: x => x.OrderByDescending(x => x.Name), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_OrderBy_Take(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name).Take(3)), elementAsserter: (e, a) => AssertInclude( @@ -1654,13 +1422,11 @@ public virtual Task Filtered_include_basic_OrderBy_Take(bool async) e => e.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Name).Take(3), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_OrderBy_Skip(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name).Skip(1)), elementAsserter: (e, a) => AssertInclude( @@ -1669,13 +1435,11 @@ public virtual Task Filtered_include_basic_OrderBy_Skip(bool async) e => e.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Name).Skip(1), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_OrderBy_Skip_Take(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name).Skip(1).Take(3)), elementAsserter: (e, a) => AssertInclude( @@ -1684,13 +1448,11 @@ public virtual Task Filtered_include_basic_OrderBy_Skip_Take(bool async) e => e.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Name).Skip(1).Take(3), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_Skip_without_OrderBy(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.Skip(1)), elementSorter: e => e.Id, @@ -1699,13 +1461,11 @@ public virtual Task Filtered_include_Skip_without_OrderBy(bool async) AssertEqual(e, a); Assert.Equal(Math.Max(e.OneToMany_Optional1.Count - 1, 0), a.OneToMany_Optional1?.Count); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_Take_without_OrderBy(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.Take(1)), elementSorter: e => e.Id, @@ -1714,13 +1474,11 @@ public virtual Task Filtered_include_Take_without_OrderBy(bool async) AssertEqual(e, a); Assert.Equal(e.OneToMany_Optional1.Any() ? 1 : 0, a.OneToMany_Optional1?.Count); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_on_ThenInclude(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) @@ -1733,13 +1491,11 @@ public virtual Task Filtered_include_on_ThenInclude(bool async) "OneToOne_Optional_FK1", x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_after_reference_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include( @@ -1753,13 +1509,11 @@ public virtual Task Filtered_include_after_reference_navigation(bool async) "OneToOne_Optional_FK1", x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_after_different_filtered_include_same_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Take(3)) @@ -1774,13 +1528,11 @@ public virtual Task Filtered_include_after_different_filtered_include_same_level e => e.OneToMany_Required1, includeFilter: x => x.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_after_different_filtered_include_different_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Take(3)) @@ -1796,40 +1548,46 @@ public virtual Task Filtered_include_after_different_filtered_include_different_ "OneToMany_Optional1", includeFilter: x => x.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual async Task Filtered_include_different_filter_set_on_same_navigation_twice(bool async) - { - var message = (await Assert.ThrowsAsync( + => Assert.Equal( + CoreStrings.MultipleFilteredIncludesOnSameNavigation( + "navigation .Where(x => x.Name != \"Bar\") .OrderByDescending(x => x.Name) .Take(3)", + "navigation .Where(x => x.Name != \"Foo\") .OrderBy(x => x.Id) .Take(3)") + .Replace("\r", "").Replace("\n", ""), + (await Assert.ThrowsAsync( () => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)) .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Take(3))))) - .Message; - } + .Message + .Replace("\r", "").Replace("\n", "")); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual async Task Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(bool async) - { - var message = (await Assert.ThrowsAsync( + => Assert.Equal( + CoreStrings.MultipleFilteredIncludesOnSameNavigation( + "navigation .Where(x => x.Name != \"Bar\")", + "navigation .Where(x => x.Name != \"Foo\")") + .Replace("\r", "").Replace("\n", ""), + (await Assert.ThrowsAsync( () => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo")).ThenInclude(l2 => l2.OneToMany_Optional2) .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Bar")) .ThenInclude(l2 => l2.OneToOne_Required_FK2)))) - .Message; - } + .Message + .Replace("\r", "").Replace("\n", "")); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_same_filter_set_on_same_navigation_twice(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderByDescending(x => x.Id).Take(2)) @@ -1840,13 +1598,11 @@ public virtual Task Filtered_include_same_filter_set_on_same_navigation_twice(bo e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderByDescending(x => x.Id).Take(2), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)) @@ -1861,14 +1617,12 @@ public virtual Task Filtered_include_same_filter_set_on_same_navigation_twice_fo assertOrder: true), new ExpectedInclude(e => e.OneToMany_Optional2), new ExpectedInclude(e => e.OneToOne_Required_FK2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)) @@ -1882,13 +1636,11 @@ public virtual Task Filtered_include_multiple_multi_level_includes_with_first_le assertOrder: true), new ExpectedInclude(e => e.OneToMany_Optional2, "OneToMany_Optional1"), new ExpectedInclude(e => e.OneToOne_Required_FK2, "OneToMany_Optional1"))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_and_non_filtered_include_on_same_navigation1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) @@ -1899,13 +1651,11 @@ public virtual Task Filtered_include_and_non_filtered_include_on_same_navigation e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_and_non_filtered_include_on_same_navigation2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)) @@ -1916,13 +1666,11 @@ public virtual Task Filtered_include_and_non_filtered_include_on_same_navigation e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3), assertOrder: true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)) @@ -1939,13 +1687,11 @@ public virtual Task Filtered_include_and_non_filtered_include_followed_by_then_i e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToOne_Optional_PK2", includeFilter: x => x.Where(x => x.Id > 1)))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_complex_three_level_with_middle_having_filter1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) @@ -1964,13 +1710,11 @@ public virtual Task Filtered_include_complex_three_level_with_middle_having_filt assertOrder: true), new ExpectedInclude(e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToMany_Optional2"), new ExpectedInclude(e => e.OneToMany_Required3, "OneToMany_Optional1.OneToMany_Optional2"))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_complex_three_level_with_middle_having_filter2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) @@ -1988,7 +1732,6 @@ public virtual Task Filtered_include_complex_three_level_with_middle_having_filt assertOrder: true), new ExpectedInclude(e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToMany_Optional2"), new ExpectedInclude(e => e.OneToMany_Required3, "OneToMany_Optional1.OneToMany_Optional2"))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -2011,8 +1754,7 @@ public virtual Task Filtered_include_variable_used_inside_filter(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_context_accessed_inside_filter(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => ss.Set().Count() > 7).OrderBy(x => x.Id).Take(3)), @@ -2022,48 +1764,45 @@ public virtual Task Filtered_include_context_accessed_inside_filter(bool async) new ExpectedFilteredInclude( x => x.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Id).Take(3)))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_context_accessed_inside_filter_correlated(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() - .Include(l1 => l1.OneToMany_Optional1.Where(x => ss.Set().Count(xx => xx.Id != x.Id) > 1).OrderBy(x => x.Id).Take(3)), + .Include( + l1 => l1.OneToMany_Optional1.Where(x => ss.Set().Count(xx => xx.Id != x.Id) > 1).OrderBy(x => x.Id) + .Take(3)), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedFilteredInclude( x => x.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Id).Take(3)))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Filtered_include_include_parameter_used_inside_filter_throws(bool async) - { - await Assert.ThrowsAsync( + public virtual Task Filtered_include_include_parameter_used_inside_filter_throws(bool async) + => AssertInvalidMaterializationType( () => AssertQuery( async, ss => ss.Set() - .Select(l1 => ss.Set().Include(l2 => l2.OneToMany_Optional2.Where(x => x.Id != l2.Id))))); - } + .Select(l1 => ss.Set().Include(l2 => l2.OneToMany_Optional2.Where(x => x.Id != l2.Id)))), + "IEnumerable"); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_outer_parameter_used_inside_filter(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select( - l1 => new - { - l1.Id, - FullInclude = ss.Set().Include(l2 => l2.OneToMany_Optional2).ToList(), - FilteredInclude = ss.Set().Include(l2 => l2.OneToMany_Optional2.Where(x => x.Id != l1.Id)).ToList() - }), + l1 => new + { + l1.Id, + FullInclude = ss.Set().Include(l2 => l2.OneToMany_Optional2).ToList(), + FilteredInclude = ss.Set().Include(l2 => l2.OneToMany_Optional2.Where(x => x.Id != l1.Id)).ToList() + }), elementSorter: e => e.Id, elementAsserter: (e, a) => { @@ -2076,7 +1815,6 @@ public virtual Task Filtered_include_outer_parameter_used_inside_filter(bool asy x => x.OneToMany_Optional2, includeFilter: x => x.Where(x => x.Id != e.Id))); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -2095,30 +1833,29 @@ public virtual async Task Filtered_include_is_considered_loaded(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual async Task Filtered_include_with_Distinct_throws(bool async) - { - var message = (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.Distinct())))).Message; - } + => Assert.Equal( + CoreStrings.InvalidIncludeExpression("l1.OneToMany_Optional1.AsQueryable().Distinct()"), + (await Assert.ThrowsAsync( + () => AssertQuery( + async, + ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.Distinct())))).Message); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual async Task Filtered_include_calling_methods_directly_on_parameter_throws(bool async) - { - var message = (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => ss.Set() - .Include(l1 => l1.OneToMany_Optional1) - .ThenInclude(l2 => l2.AsQueryable().Where(xx => xx.Id != 42))))).Message; - } + => Assert.Equal( + CoreStrings.InvalidIncludeExpression("l2.AsQueryable().Where(xx => (xx.Id != 42))"), + (await Assert.ThrowsAsync( + () => AssertQuery( + async, + ss => ss.Set() + .Include(l1 => l1.OneToMany_Optional1) + .ThenInclude(l2 => l2.AsQueryable().Where(xx => xx.Id != 42))))).Message); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_Take_with_another_Take_on_top_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.OrderByDescending(x => x.Name).Take(4)) @@ -2133,13 +1870,11 @@ public virtual Task Filtered_include_Take_with_another_Take_on_top_level(bool as x => x.OneToMany_Optional1, includeFilter: x => x.OrderByDescending(xx => xx.Name).Take(4)), new ExpectedInclude(x => x.OneToOne_Optional_FK2, "OneToMany_Optional1"))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_Skip_Take_with_another_Skip_Take_on_top_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.OrderByDescending(x => x.Name).Skip(2).Take(4)) @@ -2155,14 +1890,11 @@ public virtual Task Filtered_include_Skip_Take_with_another_Skip_Take_on_top_lev x => x.OneToMany_Optional1, includeFilter: x => x.OrderByDescending(xx => xx.Name).Skip(2).Take(4)), new ExpectedInclude(x => x.OneToOne_Optional_FK2, "OneToMany_Optional1"))); - } - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) - { - return AssertFirstOrDefault( + => AssertFirstOrDefault( async, ss => ss.Set() .OrderBy(l1 => l1.Id) @@ -2175,13 +1907,11 @@ public virtual Task Filtered_include_with_Take_without_order_by_followed_by_Then x => x.OneToMany_Optional1, includeFilter: x => x.Take(40)), new ExpectedInclude(x => x.OneToOne_Optional_FK2, "OneToMany_Optional1"))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.Id) @@ -2196,13 +1926,11 @@ public virtual Task Filtered_include_with_Take_without_order_by_followed_by_Then x => x.OneToMany_Optional1, includeFilter: x => x.Take(40)), new ExpectedInclude(x => x.OneToOne_Optional_FK2, "OneToMany_Optional1"))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Projecting_collection_with_FirstOrDefault(bool async) - { - return AssertFirstOrDefault( + => AssertFirstOrDefault( async, ss => ss.Set() .Select(e => new { e.Id, Level2s = e.OneToMany_Optional1.ToList() }), @@ -2212,204 +1940,154 @@ public virtual Task Projecting_collection_with_FirstOrDefault(bool async) Assert.Equal(e.Id, a.Id); AssertCollection(e.Level2s, a.Level2s); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_on_grouping_element(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1) - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1) }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); AssertCollection(e.Level1s, a.Level1s); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Take_on_grouping_element(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderByDescending(e => e.Name).Take(10) - }), + .Select(g => new { g.Key, Level1s = g.OrderByDescending(e => e.Name).Take(10) }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); AssertCollection(e.Level1s, a.Level1s); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_on_grouping_element(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); AssertCollection(e.Level1s, a.Level1s); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_Distinct_on_grouping_element(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5).Distinct() - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5).Distinct() }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); AssertCollection(e.Level1s, a.Level1s); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_ToList_on_grouping_element(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5).ToList() - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5).ToList() }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); AssertCollection(e.Level1s, a.Level1s); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_on_grouping_element_into_non_entity(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5).Select(l1 => new { l1.Name }) - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5).Select(l1 => new { l1.Name }) }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); AssertCollection(e.Level1s, a.Level1s, ordered: true); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_on_grouping_element_with_collection_include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); - AssertCollection(e.Level1s, a.Level1s, + AssertCollection( + e.Level1s, a.Level1s, elementAsserter: (ee, aa) => AssertInclude(ee, aa, new ExpectedInclude(l => l.OneToMany_Optional1))); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_on_grouping_element_with_reference_include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) - }), + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) }), elementSorter: e => e.Key, elementAsserter: (e, a) => { AssertEqual(e.Key, a.Key); - AssertCollection(e.Level1s, a.Level1s, + AssertCollection( + e.Level1s, a.Level1s, elementAsserter: (ee, aa) => AssertInclude(ee, aa, new ExpectedInclude(l => l.OneToOne_Optional_FK1))); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Skip_Take_on_grouping_element_inside_collection_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() - .Select(l1 => new - { - l1.Id, - group = ss.Set() - .Where(l => l.Name == l1.Name) - .GroupBy(l => l.Date) - .Select(g => new - { - g.Key, - Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) - }).ToList() - }), + .Select( + l1 => new + { + l1.Id, + group = ss.Set() + .Where(l => l.Name == l1.Name) + .GroupBy(l => l.Date) + .Select(g => new { g.Key, Level1s = g.OrderBy(e => e.Name).Skip(1).Take(5) }).ToList() + }), elementSorter: e => e.Id, elementAsserter: (e, a) => { AssertEqual(e.Id, a.Id); - AssertCollection(e.group, a.group, + AssertCollection( + e.group, a.group, elementSorter: i => i.Key, elementAsserter: (ee, aa) => { @@ -2417,79 +2095,65 @@ public virtual Task Skip_Take_on_grouping_element_inside_collection_projection(b AssertCollection(ee.Level1s, aa.Level1s); }); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_over_conditional_null_source(bool async) - { - return AssertTranslationFailed(() => AssertQueryScalar( - async, - ss => ss.Set() - .SelectMany(l2 => l2.Id == 1 - ? l2.OneToMany_Required_Inverse2.OneToMany_Optional1.Select(e => e.Id) - : null))); - } + => AssertTranslationFailed( + () => AssertQueryScalar( + async, + ss => ss.Set() + .SelectMany( + l2 => l2.Id == 1 + ? l2.OneToMany_Required_Inverse2.OneToMany_Optional1.Select(e => e.Id) + : null))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_over_conditional_empty_source(bool async) - { - return AssertTranslationFailed(() => AssertQueryScalar( - async, - ss => ss.Set() - .SelectMany(l2 => l2.Id == 1 - ? l2.OneToMany_Required_Inverse2.OneToMany_Optional1.Select(e => e.Id) - : Enumerable.Empty()))); - } + => AssertTranslationFailed( + () => AssertQueryScalar( + async, + ss => ss.Set() + .SelectMany( + l2 => l2.Id == 1 + ? l2.OneToMany_Required_Inverse2.OneToMany_Optional1.Select(e => e.Id) + : Enumerable.Empty()))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_partially_added_before_Where_and_then_build_upon(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToOne_Optional_FK1.OneToMany_Optional2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) .Where(l1 => l1.OneToOne_Optional_PK1.Id < 3 || l1.OneToOne_Optional_FK1.Id > 8) .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToOne_Optional_FK1.OneToMany_Optional2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_partially_added_before_Where_and_then_build_upon_with_filtered_include(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToOne_Optional_FK1.OneToMany_Optional2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.OrderBy(x => x.Id).Take(3)) .Where(l1 => l1.OneToOne_Optional_PK1.Id < 3 || l1.OneToOne_Optional_FK1.Id > 8) .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Required2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToOne_Optional_FK1.OneToMany_Optional2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Take_on_correlated_collection_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select(l1 => new { l1.Id, Collection = l1.OneToMany_Optional1.Take(50) }), elementSorter: e => e.Id, @@ -2498,36 +2162,34 @@ public virtual Task Take_on_correlated_collection_in_projection(bool async) AssertEqual(e.Id, a.Id); AssertCollection(e.Collection, a.Collection); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task FirstOrDefault_with_predicate_on_correlated_collection_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, - ss => ss.Set().Select(l1 => new - { - l1.Id, - Element = l1.OneToMany_Optional1.FirstOrDefault(l2 => l2.Id == l1.Id) - }), + ss => ss.Set().Select(l1 => new { l1.Id, Element = l1.OneToMany_Optional1.FirstOrDefault(l2 => l2.Id == l1.Id) }), elementSorter: e => e.Id, elementAsserter: (e, a) => { AssertEqual(e.Id, a.Id); AssertEqual(e.Element, a.Element); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) - { - return AssertQuery( + public virtual Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) + => AssertQuery( async, ss => from l1 in ss.Set() from l2 in ss.Set().Where(x => x.Level1_Required_Id == l1.Id * 2 || x.Name.Length == x.Id).DefaultIfEmpty() - select new { Root = l1, Element = l2, Collection = l1.OneToMany_Optional1 }, + select new + { + Root = l1, + Element = l2, + Collection = l1.OneToMany_Optional1 + }, elementSorter: e => (e.Root.Id, e.Element.Id), elementAsserter: (e, a) => { @@ -2535,36 +2197,36 @@ from l2 in ss.Set().Where(x => x.Level1_Required_Id == l1.Id * 2 || x.Na AssertEqual(e.Element, a.Element); AssertCollection(e.Collection, a.Collection); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_query_issue_21665(bool async) - { - return AssertFirstOrDefault( + => AssertFirstOrDefault( async, ss => ss.Set() .OrderBy(l1 => l1.Name) - .Select(l1 => new - { - Level1 = l1, - Level2Name = l1.OneToOne_Optional_FK1.Name, - ChildCount = l1.OneToMany_Optional_Self1.Count, - Level2Count = l1.OneToMany_Optional1.Count(), - IsLevel2There = l1.OneToMany_Optional1.Any(l2 => l2.Id == 2), - Children = l1.OneToMany_Optional_Self1 - .OrderBy(e => e.Name) - .Skip(1) - .Take(5) - .Select(lc1 => new - { - Level1 = lc1, - ChildCount = lc1.OneToMany_Optional_Self1.Count, - Level2Name = lc1.OneToOne_Optional_FK1.Name, - Level2Count = lc1.OneToMany_Optional1.Count(), - IsLevel2There = lc1.OneToMany_Optional1.Any(l2 => l2.Id == 2) - }) - }), + .Select( + l1 => new + { + Level1 = l1, + Level2Name = l1.OneToOne_Optional_FK1.Name, + ChildCount = l1.OneToMany_Optional_Self1.Count, + Level2Count = l1.OneToMany_Optional1.Count(), + IsLevel2There = l1.OneToMany_Optional1.Any(l2 => l2.Id == 2), + Children = l1.OneToMany_Optional_Self1 + .OrderBy(e => e.Name) + .Skip(1) + .Take(5) + .Select( + lc1 => new + { + Level1 = lc1, + ChildCount = lc1.OneToMany_Optional_Self1.Count, + Level2Name = lc1.OneToOne_Optional_FK1.Name, + Level2Count = lc1.OneToMany_Optional1.Count(), + IsLevel2There = lc1.OneToMany_Optional1.Any(l2 => l2.Id == 2) + }) + }), e => e.Level1.Id == 2, asserter: (e, a) => { @@ -2573,7 +2235,8 @@ public virtual Task Complex_query_issue_21665(bool async) AssertEqual(e.ChildCount, a.ChildCount); AssertEqual(e.Level2Count, a.Level2Count); AssertEqual(e.IsLevel2There, a.IsLevel2There); - AssertCollection(e.Children, a.Children, ordered: true, + AssertCollection( + e.Children, a.Children, ordered: true, elementAsserter: (ee, aa) => { AssertEqual(ee.Level1, aa.Level1); @@ -2583,6 +2246,5 @@ public virtual Task Complex_query_issue_21665(bool async) AssertEqual(ee.IsLevel2There, aa.IsLevel2There); }); }); - } } } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsSharedTypeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsSharedTypeQueryTestBase.cs index 9472c67b4e8..b488cb41812 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsSharedTypeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsCollectionsSharedTypeQueryTestBase.cs @@ -1,12 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Xunit; namespace Microsoft.EntityFrameworkCore.Query { - public abstract class ComplexNavigationsCollectionsSharedTypeQueryTestBase : ComplexNavigationsCollectionsQueryTestBase + public abstract class + ComplexNavigationsCollectionsSharedTypeQueryTestBase : ComplexNavigationsCollectionsQueryTestBase where TFixture : ComplexNavigationsSharedTypeQueryFixtureBase, new() { protected ComplexNavigationsCollectionsSharedTypeQueryTestBase(TFixture fixture) @@ -14,55 +17,59 @@ protected ComplexNavigationsCollectionsSharedTypeQueryTestBase(TFixture fixture) { } - // Self-ref not supported - public override Task Multiple_complex_includes_self_ref(bool async) - => Task.CompletedTask; + public override async Task Multiple_complex_includes_self_ref(bool async) + => Assert.Equal( + CoreStrings.InvalidIncludeExpression("e.OneToOne_Optional_Self1"), + (await Assert.ThrowsAsync( + () => base.Multiple_complex_includes_self_ref(async))).Message); - [ConditionalTheory] - public override Task Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) - => Task.CompletedTask; + public override Task + Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) + => AssertTranslationFailed( + () => base + .Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top( + async)); - // include after select is not supported public override Task Include_collection_with_multiple_orderbys_complex(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_collection_with_multiple_orderbys_complex(async)); public override Task Include_collection_with_multiple_orderbys_complex_repeated(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_collection_with_multiple_orderbys_complex_repeated(async)); public override Task Include_collection_with_multiple_orderbys_complex_repeated_checked(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_collection_with_multiple_orderbys_complex_repeated_checked(async)); public override Task Include_collection_with_multiple_orderbys_member(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_collection_with_multiple_orderbys_member(async)); public override Task Include_collection_with_multiple_orderbys_methodcall(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_collection_with_multiple_orderbys_methodcall(async)); public override Task Include_collection_with_multiple_orderbys_property(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_collection_with_multiple_orderbys_property(async)); public override Task Include_inside_subquery(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Include_inside_subquery(async)); public override Task Filtered_include_outer_parameter_used_inside_filter(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Filtered_include_outer_parameter_used_inside_filter(async)); public override Task Include_after_multiple_SelectMany_and_reference_navigation(bool async) - => Task.CompletedTask; + => AssertInvalidIncludeExpression(() => base.Include_after_multiple_SelectMany_and_reference_navigation(async)); public override Task Include_after_SelectMany_and_multiple_reference_navigations(bool async) - => Task.CompletedTask; + => AssertInvalidIncludeExpression(() => base.Include_after_SelectMany_and_multiple_reference_navigations(async)); public override Task Required_navigation_with_Include(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Required_navigation_with_Include(async)); public override Task Required_navigation_with_Include_ThenInclude(bool async) - => Task.CompletedTask; + => AssertIncludeOnNonEntity(() => base.Required_navigation_with_Include_ThenInclude(async)); - // Navigations used are not mapped in shared type. public override Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async) - => Task.CompletedTask; + => AssertTranslationFailed(() => base.SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(async)); - public override Task Complex_query_issue_21665(bool async) => Task.CompletedTask; + public override Task Complex_query_issue_21665(bool async) + => AssertTranslationFailed(() => base.Complex_query_issue_21665(async)); } } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index 9f08503a80e..8612ee1dd9e 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -5,25 +5,11 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Reflection; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; -// ReSharper disable ConvertClosureToMethodGroup -// ReSharper disable PossibleUnintendedReferenceComparison -// ReSharper disable ArgumentsStyleLiteral -// ReSharper disable PossibleMultipleEnumeration -// ReSharper disable UnusedVariable -// ReSharper disable EqualExpressionComparison -// ReSharper disable AccessToDisposedClosure -// ReSharper disable StringStartsWithIsCultureSpecific -// ReSharper disable InconsistentNaming -// ReSharper disable MergeConditionalExpression -// ReSharper disable ReplaceWithSingleCallToSingle -// ReSharper disable ReturnValueOfPureMethodIsNotUsed -// ReSharper disable ConvertToExpressionBodyWhenPossible #pragma warning disable RCS1155 // Use StringComparison when comparing strings. namespace Microsoft.EntityFrameworkCore.Query { @@ -41,106 +27,81 @@ protected ComplexNavigationsQueryTestBase(TFixture fixture) protected override Expression RewriteExpectedQueryExpression(Expression expectedQueryExpression) => new ExpectedQueryRewritingVisitor(Fixture.GetShadowPropertyMappings()).Visit(expectedQueryExpression); - private MemberInfo GetMemberInfo(Type sourceType, string name) - => sourceType.GetMember(name).Single(); - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Entity_equality_empty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => l.OneToOne_Optional_FK1 == new Level2())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_when_sentinel_ef_property(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(l.OneToOne_Optional_FK1, "Id") == 0)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(l.OneToOne_Required_FK1, "Id") > 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_required2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(l.OneToOne_Required_FK_Inverse2, "Id") > 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_nested(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(EF.Property(l, "OneToOne_Required_FK1"), "Id") == 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_nested2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(EF.Property(l, "OneToOne_Required_FK_Inverse2"), "Id") == 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_and_member_expression1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(l, "OneToOne_Required_FK1").Id == 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_and_member_expression2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(l.OneToOne_Required_FK1, "Id") == 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_using_property_method_and_member_expression3(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => EF.Property(l.OneToOne_Required_FK_Inverse2, "Id") == 7)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_navigation_converted_to_FK(bool async) - { - // TODO: remove this? it is testing optimization that is no longer there - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l => l.OneToOne_Required_FK_Inverse2 == new Level1 { Id = 1 }), ss => ss.Set().Where(l => l.OneToOne_Required_FK_Inverse2.Id == 1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_two_conditions_on_same_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where( l => l.OneToOne_Required_FK1 == new Level2 { Id = 1 } @@ -148,13 +109,11 @@ public virtual Task Key_equality_two_conditions_on_same_navigation(bool async) ss => ss.Set().Where( l => l.OneToOne_Required_FK1.Id == 1 || l.OneToOne_Required_FK1.Id == 2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Key_equality_two_conditions_on_same_navigation2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where( l => l.OneToOne_Required_FK_Inverse2 == new Level1 { Id = 1 } @@ -162,19 +121,20 @@ public virtual Task Key_equality_two_conditions_on_same_navigation2(bool async) ss => ss.Set().Where( l => l.OneToOne_Required_FK_Inverse2.Id == 1 || l.OneToOne_Required_FK_Inverse2.Id == 2)); - } - [ConditionalFact] - public virtual void Multi_level_include_with_short_circuiting() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Multi_level_include_with_short_circuiting(bool async) { using var context = CreateContext(); + var query = context.Fields .Include(x => x.Label.Globalizations) .ThenInclude(x => x.Language) .Include(x => x.Placeholder.Globalizations) .ThenInclude(x => x.Language); - var result = query.ToList().OrderBy(e => e.Name).ToList(); + var result = (async ? await query.ToListAsync() : query.ToList()).OrderBy(e => e.Name).ToList(); Assert.Equal(2, result.Count); Assert.Equal("Field1", result[0].Name); @@ -212,114 +172,93 @@ public virtual void Multi_level_include_with_short_circuiting() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_key_access_optional(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() join e2 in ss.Set() on e1.Id equals e2.OneToOne_Optional_FK_Inverse2.Id select new { Id1 = e1.Id, Id2 = e2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_key_access_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() join e2 in ss.Set() on e1.Id equals e2.OneToOne_Required_FK_Inverse2.Id select new { Id1 = e1.Id, Id2 = e2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigation_key_access_optional_comparison(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from e2 in ss.Set() where e2.OneToOne_Optional_PK_Inverse2.Id > 5 select e2.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Simple_level1_include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Required_PK1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Simple_level1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set()); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Simple_level1_level2_include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Simple_level1_level2_GroupBy_Count(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().GroupBy( l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.Name) .Select(g => g.Count())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Simple_level1_level2_GroupBy_Having_Count(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().GroupBy( l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.Name, l1 => new { Id = (int?)l1.OneToOne_Required_PK1.Id ?? 0 }) .Where(g => g.Min(l1 => l1.Id) > 0) .Select(g => g.Count())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Simple_level1_level2_level3_include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.OneToOne_Required_PK3)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigation_key_access_required_comparison(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from e2 in ss.Set() where e2.OneToOne_Required_PK_Inverse2.Id > 5 select e2.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigation_inside_method_call_translated_to_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() where e1.OneToOne_Required_FK1.Name.StartsWith("L") @@ -327,24 +266,20 @@ where e1.OneToOne_Required_FK1.Name.StartsWith("L") ss => from e1 in ss.Set() where e1.OneToOne_Required_FK1.Name.MaybeScalar(x => x.StartsWith("L")) == true select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigation_inside_method_call_translated_to_join2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e3 in ss.Set() where e3.OneToOne_Required_FK_Inverse3.Name.StartsWith("L") select e3); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_inside_method_call_translated_to_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() where e1.OneToOne_Optional_FK1.Name.StartsWith("L") @@ -352,24 +287,20 @@ where e1.OneToOne_Optional_FK1.Name.StartsWith("L") ss => from e1 in ss.Set() where e1.OneToOne_Optional_FK1.Name.MaybeScalar(x => x.StartsWith("L")) == true select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_inside_property_method_translated_to_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() where EF.Property(EF.Property(e1, "OneToOne_Optional_FK1"), "Name") == "L2 01" select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_inside_nested_method_call_translated_to_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() where e1.OneToOne_Optional_FK1.Name.ToUpper().StartsWith("L") @@ -378,24 +309,20 @@ where e1.OneToOne_Optional_FK1.Name.ToUpper().StartsWith("L") where e1.OneToOne_Optional_FK1.Name.MaybeScalar(x => x.ToUpper().StartsWith("L")) == true select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Method_call_on_optional_navigation_translates_to_null_conditional_properly_for_arguments(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() where e1.OneToOne_Optional_FK1.Name.StartsWith(e1.OneToOne_Optional_FK1.Name) select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_inside_method_call_translated_to_join_keeps_original_nullability(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() @@ -405,13 +332,11 @@ from e1 in ss.Set() from e1 in ss.Set() where e1.OneToOne_Optional_FK1.MaybeScalar(x => x.Date.AddDays(10)) > new DateTime(2000, 2, 1) select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() @@ -421,14 +346,12 @@ from e1 in ss.Set() from e1 in ss.Set() where e1.OneToOne_Optional_FK1.MaybeScalar(x => x.Date.AddDays(10).AddDays(15).AddMonths(2)) > new DateTime(2000, 2, 1) select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability_also_for_arguments( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() @@ -438,61 +361,51 @@ from e1 in ss.Set() from e1 in ss.Set() where e1.OneToOne_Optional_FK1.MaybeScalar(x => x.Date.AddDays(15).AddDays(x.Id)) > new DateTime(2000, 2, 1) select e1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_in_outer_selector_translated_to_extra_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() join e2 in ss.Set() on e1.OneToOne_Optional_FK1.Id equals e2.Id select new { Id1 = e1.Id, Id2 = e2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_in_outer_selector_translated_to_extra_join_nested(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() join e3 in ss.Set() on e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id equals e3.Id select new { Id1 = e1.Id, Id3 = e3.Id }, e => (e.Id1, e.Id3)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_in_outer_selector_translated_to_extra_join_nested2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e3 in ss.Set() join e1 in ss.Set() on e3.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Id equals e1.Id select new { Id3 = e3.Id, Id1 = e1.Id }, e => (e.Id1, e.Id3)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_in_inner_selector(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e2 in ss.Set() join e1 in ss.Set() on e2.Id equals e1.OneToOne_Optional_FK1.Id select new { Id2 = e2.Id, Id1 = e1.Id }, e => (e.Id2, e.Id1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigations_in_inner_selector_translated_without_collision(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e2 in ss.Set() join e1 in ss.Set() on e2.Id equals e1.OneToOne_Optional_FK1.Id @@ -504,13 +417,11 @@ join e3 in ss.Set() on e2.Id equals e3.OneToOne_Optional_FK_Inverse3.Id Id3 = e3.Id }, e => (e.Id2, e.Id1, e.Id3)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_non_key_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e2 in ss.Set() @@ -523,13 +434,11 @@ join e1 in ss.Set() on e2.Name equals e1.OneToOne_Optional_FK1.Name Name1 = e1.Name }, e => (e.Id2, e.Name2, e.Id1, e.Name1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_with_orderby_on_inner_sequence_navigation_non_key_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e2 in ss.Set() @@ -542,49 +451,41 @@ join e1 in ss.Set().OrderBy(l1 => l1.Id) on e2.Name equals e1.OneToOne_O Name1 = e1.Name }, e => (e.Id2, e.Name2, e.Id1, e.Name1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_self_ref(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() join e2 in ss.Set() on e1.Id equals e2.OneToMany_Optional_Self_Inverse1.Id select new { Id1 = e1.Id, Id2 = e2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_nested(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e3 in ss.Set() join e1 in ss.Set() on e3.Id equals e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id select new { Id3 = e3.Id, Id1 = e1.Id }, e => (e.Id3, e.Id1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_nested2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e3 in ss.Set() join e1 in ss.Set().OrderBy(ll => ll.Id) on e3.Id equals e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id select new { Id3 = e3.Id, Id1 = e1.Id }, e => (e.Id3, e.Id1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_deeply_nested_non_key_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e4 in ss.Set() @@ -597,13 +498,11 @@ join e1 in ss.Set() on e4.Name equals e1.OneToOne_Required_FK1.OneToOne_ Name1 = e1.Name }, e => (e.Id4, e.Name4, e.Id1, e.Name1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_navigation_deeply_nested_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() @@ -617,13 +516,11 @@ join e4 in ss.Set() on e1.Name equals e4.OneToOne_Required_FK_Inverse4.O Name1 = e1.Name }, e => (e.Id4, e.Name4, e.Id1, e.Name1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_and_project_into_anonymous_type(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(e => e.OneToOne_Optional_FK1).Select(e => new { e.Id, entity = e }), elementSorter: e => e.Id, @@ -632,253 +529,203 @@ public virtual Task Include_reference_and_project_into_anonymous_type(bool async AssertInclude(e.entity, a.entity, new ExpectedInclude(ee => ee.OneToOne_Optional_FK1)); AssertEqual(e.Id, a.Id); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_nav_prop_reference_optional1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select(e => e.OneToOne_Optional_FK1.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_nav_prop_reference_optional1_via_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation select l2 == null ? null : l2.Name); -#pragma warning restore IDE0031 // Use null propagation - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_nav_prop_reference_optional2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Select(e => (int?)e.OneToOne_Optional_FK1.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_nav_prop_reference_optional2_via_DefaultIfEmpty(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.DefaultIfEmpty() select l2 == null ? null : (int?)l2.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_nav_prop_reference_optional3(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select(e => e.OneToOne_Optional_FK_Inverse2.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_nav_prop_reference_optional1(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set() .Where(e => e.OneToOne_Optional_FK1.Name == "L2 05" || e.OneToOne_Optional_FK1.Name == "L2 07") .Select(e => e.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_nav_prop_reference_optional1_via_DefaultIfEmpty(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() join l2Left in ss.Set() on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft from l2Left in groupJoinLeft.DefaultIfEmpty() join l2Right in ss.Set() on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight from l2Right in groupJoinRight.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) == "L2 07" -#pragma warning restore IDE0031 // Use null propagation select l1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_nav_prop_reference_optional2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set() .Where(e => e.OneToOne_Optional_FK1.Name == "L2 05" || e.OneToOne_Optional_FK1.Name != "L2 42") .Select(e => e.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_nav_prop_reference_optional2_via_DefaultIfEmpty(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() join l2Left in ss.Set() on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft from l2Left in groupJoinLeft.DefaultIfEmpty() join l2Right in ss.Set() on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight from l2Right in groupJoinRight.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) != "L2 42" -#pragma warning restore IDE0031 // Use null propagation select l1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_multiple_nav_prop_reference_optional(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Select(e => (int?)e.OneToOne_Optional_FK1.OneToOne_Optional_FK2.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_member_compared_to_value(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2.Name != "L3 05" select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_member_compared_to_null(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2.Name != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2 == null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() where l3.OneToOne_Optional_FK_Inverse3.OneToOne_Optional_FK_Inverse2 == null select l3); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null3(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where null != l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2 select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null4(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() where null != l3.OneToOne_Optional_FK_Inverse3.OneToOne_Optional_FK_Inverse2 select l3); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null5(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(e => e.OneToOne_Optional_FK1.OneToOne_Required_FK2.OneToOne_Required_FK3 == null)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_multiple_nav_prop_reference_required(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Select(e => (int?)e.OneToOne_Required_FK1.OneToOne_Required_FK2.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_multiple_nav_prop_reference_required2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Select(e => e.OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_multiple_nav_prop_optional_required(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() select (int?)l1.OneToOne_Optional_FK1.OneToOne_Required_FK2.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_multiple_nav_prop_optional_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.OneToOne_Optional_FK1.OneToOne_Required_FK2.Name != "L3 05" select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_comparison1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l11 in ss.Set() @@ -891,13 +738,11 @@ from l12 in ss.Set() where l11.Id == l12.Id select new { Id1 = l11.Id, Id2 = l12.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_comparison2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -910,13 +755,11 @@ from l2 in ss.Set() where l1.Id == l2.OneToOne_Optional_FK_Inverse2.Id select new { Id1 = l1.Id, Id2 = l2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_comparison3(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -929,13 +772,11 @@ from l2 in ss.Set() where l1.OneToOne_Optional_FK1.Id == l2.Id select new { Id1 = l1.Id, Id2 = l2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -943,47 +784,39 @@ from l2 in ss.Set() where l1.OneToOne_Optional_FK1.Name == "L2 01" || l2.OneToOne_Required_FK_Inverse2.Name != "Bar" select new { Id1 = (int?)l1.Id, Id2 = (int?)l2.Id }, e => (e.Id1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() where l1.OneToOne_Optional_FK1.OneToOne_Required_FK2.Name == "L3 05" || l1.OneToOne_Optional_FK1.Name != "L2 05" select l1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse3(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() where l1.OneToOne_Optional_FK1.Name != "L2 05" || l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Name == "L3 05" select l1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse4(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l3 in ss.Set() where l3.OneToOne_Optional_FK_Inverse3.Name != "L2 05" || l3.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Name == "L1 05" select l3.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_navigations_with_predicate_projected_into_anonymous_type(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where( @@ -991,13 +824,11 @@ public virtual Task Complex_navigations_with_predicate_projected_into_anonymous_ && e.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id != 7) .Select(e => new { e.Name, Id = (int?)e.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id }), elementSorter: e => (e.Name, e.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_navigations_with_predicate_projected_into_anonymous_type2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e in ss.Set() where e.OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2 @@ -1005,13 +836,11 @@ where e.OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2 && e.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Id != 7 select new { e.Name, Id = (int?)e.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Id }, e => (e.Name, e.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_projected_into_DTO(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select( e => new MyOuterDto @@ -1030,7 +859,6 @@ public virtual Task Optional_navigation_projected_into_DTO(bool async) Assert.Equal(e.Inner?.Id, a.Inner?.Id); Assert.Equal(e.Inner?.Name, a.Inner?.Name); }); - } public class MyOuterDto { @@ -1049,142 +877,117 @@ public class MyInnerDto [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task OrderBy_nav_prop_reference_optional(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().OrderBy(e => e.OneToOne_Optional_FK1.Name).ThenBy(e => e.Id).Select(e => e.Id), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation orderby l2 == null ? null : l2.Name, l1.Id -#pragma warning restore IDE0031 // Use null propagation select l1.Id, assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_Sum(bool async) - { - return AssertSum( + => AssertSum( async, ss => ss.Set(), ss => ss.Set(), actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id, expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_Min(bool async) - { - return AssertMin( + => AssertMin( async, ss => ss.Set(), ss => ss.Set(), actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id, expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_Max(bool async) - { - return AssertMax( + => AssertMax( async, ss => ss.Set(), ss => ss.Set(), actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id, expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_Average(bool async) - { - return AssertAverage( + => AssertAverage( async, ss => ss.Set(), ss => ss.Set(), actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id, expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_Average_with_identity_selector(bool async) - { - return AssertAverage( + => AssertAverage( async, ss => ss.Set().Select(e => (int?)e.OneToOne_Optional_FK1.Level1_Required_Id), selector: e => e); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_Average_without_selector(bool async) - { - return AssertAverage( + => AssertAverage( async, ss => ss.Set().Select(e => (int?)e.OneToOne_Optional_FK1.Level1_Required_Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(bool async) - { - return AssertSum( + => AssertSum( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.DefaultIfEmpty() select l2, selector: e => e == null ? 0 : e.Level1_Required_Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_optional_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set().Include(e => e.OneToOne_Optional_FK1) where l1.OneToOne_Optional_FK1.Name != "L2 05" select l1, elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_flattening_bug_4539(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() - join l1_Optional in ss.Set() on (int?)l1.Id equals l1_Optional.Level1_Optional_Id into grouping + join l1_Optional in ss.Set() on l1.Id equals l1_Optional.Level1_Optional_Id into grouping from l1_Optional in grouping.DefaultIfEmpty() from l2 in ss.Set() join l2_Required_Reverse in ss.Set() on l2.Level1_Required_Id equals l2_Required_Reverse.Id select new { l1_Optional, l2_Required_Reverse }, elementSorter: e => (e.l1_Optional?.Id, e.l2_Required_Reverse.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Query_source_materialization_bug_4547(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from e3 in ss.Set() join e1 in ss.Set() @@ -1195,7 +998,7 @@ join e1 in ss.Set() from subQuery2 in ss.Set() join subQuery3 in ss.Set() on - subQuery2 != null ? (int?)subQuery2.Id : null + subQuery2 != null ? subQuery2.Id : null equals subQuery3.Level2_Optional_Id into @@ -1205,225 +1008,183 @@ from subQuery3 in grouping.DefaultIfEmpty() select subQuery3 != null ? (int?)subQuery3.Id : null ).FirstOrDefault() select e1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Optional1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_and_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Optional1).Select(e => e.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_and_filter_before(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(e => e.Id == 1).SelectMany(l1 => l1.OneToMany_Optional1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_and_filter_after(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Optional1).Where(e => e.Id != 6)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_nested_navigation_property_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToOne_Required_FK1.OneToMany_Optional2), ss => ss.Set().SelectMany(l1 => l1.OneToOne_Required_FK1.OneToMany_Optional2 ?? new List())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_nested_navigation_property_optional_and_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2).Select(e => e.Name), ss => ss.Set().SelectMany(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2 ?? new List()) .Select(e => e.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_calls(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(e => e.OneToMany_Optional1).SelectMany(e => e.OneToMany_Optional2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_with_another_navigation_in_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Optional1.Select(l2 => l2.OneToOne_Optional_FK2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_navigation_property_to_collection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l1 => l1.OneToOne_Required_FK1.OneToMany_Optional2.Count > 0), ss => ss.Set().Where(l1 => l1.OneToOne_Required_FK1.OneToMany_Optional2.MaybeScalar(x => x.Count) > 0)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_navigation_property_to_collection2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l3 => l3.OneToOne_Required_FK_Inverse3.OneToMany_Optional2.Count > 0), ss => ss.Set().Where( l3 => l3.OneToOne_Required_FK_Inverse3.OneToMany_Optional2.MaybeScalar(x => x.Count) > 0)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_navigation_property_to_collection_of_original_entity_type(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l2 => l2.OneToMany_Required_Inverse2.OneToMany_Optional1.Count() > 0), ss => ss.Set().Where( l2 => l2.OneToMany_Required_Inverse2.OneToMany_Optional1.MaybeScalar(x => x.Count()) > 0)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_subquery_doesnt_project_unnecessary_columns_in_top_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => (from l1 in ss.Set() where ss.Set().Any(l2 => l2.Level1_Required_Id == l1.Id) select l1.Name).Distinct()); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_subquery_doesnt_project_unnecessary_columns_in_top_level_join(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from e1 in ss.Set() join e2 in ss.Set() on e1.Id equals e2.OneToOne_Optional_FK_Inverse2.Id where ss.Set().Any(l2 => l2.Level1_Required_Id == e1.Id) select new { Name1 = e1.Name, Id2 = e2.Id }, e => (e.Name1, e.Id2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_nested_subquery_doesnt_project_unnecessary_columns_in_top_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => (from l1 in ss.Set() where ss.Set().Any(l2 => ss.Set().Select(l3 => l2.Id).Any()) select l1.Name).Distinct()); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_nested_two_levels_up_subquery_doesnt_project_unnecessary_columns_in_top_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => (from l1 in ss.Set() where ss.Set().Any(l2 => ss.Set().Select(l3 => l1.Id).Any()) select l1.Name).Distinct() ); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_where_with_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Required1).Where(l2 => l2.OneToMany_Required2.Any())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l3 => l3.OneToOne_Required_FK_Inverse3.Id).Select(l3 => l3.OneToOne_Required_FK_Inverse3), elementAsserter: (e, a) => AssertEqual(e, a), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l3 => l3.OneToOne_Required_FK_Inverse3.Id) .Select(l3 => EF.Property(l3, "OneToOne_Required_FK_Inverse3")), elementAsserter: (e, a) => AssertEqual(e, a), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access3(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l3 => EF.Property(l3, "OneToOne_Required_FK_Inverse3").Id) .Select(l3 => l3.OneToOne_Required_FK_Inverse3), elementAsserter: (e, a) => AssertEqual(e, a), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Order_by_key_of_navigation_similar_to_projected_gets_optimized_into_FK_access(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() orderby l3.OneToOne_Required_FK_Inverse3.Id select l3.OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2, elementAsserter: (e, a) => AssertEqual(e, a), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Select(l3 => l3.OneToOne_Required_FK_Inverse3) @@ -1431,13 +1192,11 @@ public virtual Task Order_by_key_of_projected_navigation_doesnt_get_optimized_in .Take(10) .Select(l2 => l2.OneToOne_Required_FK_Inverse2.Name), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Order_by_key_of_anonymous_type_projected_navigation_doesnt_get_optimized_into_FK_access_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Select( @@ -1446,13 +1205,11 @@ public virtual Task Order_by_key_of_anonymous_type_projected_navigation_doesnt_g .Take(10) .Select(l2 => l2.OneToOne_Required_FK_Inverse3.Name), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_take_optional_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1) @@ -1460,26 +1217,22 @@ public virtual Task Optional_navigation_take_optional_navigation(bool async) .Take(10) .Select(l2 => l2.OneToOne_Optional_FK2.Name), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Projection_select_correct_table_from_subquery_when_materialization_is_not_required(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l2 => l2.OneToOne_Required_FK_Inverse2.Name == "L1 03") .OrderBy(l => l.Id) .Take(3) .Select(l2 => l2.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Projection_select_correct_table_with_anonymous_projection_in_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => (from l2 in ss.Set() join l1 in ss.Set() on l2.Level1_Required_Id equals l1.Id @@ -1490,13 +1243,11 @@ join l3 in ss.Set() on l1.Id equals l3.Level2_Required_Id .OrderBy(l => l.l1.Id) .Take(3) .Select(l => l.l2.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Projection_select_correct_table_in_subquery_when_materialization_is_not_required_in_multiple_joins(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => (from l2 in ss.Set() join l1 in ss.Set() on l2.Level1_Required_Id equals l1.Id @@ -1504,156 +1255,138 @@ join l3 in ss.Set() on l1.Id equals l3.Level2_Required_Id where l1.Name == "L1 03" where l3.Name == "L3 08" select l1).OrderBy(l1 => l1.Id).Take(3).Select(l1 => l1.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_predicate_on_optional_reference_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l1 => l1.OneToOne_Required_FK1.Name == "L2 03") .OrderBy(l1 => l1.Id) .Take(3) .Select(l1 => l1.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_string_based_Include1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include("OneToOne_Required_FK2"), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Required_FK2))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_string_based_Include2(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l2 => l2.OneToOne_Required_FK2), - new ExpectedInclude(l3 => l3.OneToOne_Required_FK3, "OneToOne_Required_FK2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include("OneToOne_Required_FK2.OneToOne_Required_FK3"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l2 => l2.OneToOne_Required_FK2), + new ExpectedInclude(l3 => l3.OneToOne_Required_FK3, "OneToOne_Required_FK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_with_string_based_Include(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .SelectMany(l1 => l1.OneToMany_Optional2) .Include("OneToOne_Required_FK3"), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToOne_Required_FK3))); - } - [ConditionalTheory(Skip = "Issue#16752")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigations_with_Include(bool async) - { - return AssertQuery( - async, - ss => ss.Set() - .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) - .Include(l2 => l2.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); - } + // Include after select. Issue #16752. + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set() + .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) + .Include(l2 => l2.OneToOne_Optional_FK2), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)))); - [ConditionalTheory(Skip = "Issue#16752")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigation_using_multiple_selects_with_Include(bool async) - { - return AssertQuery( - async, - ss => ss.Set() - .Select(l4 => l4.OneToOne_Required_FK_Inverse4) - .Select(l3 => l3.OneToOne_Required_FK_Inverse3) - .Include(l2 => l2.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); - } + // Include after select. Issue #16752. + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set() + .Select(l4 => l4.OneToOne_Required_FK_Inverse4) + .Select(l3 => l3.OneToOne_Required_FK_Inverse3) + .Include(l2 => l2.OneToOne_Optional_FK2), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)))); - [ConditionalTheory(Skip = "Issue#16752")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigation_with_string_based_Include(bool async) - { - return AssertQuery( - async, - ss => ss.Set() - .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) - .Include("OneToOne_Optional_FK2"), - elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); - } + // Include after select. Issue #16752. + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set() + .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) + .Include("OneToOne_Optional_FK2"), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)))); - [ConditionalTheory(Skip = "Issue#16752")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigation_using_multiple_selects_with_string_based_Include(bool async) - { - return AssertQuery( - async, - ss => ss.Set() - .Select(l4 => l4.OneToOne_Required_FK_Inverse4) - .Select(l3 => l3.OneToOne_Required_FK_Inverse3) - .Include("OneToOne_Optional_FK2"), - elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); - } + // Include after select. Issue #16752. + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set() + .Select(l4 => l4.OneToOne_Required_FK_Inverse4) + .Select(l3 => l3.OneToOne_Required_FK_Inverse3) + .Include("OneToOne_Optional_FK2"), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)))); - [ConditionalTheory(Skip = "Issue#16752")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_Include(bool async) - { - return AssertQuery( - async, - ss => ss.Set() - .Select(l1 => l1.OneToOne_Optional_FK1) - .Include(l2 => l2.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); - } + // Include after select. Issue #16752. + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set() + .Select(l1 => l1.OneToOne_Optional_FK1) + .Include(l2 => l2.OneToOne_Optional_FK2), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_navigation_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l2 in l1.OneToMany_Optional1.DefaultIfEmpty() where l2 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_navigation_filter_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l2 in l1.OneToMany_Optional1.Where(l => l.Id > 5).DefaultIfEmpty() where l2 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigation_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l3 in l1.OneToOne_Required_FK1.OneToMany_Optional2.DefaultIfEmpty() @@ -1663,13 +1396,11 @@ from l3 in l1.OneToOne_Required_FK1.OneToMany_Optional2.DefaultIfEmpty() from l3 in l1.OneToOne_Required_FK1.OneToMany_Optional2.DefaultIfEmpty() ?? new List() where l3 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigation_filter_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l3 in l1.OneToOne_Optional_FK1.OneToMany_Optional2.Where(l => l.Id > 5).DefaultIfEmpty() @@ -1679,13 +1410,11 @@ from l3 in l1.OneToOne_Optional_FK1.OneToMany_Optional2.Where(l => l.Id > 5).Def from l3 in l1.OneToOne_Optional_FK1.OneToMany_Optional2.Where(l => l.Id > 5).DefaultIfEmpty() where l3 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_required_navigation_filter_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l3 in l1.OneToOne_Required_FK1.OneToMany_Required2.Where(l => l.Id > 5).DefaultIfEmpty() @@ -1695,13 +1424,11 @@ from l3 in l1.OneToOne_Required_FK1.OneToMany_Required2.Where(l => l.Id > 5).Def from l3 in l1.OneToOne_Required_FK1.OneToMany_Required2.Where(l => l.Id > 5).DefaultIfEmpty() where l3 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set().SelectMany( @@ -1720,14 +1447,12 @@ equals l2.Level1_Optional_Id AssertEqual(e.l1, a.l1); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set().SelectMany( @@ -1741,14 +1466,12 @@ on l1.Id equals l2.Level1_Optional_Id AssertEqual(e.l1, a.l1); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set().SelectMany( l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Optional_FK_Inverse3.OneToMany_Required_Self2.DefaultIfEmpty()) @@ -1760,14 +1483,12 @@ join l1 in ss.Set() on l2.Level1_Optional_Id equals l1.Id AssertEqual(e.l2, a.l2); AssertEqual(e.l1, a.l1); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany3( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l4 in ss.Set().SelectMany( l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) @@ -1779,14 +1500,12 @@ join l2 in ss.Set() on l4.Id equals l2.Id AssertEqual(e.l4, a.l4); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany4( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l4 in ss.Set().SelectMany( l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) @@ -1799,13 +1518,11 @@ from l2 in grouping.DefaultIfEmpty() AssertEqual(e.l4, a.l4); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_joined_together(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l4 in ss.Set().SelectMany( l1 => l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToMany_Required3.DefaultIfEmpty()) @@ -1820,63 +1537,53 @@ on l4.Id equals l2.Id AssertEqual(e.l4, a.l4); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_followed_by_Select_required_navigation_using_same_navs( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set().SelectMany( l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToMany_Required2.DefaultIfEmpty()) select l3.OneToOne_Required_FK_Inverse3.OneToOne_Required_PK_Inverse2); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_followed_by_Select_required_navigation_using_different_navs( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set().SelectMany(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.DefaultIfEmpty()) select l3.OneToOne_Required_FK_Inverse3.OneToOne_Required_PK_Inverse2); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_with_navigation_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l2 in l1.OneToMany_Optional1 from l3 in l2.OneToMany_Optional2.Where(l => l.Id > 5).DefaultIfEmpty() where l3 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l2 in l1.OneToMany_Required1.Where(l => l.Id > 5).OrderBy(l => l.Id).Take(3).DefaultIfEmpty() where l2 != null select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_join_subquery_containing_filter_and_distinct(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -1888,13 +1595,11 @@ join l2 in ss.Set().Where(l => l.Id > 2).Distinct() on l1.Id equals l2.L AssertEqual(e.l1, a.l1); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_join_with_key_selector_being_a_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals ss.Set().Select(l => l.Id).OrderBy(l => l).FirstOrDefault() @@ -1905,25 +1610,21 @@ join l2 in ss.Set() on l1.Id equals ss.Set().Select(l => l.Id).O AssertEqual(e.l1, a.l1); AssertEqual(e.l2, a.l2); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Contains_with_subquery_optional_navigation_and_constant_item(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.Distinct().Select(l3 => l3.Id).Contains(1)), ss => ss.Set().Where( l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.MaybeScalar(x => x.Distinct().Select(l3 => l3.Id).Contains(1)) == true)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Contains_with_subquery_optional_navigation_scalar_distinct_and_constant_item(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where( l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.Select(l3 => l3.Name.Length).Distinct().Contains(1)), @@ -1931,13 +1632,11 @@ public virtual Task Contains_with_subquery_optional_navigation_scalar_distinct_a l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.MaybeScalar( x => x.Select(l3 => l3.Name.Length).Distinct().Contains(1)) == true)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_query_with_optional_navigations_and_client_side_evaluation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where( l1 => l1.Id < 3 @@ -1947,24 +1646,20 @@ public virtual Task Complex_query_with_optional_navigations_and_client_side_eval l1 => l1.Id < 3 && !l1.OneToMany_Optional1.Select(l2 => l2.OneToOne_Optional_FK2.OneToOne_Optional_FK3.MaybeScalar(x => x.Id)) .All(a => true))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_on_a_subquery_with_First_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l2o => l2o.Id == 7) .Select(l2o => ss.Set().OrderBy(l2i => l2i.Id).First().OneToOne_Required_FK_Inverse2.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_on_a_subquery_with_complex_projection_and_First(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2o in ss.Set() @@ -1975,13 +1670,11 @@ join l1i in ss.Set() on l2i.Level1_Required_Id equals l1i.Id orderby l2i.Id select new { Navigation = l2i.OneToOne_Required_FK_Inverse2, Constant = 7 }).First().Navigation.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_on_a_subquery_with_First_in_predicate(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l2o => l2o.Id == 7) @@ -1989,39 +1682,33 @@ public virtual Task Required_navigation_on_a_subquery_with_First_in_predicate(bo l1 => EF.Property( ss.Set().OrderBy(l2i => l2i.Id).First().OneToOne_Required_FK_Inverse2, "Name") == "L1 02")); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Manually_created_left_join_propagates_nullability_to_navigations(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1_manual in ss.Set() join l2_manual in ss.Set() on l1_manual.Id equals l2_manual.Level1_Optional_Id into grouping from l2_manual in grouping.DefaultIfEmpty() where l2_manual.OneToOne_Required_FK_Inverse2.Name != "L3 02" select l2_manual.OneToOne_Required_FK_Inverse2.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_propagates_nullability_to_manually_created_left_join1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2_nav in ss.Set().Select(ll => ll.OneToOne_Optional_FK1) join l2 in ss.Set() on l2_nav.Level1_Required_Id equals l2.Id into grouping from l2 in grouping.DefaultIfEmpty() select new { Id1 = (int?)l2_nav.Id, Id2 = (int?)l2.Id }, elementSorter: e => e.Id1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_propagates_nullability_to_manually_created_left_join2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() join l2_nav in ss.Set().Select(ll => ll.OneToOne_Optional_FK1) on l3.Level2_Required_Id equals l2_nav.Id into @@ -2029,13 +1716,11 @@ join l2_nav in ss.Set().Select(ll => ll.OneToOne_Optional_FK1) on l3.Lev from l2_nav in grouping.DefaultIfEmpty() select new { Name1 = l3.Name, Name2 = l2_nav.Name }, elementSorter: e => (e.Name1, e.Name2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_reference_protection_complex(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() join l2_outer in @@ -2046,13 +1731,11 @@ select l2_inner on l3.Level2_Required_Id equals l2_outer.Id into grouping_outer from l2_outer in grouping_outer.DefaultIfEmpty() select l2_outer.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_reference_protection_complex_materialization(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() join l2_outer in @@ -2069,18 +1752,14 @@ from l2_outer in grouping_outer.DefaultIfEmpty() AssertEqual(e.entity, a.entity); Assert.Equal(e.property, a.property); }); - } private static TResult ClientMethodReturnSelf(TResult element) - { - return element; - } + => element; [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_reference_protection_complex_client_eval(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l3 in ss.Set() join l2_outer in @@ -2091,13 +1770,11 @@ select l2_inner on l3.Level2_Required_Id equals l2_outer.Id into grouping_outer from l2_outer in grouping_outer.DefaultIfEmpty() select ClientMethodReturnSelf(l2_outer.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1_outer in ss.Set() join subquery in @@ -2107,13 +1784,11 @@ select l2_inner on l1_outer.Id equals subquery.Level1_Optional_Id into grouping from subquery in grouping.DefaultIfEmpty() select (int?)subquery.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1_outer in ss.Set() join subquery in @@ -2123,13 +1798,11 @@ select l2_inner on l1_outer.Id equals subquery.Level1_Optional_Id into grouping from subquery in grouping.DefaultIfEmpty() select subquery != null ? (int?)subquery.Id : null); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened3(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1_outer in ss.Set() join subquery in @@ -2140,13 +1813,11 @@ select l2_inner on l1_outer.Id equals subquery.Level1_Required_Id into grouping from subquery in grouping.DefaultIfEmpty() select (int?)subquery.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from x in @@ -2158,46 +1829,42 @@ orderby l1.Id join l2_outer in ss.Set() on x.Id equals l2_outer.Level1_Optional_Id into grouping_outer from l2_outer in grouping_outer.DefaultIfEmpty() select l2_outer.Name); - } - [ConditionalTheory(Skip = "Issue #17328")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer_with_client_method(bool async) - { - return AssertQuery( - async, - ss => - from x in - (from l1 in ss.Set() - join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping - from l2 in grouping.DefaultIfEmpty() - orderby l1.Id - select ClientLevel1(l1)).Take(2) - join l2_outer in ss.Set() on x.Id equals l2_outer.Level1_Optional_Id into grouping_outer - from l2_outer in grouping_outer.DefaultIfEmpty() - select l2_outer.Name, - ss => - from x in - (from l1 in ss.Set() - join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping - from l2 in grouping.DefaultIfEmpty() - orderby l1.Id - select ClientLevel1(l1)).Take(2) - join l2_outer in ss.Set() on x.Id equals l2_outer.Level1_Optional_Id into grouping_outer - from l2_outer in grouping_outer.DefaultIfEmpty() - select l2_outer.Name); - } + // Translation failed message. Issue #17328. + => AssertTranslationFailed( + () => AssertQuery( + async, + ss => + from x in + (from l1 in ss.Set() + join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping + from l2 in grouping.DefaultIfEmpty() + orderby l1.Id + select ClientLevel1(l1)).Take(2) + join l2_outer in ss.Set() on x.Id equals l2_outer.Level1_Optional_Id into grouping_outer + from l2_outer in grouping_outer.DefaultIfEmpty() + select l2_outer.Name, + ss => + from x in + (from l1 in ss.Set() + join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping + from l2 in grouping.DefaultIfEmpty() + orderby l1.Id + select ClientLevel1(l1)).Take(2) + join l2_outer in ss.Set() on x.Id equals l2_outer.Level1_Optional_Id into grouping_outer + from l2_outer in grouping_outer.DefaultIfEmpty() + select l2_outer.Name)); private static Level1 ClientLevel1(Level1 arg) - { - return arg; - } + => arg; [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_inner(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from x in @@ -2209,14 +1876,12 @@ orderby l1.Id join l1_outer in ss.Set() on x.Level1_Optional_Id equals l1_outer.Id into grouping_outer from l1_outer in grouping_outer.DefaultIfEmpty() select l1_outer.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_on_a_subquery_containing_another_GroupJoin_with_orderby_on_inner_sequence_projecting_inner( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from x in @@ -2228,43 +1893,33 @@ orderby l1.Id join l1_outer in ss.Set() on x.Level1_Optional_Id equals l1_outer.Id into grouping_outer from l1_outer in grouping_outer.DefaultIfEmpty() select l1_outer.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_on_left_side_being_a_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.OneToOne_Optional_FK1.Name) .ThenBy(l1 => l1.Id) .Take(2) .Select(x => new { x.Id, Brand = x.OneToOne_Optional_FK1.Name }), e => e.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_on_right_side_being_a_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set() join l1 in ss.Set().OrderBy(x => x.OneToOne_Optional_FK1.Name).Take(2) on l2.Level1_Optional_Id equals l1.Id into grouping from l1 in grouping.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation select new { l2.Id, Name = l1 != null ? l1.Name : null }, -#pragma warning restore IDE0031 // Use null propagation e => e.Id); - } - // ReSharper disable once UnusedParameter.Local private static bool ClientMethod(int? id) - { - return true; - } + => true; [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -2283,11 +1938,10 @@ where l1.Id < 3 select l1.Name); } - [ConditionalTheory(Skip = "Issue #17328")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_in_subquery_with_client_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -2298,13 +1952,11 @@ select ClientStringMethod(l1_inner.Name)).Count() > 7 where l1.Id < 3 select l1.Name); - } - [ConditionalTheory(Skip = "Issue #17328")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_in_subquery_with_client_projection_nested1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1_outer in ss.Set() @@ -2320,13 +1972,11 @@ select ClientStringMethod(l1_inner.Name)).Count() > 4 where l1_outer.Id < 2 select l1_outer.Name); - } - [ConditionalTheory(Skip = "Issue #17328")] + [ConditionalTheory] //(Skip = "Issue #17328")] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_in_subquery_with_client_projection_nested2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1_outer in ss.Set() @@ -2342,18 +1992,14 @@ select ClientStringMethod(l1_middle.Name)).Count() > 4 where l1_outer.Id < 2 select l1_outer.Name); - } private static string ClientStringMethod(string argument) - { - return argument; - } + => argument; [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_client_method_on_outer(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -2361,80 +2007,70 @@ join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.DefaultIfEmpty() select new { l1.Id, client = ClientMethodNullableInt(l1.Id) }, elementSorter: e => e.Id); - } - [ConditionalTheory(Skip = "Issue #17328")] + [ConditionalTheory] //(Skip = "Issue #17328")] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_client_method_in_OrderBy(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.DefaultIfEmpty() - orderby ClientMethodNullableInt(l1.Id), ClientMethodNullableInt(l2 != null ? l2.Id : (int?)null) + orderby ClientMethodNullableInt(l1.Id), ClientMethodNullableInt(l2 != null ? l2.Id : null) select l1.Id, assertOrder: true); - } private static int ClientMethodNullableInt(int? id) - { - return id ?? 0; - } + => id ?? 0; [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_without_DefaultIfEmpty(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin from l2 in groupJoin.Select(gg => gg) select l1.Id); - } - [ConditionalTheory(Skip = "Issue #19015")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_with_subquery_on_inner(bool async) - { - return AssertQueryScalar( - async, - ss => from l1 in ss.Set() - join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin - from l2 in groupJoin.Where(gg => gg.Id > 0).OrderBy(gg => gg.Id).Take(10).DefaultIfEmpty() - select l1.Id); - } + // SelectMany Skip/Take. Issue #19015. + => AssertTranslationFailed( + () => AssertQueryScalar( + async, + ss => from l1 in ss.Set() + join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.Where(gg => gg.Id > 0).OrderBy(gg => gg.Id).Take(10).DefaultIfEmpty() + select l1.Id)); - [ConditionalTheory(Skip = "Issue #19015")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupJoin_with_subquery_on_inner_and_no_DefaultIfEmpty(bool async) - { - return AssertQueryScalar( - async, - ss => from l1 in ss.Set() - join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin - from l2 in groupJoin.Where(gg => gg.Id > 0).OrderBy(gg => gg.Id).Take(10) - select l1.Id); - } + // SelectMany Skip/Take. Issue #19015. + => AssertTranslationFailed( + () => AssertQueryScalar( + async, + ss => from l1 in ss.Set() + join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into groupJoin + from l2 in groupJoin.Where(gg => gg.Id > 0).OrderBy(gg => gg.Id).Take(10) + select l1.Id)); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_in_subquery_with_unrelated_projection(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Where(l1 => l1.OneToOne_Optional_FK1.Name != "Foo") .OrderBy(l1 => l1.Id) .Take(15) .Select(l1 => l1.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Explicit_GroupJoin_in_subquery_with_unrelated_projection(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in (from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping @@ -2444,61 +2080,47 @@ from l2 in grouping.DefaultIfEmpty() #pragma warning restore IDE0031 // Use null propagation select l1).OrderBy(l1 => l1.Id).Take(15) select l1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Explicit_GroupJoin_in_subquery_with_unrelated_projection2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in (from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping from l2 in grouping.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation where (l2 != null ? l2.Name : null) != "Foo" -#pragma warning restore IDE0031 // Use null propagation select l1).Distinct() select l1.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Explicit_GroupJoin_in_subquery_with_unrelated_projection3(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in (from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping from l2 in grouping.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation where (l2 != null ? l2.Name : null) != "Foo" -#pragma warning restore IDE0031 // Use null propagation select l1.Id).Distinct() select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Explicit_GroupJoin_in_subquery_with_unrelated_projection4(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l1 in (from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping from l2 in grouping.DefaultIfEmpty() -#pragma warning disable IDE0031 // Use null propagation where (l2 != null ? l2.Name : null) != "Foo" -#pragma warning restore IDE0031 // Use null propagation select l1.Id).Distinct().OrderBy(id => id).Take(20) select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Explicit_GroupJoin_in_subquery_with_scalar_result_operator(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -2508,14 +2130,12 @@ from l2 in grouping.DefaultIfEmpty() select l1_inner).Count() > 4 select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Explicit_GroupJoin_in_subquery_with_multiple_result_operator_distinct_count_materializes_main_clause( bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -2525,13 +2145,11 @@ from l2 in grouping.DefaultIfEmpty() select l1_inner).Distinct().Count() > 4 select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Where_on_multilevel_reference_in_subquery_with_outer_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l3 => l3.OneToMany_Required_Inverse3.OneToOne_Required_FK_Inverse2.Name == "L1 03") @@ -2539,26 +2157,22 @@ public virtual Task Where_on_multilevel_reference_in_subquery_with_outer_project .Skip(0) .Take(10) .Select(l3 => l3.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_condition_optimizations_applied_correctly_when_anonymous_type_with_single_property(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set() on new { A = EF.Property(l1, "OneToMany_Optional_Self_Inverse1Id") } equals new { A = EF.Property(l2, "Level1_Optional_Id") } select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_condition_optimizations_applied_correctly_when_anonymous_type_with_multiple_properties(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() @@ -2574,13 +2188,11 @@ join l2 in ss.Set() B = EF.Property(l2, "OneToMany_Optional_Self_Inverse2Id") } select l1); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Nested_group_join_with_take(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1_outer in @@ -2592,80 +2204,66 @@ from l2_inner in grouping_inner.DefaultIfEmpty() join l2_outer in ss.Set() on l1_outer.Id equals l2_outer.Level1_Optional_Id into grouping_outer from l2_outer in grouping_outer.DefaultIfEmpty() select l2_outer.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigation_with_same_navigation_compared_to_null(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l2 in ss.Set() where l2.OneToMany_Required_Inverse2.Name != "L1 07" && l2.OneToMany_Required_Inverse2 != null select l2.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multi_level_navigation_compared_to_null(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l3 in ss.Set() where l3.OneToMany_Optional_Inverse3.OneToOne_Required_FK_Inverse2 != null select l3.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multi_level_navigation_with_same_navigation_compared_to_null(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => from l3 in ss.Set() where l3.OneToMany_Optional_Inverse3.OneToOne_Required_FK_Inverse2.Name != "L1 07" where l3.OneToMany_Optional_Inverse3.OneToOne_Required_FK_Inverse2 != null select l3.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigations_compared_to_each_other1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set() where l2.OneToMany_Required_Inverse2 == l2.OneToMany_Required_Inverse2 select l2.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigations_compared_to_each_other2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set() where l2.OneToMany_Required_Inverse2 == l2.OneToOne_Optional_PK_Inverse2 select l2.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigations_compared_to_each_other3(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set() where l2.OneToMany_Optional2.Select(i => i.OneToOne_Optional_PK_Inverse3 == l2).Any() select l2.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigations_compared_to_each_other4(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set() where l2.OneToOne_Required_FK2.OneToMany_Optional3 @@ -2676,13 +2274,11 @@ where l2.OneToOne_Required_FK2.OneToMany_Optional3.MaybeScalar( x => x.Select(i => i.OneToOne_Optional_PK_Inverse4 == l2.OneToOne_Required_FK2).Any()) == true select l2.Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Navigations_compared_to_each_other5(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l2 in ss.Set() where l2.OneToOne_Required_FK2.OneToMany_Optional3 @@ -2693,82 +2289,70 @@ where l2.OneToOne_Required_FK2.OneToMany_Optional3.MaybeScalar( x => x.Select(i => i.OneToOne_Optional_PK_Inverse4 == l2.OneToOne_Optional_PK2).Any()) == true select l2.Name); - } - [ConditionalTheory(Skip = "Issue#16752")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Level4_Include(bool async) - { - return AssertQuery( - async, - ss => ss.Set().Select(l1 => l1.OneToOne_Required_PK1) - .Where(t => t != null) - .Select(l2 => l2.OneToOne_Required_PK2) - .Where(t => t != null) - .Select(l3 => l3.OneToOne_Required_PK3) - .Where(t => t != null) - .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) - .Include(l2 => l2.OneToOne_Optional_FK2), - elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)), - elementSorter: e => e.Id); - } + // Include after select. Issue #16752. + => AssertIncludeOnNonEntity( + () => AssertQuery( + async, + ss => ss.Set().Select(l1 => l1.OneToOne_Required_PK1) + .Where(t => t != null) + .Select(l2 => l2.OneToOne_Required_PK2) + .Where(t => t != null) + .Select(l3 => l3.OneToOne_Required_PK3) + .Where(t => t != null) + .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) + .Include(l2 => l2.OneToOne_Optional_FK2), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)), + elementSorter: e => e.Id)); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Comparing_collection_navigation_on_optional_reference_to_null(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Where(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2 == null).Select(l1 => l1.Id)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_subquery_with_client_eval_and_navigation1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select(l2 => ss.Set().OrderBy(l => l.Id).First().OneToOne_Required_FK_Inverse2.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_subquery_with_client_eval_and_navigation2(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Select( l2 => ss.Set().OrderBy(l => l.Id).First().OneToOne_Required_FK_Inverse2.Name == "L1 02")); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_subquery_with_client_eval_and_multi_level_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select( l3 => ss.Set().OrderBy(l => l.Id).First().OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2.Name)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Member_doesnt_get_pushed_down_into_subquery_with_result_operator(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.Id < 3 select (from l3 in ss.Set() select l3).Distinct().OrderBy(l => l.Id).Skip(1).FirstOrDefault().Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Subquery_with_Distinct_Skip_FirstOrDefault_without_OrderBy(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.Id < 3 @@ -2781,38 +2365,36 @@ orderby l3.Id }, elementSorter: e => e.Key, elementAsserter: (e, a) => Assert.Equal(e.Key, a.Key)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_collection_navigation_count(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() select new { l1.Id, l1.OneToOne_Optional_FK1.OneToMany_Optional2.Count }, ss => from l1 in ss.Set() select new { l1.Id, Count = l1.OneToOne_Optional_FK1.OneToMany_Optional2.MaybeScalar(x => x.Count) ?? 0 }, elementSorter: e => e.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_optional_navigation_property_string_concat(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() from l2 in l1.OneToMany_Optional1.Where(l => l.Id > 5).OrderByDescending(l => l.Name).DefaultIfEmpty() select l1.Name + " " + (l2 != null ? l2.Name : "NULL")); - } - [ConditionalFact] - public virtual void Entries_for_detached_entities_are_removed() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Entries_for_detached_entities_are_removed(bool async) { using var context = CreateContext(); + context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; - var entity = QueryAsserter.SetSourceCreator(context).Set().OrderBy(l2 => l2.Id).First(); + var queryable = QueryAsserter.SetSourceCreator(context).Set().OrderBy(l2 => l2.Id); + var entity = async ? await queryable.FirstAsync() : queryable.First(); var entry = context.ChangeTracker.Entries().Single(); Assert.Same(entity, entry.Entity); @@ -2826,166 +2408,114 @@ public virtual void Entries_for_detached_entities_are_removed() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_with_groupby_in_subquery(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToOne_Optional_FK1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multi_include_with_groupby_in_subquery(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.OneToOne_Optional_FK1), - new ExpectedInclude(e => e.OneToMany_Optional2, "OneToOne_Optional_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.OneToOne_Optional_FK1), + new ExpectedInclude(e2 => e2.OneToMany_Optional2, "OneToOne_Optional_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigation_with_same_name_and_same_type(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.ReferenceSameType), - new ExpectedInclude(e => e.ReferenceSameType) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("ReferenceSameType"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.ReferenceSameType), + new ExpectedInclude(e2 => e2.ReferenceSameType))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigation_with_same_name_and_different_type(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.ReferenceDifferentType), - new ExpectedInclude(e => e.ReferenceDifferentType) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("ReferenceDifferentType"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.ReferenceDifferentType), + new ExpectedInclude(e2 => e2.ReferenceDifferentType))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.ReferenceDifferentType), - new ExpectedInclude(e => e.ReferenceDifferentType), - new ExpectedInclude(e => e.BaseCollection, "ReferenceDifferentType") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("ReferenceDifferentType.BaseCollection"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.ReferenceDifferentType), + new ExpectedInclude(e2 => e2.ReferenceDifferentType), + new ExpectedInclude(e3 => e3.BaseCollection, "ReferenceDifferentType"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_collection_navigation_with_same_name_and_same_type(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.CollectionSameType), - new ExpectedInclude(e => e.CollectionSameType) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("CollectionSameType"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.CollectionSameType), + new ExpectedInclude(e2 => e2.CollectionSameType))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_collection_navigation_with_same_name_and_different_type(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.CollectionDifferentType), - new ExpectedInclude(e => e.CollectionDifferentType) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("CollectionDifferentType"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.CollectionDifferentType), + new ExpectedInclude(e2 => e2.CollectionDifferentType))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_collection_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.CollectionDifferentType), - new ExpectedInclude(e => e.CollectionDifferentType), - new ExpectedInclude(e => e.BaseCollection, "CollectionDifferentType") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("CollectionDifferentType.BaseCollection"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.CollectionDifferentType), + new ExpectedInclude(e2 => e2.CollectionDifferentType), + new ExpectedInclude(e3 => e3.BaseCollection, "CollectionDifferentType"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigations_complex(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Reference), - new ExpectedInclude(e => e.CollectionDifferentType, "Reference"), - new ExpectedInclude(e => e.CollectionDifferentType, "Reference"), - new ExpectedInclude(e => e.Collection), - new ExpectedInclude(e => e.ReferenceSameType, "Collection"), - new ExpectedInclude(e => e.ReferenceSameType, "Collection") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("Reference.CollectionDifferentType").Include("Collection.ReferenceSameType"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(e1 => e1.Reference), + new ExpectedInclude(e2 => e2.CollectionDifferentType, "Reference"), + new ExpectedInclude(e3 => e3.CollectionDifferentType, "Reference"), + new ExpectedInclude(e4 => e4.Collection), + new ExpectedInclude(e5 => e5.ReferenceSameType, "Collection"), + new ExpectedInclude(e6 => e6.ReferenceSameType, "Collection"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Nav_rewrite_doesnt_apply_null_protection_for_function_arguments(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().Where(l1 => l1.OneToOne_Optional_PK1 != null) .Select(l1 => Math.Max(l1.OneToOne_Optional_PK1.Level1_Required_Id, 7))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -3001,176 +2531,115 @@ public virtual Task Accessing_optional_property_inside_result_operator_subquery( [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_subquery_with_custom_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id).SelectMany( l1 => l1.OneToMany_Optional1.Select( l2 => new { l2.Name })).Take(1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include2(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).Include(l1 => l1.OneToOne_Optional_FK1), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include3(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).Include(l1 => l1.OneToOne_Optional_PK1), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include4(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).ThenInclude(l1 => l1.OneToOne_Optional_PK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include5(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include6(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2).Select(l1 => l1.OneToOne_Optional_FK1), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include7(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2) .Select(l1 => l1.OneToOne_Optional_PK1)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include8(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_FK_Inverse2) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l2 => l2.OneToOne_Optional_FK_Inverse2.Name != "Fubar") .Include(l2 => l2.OneToOne_Optional_FK_Inverse2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK_Inverse2))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include9(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_FK_Inverse2) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToOne_Optional_FK_Inverse2) .Where(l2 => l2.OneToOne_Optional_FK_Inverse2.Name != "Fubar"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK_Inverse2))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include10(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_PK1"), - new ExpectedInclude(l3 => l3.OneToOne_Optional_PK3, "OneToOne_Optional_FK1.OneToOne_Optional_FK2") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_FK2.OneToOne_Optional_PK3), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_PK1"), + new ExpectedInclude(l3 => l3.OneToOne_Optional_PK3, "OneToOne_Optional_FK1.OneToOne_Optional_FK2"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include11(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"), - new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_PK1"), - new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToOne_Optional_PK1.OneToOne_Optional_FK2"), - new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_PK1"), - new ExpectedInclude(l3 => l3.OneToOne_Optional_PK3, "OneToOne_Optional_PK1.OneToOne_Optional_FK2"), - new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_PK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2) @@ -3178,22 +2647,27 @@ public virtual Task Include11(bool async) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_FK2.OneToOne_Optional_FK3) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_FK2.OneToOne_Optional_PK3) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_PK2), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude( + e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"), + new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_PK1"), + new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToOne_Optional_PK1.OneToOne_Optional_FK2"), + new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_PK1"), + new ExpectedInclude(l3 => l3.OneToOne_Optional_PK3, "OneToOne_Optional_PK1.OneToOne_Optional_FK2"), + new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_PK1"))); [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Include12(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) }; - - return AssertQuery( + [MemberData(nameof(IsAsyncData))] + public virtual Task Include12(bool async) + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2) .Select(l1 => l1.OneToOne_Optional_FK1), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -3217,14 +2691,7 @@ public virtual Task Include13(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include14(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1).ThenInclude(l2 => l2.OneToOne_Optional_FK2) @@ -3237,75 +2704,80 @@ public virtual Task Include14(bool async) }), elementAsserter: (e, a) => { - AssertInclude(e.one, a.one, expectedIncludes); + AssertInclude( + e.one, a.one, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1")); AssertInclude(e.two, a.two, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)); AssertEqual(e.three, a.three); }, elementSorter: e => e.one.Id); - } - [ConditionalFact(Skip = "Issue#16752")] - public virtual void Include17() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Include17(bool async) { using var ctx = CreateContext(); var query = ctx.LevelOne.Select(l1 => new { foo = l1.OneToOne_Optional_FK1, bar = l1.OneToOne_Optional_PK1 }) .Include(x => x.foo.OneToOne_Optional_FK2).Distinct(); - var result = query.ToList(); + // Include after select. Issue #16752. + return AssertIncludeOnNonEntity( + () => + { + if (async) + { + return query.ToListAsync(); + } + + query.ToList(); + return Task.CompletedTask; + }); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include18_1(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(x => x.OneToOne_Optional_FK1).Distinct(), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include18_1_1(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OrderBy(x => x.OneToOne_Required_FK1.Name).Include(x => x.OneToOne_Optional_FK1).Take(10), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include18_2(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(x => x.OneToOne_Required_FK1.Name != "Foo").Include(x => x.OneToOne_Optional_FK1).Distinct(), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); - [ConditionalFact] - public virtual void Include18_3() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include18_3(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne .OrderBy(x => x.OneToOne_Required_FK1.Name) .Include(x => x.OneToOne_Optional_FK1) .Select(l1 => new { foo = l1, bar = l1 }).Take(10); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Include18_3_1() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include18_3_1(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne .OrderBy(x => x.OneToOne_Required_FK1.Name) .Include(x => x.OneToOne_Optional_FK1) @@ -3313,105 +2785,110 @@ public virtual void Include18_3_1() .Take(10) .Select(x => new { x.foo, x.bar }); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Include18_3_2() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include18_3_2(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne .OrderBy(x => x.OneToOne_Required_FK1.Name) .Include(x => x.OneToOne_Optional_FK1) .Select(l1 => new { outer_foo = new { inner_foo = l1, inner_bar = l1.Name }, outer_bar = l1 }) .Take(10); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include18_3_3(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK2) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(x => x.OneToOne_Optional_FK1.OneToOne_Optional_FK2) .Select(l1 => l1.OneToOne_Optional_FK1) .Distinct(), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK2))); - [ConditionalFact] - public virtual void Include18_4() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include18_4(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne.Include(x => x.OneToOne_Optional_FK1).Select(l1 => new { foo = l1, bar = l1 }).Distinct(); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Include18() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include18(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne .Include(x => x.OneToOne_Optional_FK1) .Select(l1 => new { foo = l1, bar = l1.OneToOne_Optional_PK1 }) .OrderBy(x => x.foo.Id) .Take(10); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Include19() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include19(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne .Include(x => x.OneToOne_Optional_FK1) .Select(l1 => new { foo = l1.OneToOne_Optional_FK1, bar = l1.OneToOne_Optional_PK1 }) .Distinct(); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_all_method_include_gets_ignored(bool async) - { - return AssertAll( + => AssertAll( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).Include(l1 => l1.OneToMany_Optional1), predicate: l1 => l1.Name != "Foo"); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_with_navigations_in_the_result_selector1(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set(), l1 => l1.Id, l2 => l2.Level1_Required_Id, (o, i) => new { o.OneToOne_Optional_FK1, i })); - } - [ConditionalFact] - public virtual void Join_with_navigations_in_the_result_selector2() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Join_with_navigations_in_the_result_selector2(bool async) { using var ctx = CreateContext(); + var query = ctx.LevelOne.Join( ctx.LevelTwo, l1 => l1.Id, l2 => l2.Level1_Required_Id, (o, i) => new { o.OneToOne_Optional_FK1, i.OneToMany_Optional2 }); - var result = query.ToList(); + + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Member_pushdown_chain_3_levels_deep() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Member_pushdown_chain_3_levels_deep(bool async) { using var ctx = CreateContext(); + var query = from l1 in ctx.LevelOne orderby l1.Id where (from l2 in ctx.LevelTwo @@ -3427,13 +2904,15 @@ orderby l4.Id != "Foo" select l1; - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Member_pushdown_chain_3_levels_deep_entity() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Member_pushdown_chain_3_levels_deep_entity(bool async) { using var ctx = CreateContext(); + var query = from l1 in ctx.LevelOne orderby l1.Id select (from l2 in ctx.LevelTwo @@ -3447,13 +2926,15 @@ orderby l3.Id orderby l4.Id select l4).FirstOrDefault()).FirstOrDefault()).FirstOrDefault(); - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } - [ConditionalFact] - public virtual void Member_pushdown_with_collection_navigation_in_the_middle() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Member_pushdown_with_collection_navigation_in_the_middle(bool async) { using var ctx = CreateContext(); + var query = from l1 in ctx.LevelOne orderby l1.Id select (from l2 in ctx.LevelTwo @@ -3465,14 +2946,13 @@ select l2.OneToMany_Optional2.Select( orderby l4.Id select l4).FirstOrDefault()).FirstOrDefault()).FirstOrDefault().Name; - var result = query.ToList(); + _ = async ? await query.ToListAsync() : query.ToList(); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Member_pushdown_with_multiple_collections(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select( l1 => l1.OneToMany_Optional1.OrderBy(l2 => l2.Id).FirstOrDefault().OneToMany_Optional2.OrderBy(l3 => l3.Id) @@ -3481,13 +2961,11 @@ public virtual Task Member_pushdown_with_multiple_collections(bool async) l1 => l1.OneToMany_Optional1.OrderBy(l2 => l2.Id).FirstOrDefault().Maybe( x => x.OneToMany_Optional2.OrderBy(l3 => l3.Id) .FirstOrDefault().Maybe(xx => xx.Name)))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_collections_on_same_level(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1).Include(l1 => l1.OneToMany_Required1), elementAsserter: (e, a) => AssertInclude( @@ -3495,13 +2973,11 @@ public virtual Task Include_multiple_collections_on_same_level(bool async) new ExpectedInclude(l1 => l1.OneToMany_Optional1), new ExpectedInclude(l1 => l1.OneToMany_Required1)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_check_removal_applied_recursively(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where( l1 => @@ -3515,13 +2991,11 @@ public virtual Task Null_check_removal_applied_recursively(bool async) ? null : l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2.OneToOne_Optional_FK3.Name) == "L4 01")); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_check_different_structure_does_not_remove_null_checks(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where( l1 => @@ -3533,13 +3007,11 @@ public virtual Task Null_check_different_structure_does_not_remove_null_checks(b ? null : l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2.OneToOne_Optional_FK3.Name) == "L4 01")); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Union_over_entities_with_different_nullability(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set() .GroupJoin(ss.Set(), l1 => l1.Id, l2 => l2.Level1_Optional_Id, (l1, l2s) => new { l1, l2s }) @@ -3557,25 +3029,21 @@ public virtual Task Union_over_entities_with_different_nullability(bool async) .SelectMany(g => g.l1s.DefaultIfEmpty(), (g, l1) => new { l1, g.l2 }) .Where(e => e.l1 == null)) .Select(e => e.l1.MaybeScalar(x => x.Id))); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Including_reference_navigation_and_projecting_collection_navigation_2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Required_FK1) .Include(e => e.OneToMany_Required1) .Select(e => new { e, First = e.OneToMany_Required1.OrderByDescending(e => e.Id).FirstOrDefault() })); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task OrderBy_collection_count_ThenBy_reference_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .OrderBy(l1 => l1.OneToOne_Required_FK1.OneToMany_Required2.Count()) @@ -3584,49 +3052,39 @@ public virtual Task OrderBy_collection_count_ThenBy_reference_navigation(bool as .OrderBy(l1 => l1.OneToOne_Required_FK1.OneToMany_Required2.MaybeScalar(x => x.Count()) ?? 0) .ThenBy(l1 => l1.OneToOne_Required_FK1.OneToOne_Required_FK2.Name), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Null_conditional_is_not_applied_explicitly_for_optional_navigation(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l1 => l1.OneToOne_Optional_FK1 != null && l1.OneToOne_Optional_FK1.Name == "L2 01")); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Sum_with_selector_cast_using_as(bool async) - { - return AssertSum( + => AssertSum( async, ss => ss.Set().Select(s => s.Id as int?)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Sum_with_filter_with_include_selector_cast_using_as(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(l1 => l1.Id > l1.OneToMany_Optional1.Select(l2 => l2.Id as int?).Sum())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_with_joined_where_clause_cast_using_as(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(w => w.Id == w.OneToOne_Optional_FK1.Id as int?)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_outside_reference_to_joined_table_correctly_translated_to_apply(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Required_Id @@ -3634,13 +3092,11 @@ join l3 in ss.Set() on l2.Id equals l3.Level2_Required_Id join l4 in ss.Set() on l3.Id equals l4.Level3_Required_Id from other in ss.Set().Where(x => x.Id <= l2.Id && x.Name == l4.Name).DefaultIfEmpty() select l1); - } - [ConditionalTheory(Skip = "issue #19095")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany( l1 => l1.OneToMany_Optional1.DefaultIfEmpty().SelectMany( @@ -3652,13 +3108,15 @@ public virtual Task Nested_SelectMany_correlated_with_join_table_correctly_trans l2Name = l2.OneToOne_Required_PK2.Name, l3Name = l4.OneToOne_Optional_PK_Inverse4.Name })))); - } - [ConditionalFact] - public virtual void Contains_over_optional_navigation_with_null_constant() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Contains_over_optional_navigation_with_null_constant(bool async) { using var ctx = CreateContext(); - var result = ctx.Set().Select(l1 => l1.OneToOne_Optional_FK1).Contains(null); + + var queryable = ctx.Set().Select(l1 => l1.OneToOne_Optional_FK1); + var result = async ? await queryable.ContainsAsync(null) : queryable.Contains(null); var expected = Fixture.GetExpectedData().Set().Select(l1 => l1.OneToOne_Optional_FK1).Contains(null); Assert.Equal(expected, result); @@ -3667,18 +3125,15 @@ public virtual void Contains_over_optional_navigation_with_null_constant() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Contains_over_optional_navigation_with_null_parameter(bool async) - { - return AssertSingleResult( + => AssertSingleResult( async, ss => ss.Set().Select(l1 => l1.OneToOne_Optional_FK1).Contains(null), ss => ss.Set().Select(l1 => l1.OneToOne_Optional_FK1).ContainsAsync(null, default)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Contains_over_optional_navigation_with_null_column(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select( l1 => new @@ -3688,13 +3143,11 @@ public virtual Task Contains_over_optional_navigation_with_null_column(bool asyn Contains = ss.Set().Select(x => x.OneToOne_Optional_FK1.Name).Contains(l1.OneToOne_Optional_FK1.Name) }), elementSorter: e => (e.Name, e.OptionalName, e.Contains)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Contains_over_optional_navigation_with_null_entity_reference(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Select( l1 => new @@ -3704,26 +3157,22 @@ public virtual Task Contains_over_optional_navigation_with_null_entity_reference Contains = ss.Set().Select(x => x.OneToOne_Optional_FK1).Contains(l1.OneToOne_Optional_PK1) }), elementSorter: e => (e.Name, e.OptionalName, e.Contains)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Element_selector_with_coalesce_repeated_in_aggregate(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set().GroupBy( l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.Name, l1 => new { Id = ((int?)l1.OneToOne_Required_PK1.Id ?? 0) }) .Where(g => g.Min(l1 => l1.Id + l1.Id) > 0) .Select(g => g.Count())); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Nested_object_constructed_from_group_key_properties(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l1 => l1.OneToOne_Optional_FK1 != null) @@ -3758,37 +3207,31 @@ public virtual Task Nested_object_constructed_from_group_key_properties(bool asy }, Aggregate = g.Sum(x => x.Name.Length) })); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_aggregate_where_required_relationship(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l2 => l2.OneToMany_Required_Inverse2.Id) .Select(g => new { g.Key, Max = g.Max(e => e.Id) }) .Where(x => x.Max != 2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_aggregate_where_required_relationship_2(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .GroupBy(l2 => l2.OneToMany_Required_Inverse2.Id) .Select(g => new { g.Key, Max = g.Max(e => e.Id) }) .Where(x => x.Max < 2 || x.Max > 2)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Member_over_null_check_ternary_and_nested_dto_type(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Select( @@ -3800,8 +3243,7 @@ public virtual Task Member_over_null_check_ternary_and_nested_dto_type(bool asyn ? null : new Level2Dto { - Id = l1.OneToOne_Optional_FK1.Id, - Name = l1.OneToOne_Optional_FK1.Name, + Id = l1.OneToOne_Optional_FK1.Id, Name = l1.OneToOne_Optional_FK1.Name, } }) .OrderBy(e => e.Level2.Name) @@ -3822,7 +3264,6 @@ public virtual Task Member_over_null_check_ternary_and_nested_dto_type(bool asyn Assert.Equal(e.Level2.Name, a.Level2.Name); } }); - } private class Level1Dto { @@ -3840,8 +3281,7 @@ private class Level2Dto [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Member_over_null_check_ternary_and_nested_anonymous_type(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Select( @@ -3881,37 +3321,31 @@ public virtual Task Member_over_null_check_ternary_and_nested_anonymous_type(boo Assert.Equal(e.Level2.Name, a.Level2.Name); } }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Distinct_skip_without_orderby(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.Id < 3 select (from l3 in ss.Set() select l3).Distinct().Skip(1).OrderBy(e => e.Id).FirstOrDefault().Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Distinct_take_without_orderby(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() where l1.Id < 3 select (from l3 in ss.Set() select l3).Distinct().Take(1).OrderBy(e => e.Id).FirstOrDefault().Name); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Let_let_contains_from_outer_let(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set().Include(l => l.OneToMany_Required1) let level2Ids = from level2 in l1.OneToMany_Required1 select level2.Id @@ -3926,21 +3360,20 @@ from level3 in level3s.DefaultIfEmpty() AssertEqual(e.l1, a.l1); AssertEqual(e.level3, a.level3); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_conditionals_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() - .Select(l2 => new Level1Dto - { - Id = l2.Id, - Name = l2.OneToOne_Optional_FK2 == null ? null : l2.OneToOne_Optional_FK2.Name, - Level2 = l2.OneToOne_Optional_FK_Inverse2 == null ? null : new Level2Dto() - }), + .Select( + l2 => new Level1Dto + { + Id = l2.Id, + Name = l2.OneToOne_Optional_FK2 == null ? null : l2.OneToOne_Optional_FK2.Name, + Level2 = l2.OneToOne_Optional_FK_Inverse2 == null ? null : new Level2Dto() + }), elementSorter: e => e.Id, elementAsserter: (e, a) => { @@ -3956,214 +3389,228 @@ public virtual Task Multiple_conditionals_in_projection(bool async) AssertEqual(e.Level2.Name, a.Level2.Name); } }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key(bool async) - { - return AssertQueryScalar( + => AssertQueryScalar( async, ss => ss.Set() .Join( ss.Set().GroupBy(g => g.Id % 3).Select(g => new { g.Key, Sum = g.Sum(x => x.Id) }), o => new { o.Id, Condition = true }, - i => new { Id = i.Key, Condition = i.Sum > 10, }, + i => new + { + Id = i.Key, Condition = i.Sum > 10, + }, (o, i) => i.Key)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_joins_groupby_predicate(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id into grouping1 from l2 in grouping1.DefaultIfEmpty() join x in (from l3 in ss.Set() - group l3 by l3.Name into g - select new { Key = g.Key, Count = g.Count() }) on l1.Name equals x.Key into grouping2 + group l3 by l3.Name + into g + select new { g.Key, Count = g.Count() }) on l1.Name equals x.Key into grouping2 from x in grouping2.DefaultIfEmpty() where l2.Name != null || x.Count > 0 - select new { l1.Id, l1.Name, Foo = l2 == null ? "Foo" : "Bar" }, + select new + { + l1.Id, + l1.Name, + Foo = l2 == null ? "Foo" : "Bar" + }, elementSorter: e => (e.Id, e.Name, e.Foo)); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Collection_FirstOrDefault_property_accesses_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(x => x.OneToMany_Optional1).ThenInclude(x => x.OneToMany_Optional2) .Where(l1 => l1.Id < 3) - .Select(l1 => new - { - l1.Id, - Pushdown = l1.OneToMany_Optional1.Where(x => x.Name == "L2 02").FirstOrDefault().Name - })); - } + .Select(l1 => new { l1.Id, Pushdown = l1.OneToMany_Optional1.Where(x => x.Name == "L2 02").FirstOrDefault().Name })); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Collection_FirstOrDefault_entity_reference_accesses_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(x => x.OneToMany_Optional1).ThenInclude(x => x.OneToMany_Optional2) .Where(l1 => l1.Id < 3) - .Select(l1 => new - { - l1.Id, - Pushdown = l1.OneToMany_Optional1 - .Where(x => x.Name == "L2 02") - .FirstOrDefault().OneToOne_Optional_FK2 - })); - } + .Select( + l1 => new + { + l1.Id, + Pushdown = l1.OneToMany_Optional1 + .Where(x => x.Name == "L2 02") + .FirstOrDefault().OneToOne_Optional_FK2 + })); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Collection_FirstOrDefault_entity_collection_accesses_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l1 => l1.Id < 2) - .Select(l1 => new - { - l1.Id, - Pushdown = l1.OneToMany_Optional1 - .Where(x => x.Name == "L2 02") - .FirstOrDefault().OneToMany_Optional2.ToList() - }), + .Select( + l1 => new + { + l1.Id, + Pushdown = l1.OneToMany_Optional1 + .Where(x => x.Name == "L2 02") + .FirstOrDefault().OneToMany_Optional2.ToList() + }), elementSorter: e => e.Id, elementAsserter: (e, a) => { Assert.Equal(e.Id, a.Id); AssertCollection(e.Pushdown, a.Pushdown); }); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Where(l1 => l1.Id < 2) - .Select(l1 => new - { - l1.Id, - Pushdown = l1.OneToMany_Optional1 - .Where(x => x.Name == "L2 02") - .FirstOrDefault().OneToMany_Optional2 + .Select( + l1 => new + { + l1.Id, + Pushdown = l1.OneToMany_Optional1 + .Where(x => x.Name == "L2 02") + .FirstOrDefault().OneToMany_Optional2 .OrderBy(x => x.Id) .FirstOrDefault().Name - })); - } + })); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => (from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id join l3 in ss.Set() on l2.Id equals l3.Level2_Optional_Id - select new { Id1 = l1.Id, Id2 = l2.Id, Id3 = l3.Id, Name1 = l1.Name, Name2 = l2.Name }).Distinct().Select(x => new { Foo = x.Id1, Bar = x.Id2, Baz = x.Id3 }).Take(10), + select new + { + Id1 = l1.Id, + Id2 = l2.Id, + Id3 = l3.Id, + Name1 = l1.Name, + Name2 = l2.Name + }).Distinct().Select( + x => new + { + Foo = x.Id1, + Bar = x.Id2, + Baz = x.Id3 + }).Take(10), elementSorter: e => (e.Foo, e.Bar, e.Baz)); - } - - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_query_with_let_collection_SelectMany(bool async) - { - return AssertQuery( - async, - ss => from l1 in ss.Set() - where l1.Name.StartsWith("L1 0") - let inner = from i in ss.Set() - where i.Id == l1.Id && i.Id > 5 - select i - from die in inner.DefaultIfEmpty() - select die ?? l1); - } + // Materialization type. Issue #23302. + => AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => from l1 in ss.Set() + where l1.Name.StartsWith("L1 0") + let inner = from i in ss.Set() + where i.Id == l1.Id && i.Id > 5 + select i + from die in inner.DefaultIfEmpty() + select die ?? l1), + "IQueryable"); - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_without_collection_selector_returning_queryable(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => ss.Set().SelectMany(x => ss.Set().Where(l2 => l2.Id < 10))); - } - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_projecting_queryable_followed_by_SelectMany(bool async) - { - return AssertQuery( - async, - ss => ss.Set().Select(x => ss.Set().Where(l2 => l2.Id < 10)).SelectMany(x => x)); - } + => AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => ss.Set().Select(x => ss.Set().Where(l2 => l2.Id < 10)).SelectMany(x => x)), + "IQueryable"); - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from l1 in ss.Set() join l2 in ss.Set() on l1.Id equals l2.Level1_Optional_Id select ss.Set().Where(x => x.Id < 5)); - } - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_projecting_queryable_followed_by_Join(bool async) - { - return AssertQuery( - async, - ss => ss.Set().Select(x => ss.Set().Where(l2 => l2.Id < 10)).Join(ss.Set(), o => 7, i => i.Id, (o, i) => i)); - } + // Materialization type. Issue #23302. + => AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => ss.Set().Select( + x => ss.Set().Where(l2 => l2.Id < 10)) + .Join(ss.Set(), o => 7, i => i.Id, (o, i) => i)), + "IQueryable"); - [ConditionalTheory(Skip = "issue #23302")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_projecting_queryable_in_anonymous_projection_followed_by_Join(bool async) - { - return AssertQuery( - async, - ss => ss.Set().Select(x => new { Subquery = ss.Set().Where(l2 => l2.Id < 10) }).Join(ss.Set(), o => 7, i => i.Id, (o, i) => i)); - } + // Materialization type. Issue #23302. + => AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => ss.Set().Select( + x => new + { + Subquery = ss.Set() + .Where(l2 => l2.Id < 10) + }) + .Join(ss.Set(), o => 7, i => i.Id, (o, i) => i)), + "IQueryable"); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Project_shadow_properties(bool async) - { - await AssertQuery( + public virtual Task Project_shadow_properties1(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, + x.Id, OneToOne_Optional_Self1Id = EF.Property(x, "OneToOne_Optional_Self1Id"), OneToMany_Required_Self_Inverse1Id = EF.Property(x, "OneToMany_Required_Self_Inverse1Id"), OneToMany_Optional_Self_Inverse1Id = EF.Property(x, "OneToMany_Optional_Self_Inverse1Id"), }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties2(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, + x.Id, OneToOne_Optional_PK_Inverse2Id = EF.Property(x, "OneToOne_Optional_PK_Inverse2Id"), OneToMany_Required_Inverse2Id = EF.Property(x, "OneToMany_Required_Inverse2Id"), OneToMany_Optional_Inverse2Id = EF.Property(x, "OneToMany_Optional_Inverse2Id"), @@ -4173,12 +3620,15 @@ await AssertQuery( }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties3(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, + x.Id, OneToOne_Optional_PK_Inverse3Id = EF.Property(x, "OneToOne_Optional_PK_Inverse3Id"), OneToMany_Required_Inverse3Id = EF.Property(x, "OneToMany_Required_Inverse3Id"), OneToMany_Optional_Inverse3Id = EF.Property(x, "OneToMany_Optional_Inverse3Id"), @@ -4188,12 +3638,15 @@ await AssertQuery( }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties4(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, + x.Id, OneToOne_Optional_PK_Inverse4Id = EF.Property(x, "OneToOne_Optional_PK_Inverse4Id"), OneToMany_Required_Inverse4Id = EF.Property(x, "OneToMany_Required_Inverse4Id"), OneToMany_Optional_Inverse4Id = EF.Property(x, "OneToMany_Optional_Inverse4Id"), @@ -4203,56 +3656,71 @@ await AssertQuery( }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties5(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, + x.Id, InheritanceBase2Id = EF.Property(x, "InheritanceBase2Id"), InheritanceBase2Id1 = EF.Property(x, "InheritanceBase2Id1"), }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties6(bool async) + => AssertQuery( async, ss => from x in ss.Set().OfType() select new { - Id = x.Id, + x.Id, InheritanceBase2Id = EF.Property(x, "InheritanceBase2Id"), InheritanceBase2Id1 = EF.Property(x, "InheritanceBase2Id1"), }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties7(bool async) + => AssertQuery( async, ss => from x in ss.Set().OfType() select new { - Id = x.Id, + x.Id, InheritanceBase2Id = EF.Property(x, "InheritanceBase2Id"), InheritanceBase2Id1 = EF.Property(x, "InheritanceBase2Id1"), }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties8(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, - InheritanceLeaf2Id = EF.Property(x, "InheritanceLeaf2Id"), + x.Id, InheritanceLeaf2Id = EF.Property(x, "InheritanceLeaf2Id"), }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties9(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, - DifferentTypeReference_InheritanceDerived1Id = EF.Property(x, "DifferentTypeReference_InheritanceDerived1Id"), + x.Id, + DifferentTypeReference_InheritanceDerived1Id = + EF.Property(x, "DifferentTypeReference_InheritanceDerived1Id"), InheritanceDerived1Id = EF.Property(x, "InheritanceDerived1Id"), InheritanceDerived1Id1 = EF.Property(x, "InheritanceDerived1Id1"), InheritanceDerived2Id = EF.Property(x, "InheritanceDerived2Id"), @@ -4261,28 +3729,29 @@ await AssertQuery( }, elementSorter: e => e.Id); - await AssertQuery( + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_shadow_properties10(bool async) + => AssertQuery( async, ss => from x in ss.Set() select new { - Id = x.Id, - DifferentTypeReference_InheritanceDerived2Id = EF.Property(x, "DifferentTypeReference_InheritanceDerived2Id"), + x.Id, + DifferentTypeReference_InheritanceDerived2Id = + EF.Property(x, "DifferentTypeReference_InheritanceDerived2Id"), InheritanceDerived2Id = EF.Property(x, "InheritanceDerived2Id"), }, elementSorter: e => e.Id); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Prune_does_not_throw_null_ref(bool async) - { - return AssertQuery( + => AssertQuery( async, ss => from ids in (from l2 in ss.Set().Where(i => i.Id < 5) select l2.Level1_Required_Id).DefaultIfEmpty() from l1 in ss.Set().Where(x => x.Id != ids) select l1); - } } } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryFixtureBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryFixtureBase.cs index dd694a5f176..9053533d8d2 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryFixtureBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryFixtureBase.cs @@ -68,10 +68,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con // FK name needs to be explicitly provided because issue #9310 modelBuilder.Entity().HasOne(e => e.Reference).WithOne() - .HasForeignKey("InheritanceBase2Id1") + .HasForeignKey("InheritanceBase2Id") .IsRequired(false); modelBuilder.Entity().HasMany(e => e.Collection).WithOne() - .HasForeignKey("InheritanceBase2Id"); + .HasForeignKey("InheritanceBase2Id1"); modelBuilder.Entity().HasBaseType(); modelBuilder.Entity().HasOne(e => e.ReferenceSameType).WithOne() diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryTestBase.cs index 6965ea7f972..a88901b49fb 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsSharedTypeQueryTestBase.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Threading.Tasks; -using Xunit; namespace Microsoft.EntityFrameworkCore.Query { @@ -14,61 +13,65 @@ protected ComplexNavigationsSharedTypeQueryTestBase(TFixture fixture) { } - // Self-ref not supported public override Task Join_navigation_self_ref(bool async) - => Task.CompletedTask; + => AssertTranslationFailed(() => base.Join_navigation_self_ref(async)); public override Task Join_condition_optimizations_applied_correctly_when_anonymous_type_with_multiple_properties(bool async) - => Task.CompletedTask; + => AssertUnableToTranslateEFProperty( + () => base.Join_condition_optimizations_applied_correctly_when_anonymous_type_with_multiple_properties(async)); public override Task Join_condition_optimizations_applied_correctly_when_anonymous_type_with_single_property(bool async) - => Task.CompletedTask; + => AssertUnableToTranslateEFProperty( + () => base.Join_condition_optimizations_applied_correctly_when_anonymous_type_with_single_property(async)); public override Task Multiple_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_joined_together(bool async) - => Task.CompletedTask; + => AssertTranslationFailed( + () => base.Multiple_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_joined_together(async)); - public override Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany(bool async) - => Task.CompletedTask; + public override Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany( + bool async) + => AssertTranslationFailed( + () => base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany(async)); - public override Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2(bool async) - => Task.CompletedTask; + public override Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2( + bool async) + => AssertTranslationFailed( + () => base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2(async)); public override Task SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany(bool async) - => Task.CompletedTask; + => AssertTranslationFailed(() => base.SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany(async)); - [ConditionalTheory(Skip = "Issue#16752")] public override Task Include8(bool async) - { - return base.Include8(async); - } + => AssertIncludeOnNonEntity(() => base.Include8(async)); - [ConditionalTheory(Skip = "Issue#16752")] public override Task Include9(bool async) - { - return base.Include9(async); - } + => AssertIncludeOnNonEntity(() => base.Include9(async)); - // Cannot create DbSet for Level2 - public override void Join_with_navigations_in_the_result_selector2() - { - } + public override Task Join_with_navigations_in_the_result_selector2(bool async) + => AssertInvalidSetSharedType(() => base.Join_with_navigations_in_the_result_selector2(async), "Level2"); - public override void Member_pushdown_chain_3_levels_deep() - { - } + public override Task Member_pushdown_chain_3_levels_deep(bool async) + => AssertInvalidSetSharedType(() => base.Member_pushdown_chain_3_levels_deep(async), "Level2"); - public override void Member_pushdown_chain_3_levels_deep_entity() - { - } + public override Task Member_pushdown_chain_3_levels_deep_entity(bool async) + => AssertInvalidSetSharedType(() => base.Member_pushdown_chain_3_levels_deep_entity(async), "Level2"); - public override void Member_pushdown_with_collection_navigation_in_the_middle() - { - } + public override Task Member_pushdown_with_collection_navigation_in_the_middle(bool async) + => AssertInvalidSetSharedType(() => base.Member_pushdown_with_collection_navigation_in_the_middle(async), "Level2"); + + public override Task Project_shadow_properties1(bool async) + => AssertUnableToTranslateEFProperty(() => base.Project_shadow_properties1(async)); + + public override Task Project_shadow_properties2(bool async) + => AssertUnableToTranslateEFProperty(() => base.Project_shadow_properties2(async)); + + public override Task Project_shadow_properties3(bool async) + => AssertUnableToTranslateEFProperty(() => base.Project_shadow_properties3(async)); - public override Task Union_over_entities_with_different_nullability(bool async) - => Task.CompletedTask; + public override Task Project_shadow_properties4(bool async) + => AssertUnableToTranslateEFProperty(() => base.Project_shadow_properties4(async)); - public override Task Project_shadow_properties(bool async) - => Task.CompletedTask; + public override Task Project_shadow_properties9(bool async) + => AssertUnableToTranslateEFProperty(() => base.Project_shadow_properties9(async)); } } diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index a6ea1fc153a..51805c3b8a7 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -590,7 +590,7 @@ await AssertQuery( await AssertQuery( async, - ss => ss.Set().Where(g => ((short)g.Rank & (short)1) == 1)); + ss => ss.Set().Where(g => ((short)g.Rank & 1) == 1)); } [ConditionalTheory] @@ -773,8 +773,7 @@ public virtual Task Select_enum_has_flag(bool async) .Select( b => new { - hasFlagTrue = b.Rank.HasFlag(MilitaryRank.Corporal), - hasFlagFalse = b.Rank.HasFlag(MilitaryRank.Sergeant) + hasFlagTrue = b.Rank.HasFlag(MilitaryRank.Corporal), hasFlagFalse = b.Rank.HasFlag(MilitaryRank.Sergeant) })); } @@ -980,7 +979,7 @@ public virtual Task Null_propagation_optimization2(bool async) return AssertQuery( async, ss => ss.Set().Where( - g => (g.LeaderNickname == null ? (bool?)null : (bool?)g.LeaderNickname.EndsWith("us")) == (bool?)true)); + g => (g.LeaderNickname == null ? null : g.LeaderNickname.EndsWith("us")) == true)); } [ConditionalTheory] @@ -990,7 +989,7 @@ public virtual Task Null_propagation_optimization3(bool async) return AssertQuery( async, ss => ss.Set().Where( - g => (g.LeaderNickname != null ? (bool?)g.LeaderNickname.EndsWith("us") : (bool?)null) == (bool?)true)); + g => (g.LeaderNickname != null ? g.LeaderNickname.EndsWith("us") : null) == true)); } [ConditionalTheory] @@ -1000,7 +999,7 @@ public virtual Task Null_propagation_optimization4(bool async) return AssertQuery( async, ss => ss.Set().Where( - g => (null == EF.Property(g, "LeaderNickname") ? (int?)null : g.LeaderNickname.Length) == 5 == (bool?)true)); + g => (null == EF.Property(g, "LeaderNickname") ? null : g.LeaderNickname.Length) == 5 == (bool?)true)); } [ConditionalTheory] @@ -1010,7 +1009,7 @@ public virtual Task Null_propagation_optimization5(bool async) return AssertQuery( async, ss => ss.Set().Where( - g => (null != g.LeaderNickname ? (int?)(EF.Property(g, "LeaderNickname").Length) : (int?)null) + g => (null != g.LeaderNickname ? EF.Property(g, "LeaderNickname").Length : null) == 5 == (bool?)true)); } @@ -1022,7 +1021,7 @@ public virtual Task Null_propagation_optimization6(bool async) return AssertQuery( async, ss => ss.Set().Where( - g => (null != g.LeaderNickname ? (int?)EF.Property(g, "LeaderNickname").Length : (int?)null) + g => (null != g.LeaderNickname ? EF.Property(g, "LeaderNickname").Length : null) == 5 == (bool?)true)); } @@ -1051,7 +1050,7 @@ public virtual Task Select_null_propagation_optimization9(bool async) { return AssertQueryScalar( async, - ss => ss.Set().Select(g => g != null ? (int?)g.FullName.Length : (int?)null)); + ss => ss.Set().Select(g => g != null ? g.FullName.Length : (int?)null)); } [ConditionalTheory] @@ -1060,7 +1059,7 @@ public virtual Task Select_null_propagation_negative1(bool async) { return AssertQueryScalar( async, - ss => ss.Set().Select(g => g.LeaderNickname != null ? (bool?)(g.Nickname.Length == 5) : (bool?)null)); + ss => ss.Set().Select(g => g.LeaderNickname != null ? g.Nickname.Length == 5 : (bool?)null)); } [ConditionalTheory] @@ -1071,7 +1070,7 @@ public virtual Task Select_null_propagation_negative2(bool async) async, ss => from g1 in ss.Set() from g2 in ss.Set() - select g1.LeaderNickname != null ? g2.LeaderNickname : (string)null); + select g1.LeaderNickname != null ? g2.LeaderNickname : null); } [ConditionalTheory] @@ -1084,7 +1083,7 @@ public virtual Task Select_null_propagation_negative3(bool async) join g2 in ss.Set() on g1.HasSoulPatch equals true into grouping from g2 in grouping.DefaultIfEmpty() orderby g2.Nickname - select new { g2.Nickname, Condition = g2 != null ? (bool?)(g2.LeaderNickname != null) : (bool?)null }, + select new { g2.Nickname, Condition = g2 != null ? g2.LeaderNickname != null : (bool?)null }, assertOrder: true); } @@ -1292,11 +1291,11 @@ public virtual Task Where_compare_anonymous_types(bool async) ss => from g in ss.Set() from o in ss.Set().OfType() where new - { - Name = g.LeaderNickname, - Squad = g.LeaderSquadId, - Five = 5 - } + { + Name = g.LeaderNickname, + Squad = g.LeaderSquadId, + Five = 5 + } == new { Name = o.Nickname, @@ -1526,7 +1525,9 @@ public virtual Task Where_subquery_join_firstordefault_boolean(bool async) return AssertQuery( async, ss => ss.Set().Where( - g => g.HasSoulPatch && g.Weapons.Join(g.Weapons, e => e.Id, e => e.Id, (e1, e2) => e1).OrderBy(w => w.Id).FirstOrDefault().IsAutomatic)); + g => g.HasSoulPatch + && g.Weapons.Join(g.Weapons, e => e.Id, e => e.Id, (e1, e2) => e1).OrderBy(w => w.Id).FirstOrDefault() + .IsAutomatic)); } [ConditionalTheory] @@ -2315,19 +2316,15 @@ public virtual Task Select_correlated_filtered_collection_with_composite_key(boo [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Select_correlated_filtered_collection_returning_queryable_throws(bool async) + public virtual Task Select_correlated_filtered_collection_returning_queryable_throws(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"t => DbSet() - .Where(g => g.Nickname == t.GearNickName)", typeof(IQueryable).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => ss.Set().OrderBy(t => t.Note).Select(t => ss.Set().Where(g => g.Nickname == t.GearNickName)), - assertOrder: true, - elementAsserter: (e, a) => AssertCollection(e, a)))).Message, - ignoreLineEndingDifferences: true); + return AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => ss.Set().OrderBy(t => t.Note).Select(t => ss.Set().Where(g => g.Nickname == t.GearNickName)), + assertOrder: true, + elementAsserter: (e, a) => AssertCollection(e, a)), + typeof(IQueryable).ShortDisplayName()); } [ConditionalTheory] @@ -3149,8 +3146,7 @@ where f is LocustHorde orderby f.Name select new { - Name = EF.Property(horde, "Name"), - Eradicated = EF.Property((LocustHorde)f, "Eradicated") + Name = EF.Property(horde, "Name"), Eradicated = EF.Property((LocustHorde)f, "Eradicated") }, assertOrder: true); } @@ -3309,7 +3305,7 @@ public virtual Task Comparing_two_collection_navigations_composite_key(bool asyn async, ss => from g1 in ss.Set() from g2 in ss.Set() - // ReSharper disable once PossibleUnintendedReferenceComparison + // ReSharper disable once PossibleUnintendedReferenceComparison where g1.Weapons == g2.Weapons orderby g1.Nickname select new { Nickname1 = g1.Nickname, Nickname2 = g2.Nickname }, @@ -3432,8 +3428,7 @@ public virtual Task Project_collection_navigation_with_inheritance3(bool async) .Select( f => new { - f.Id, - Gears = EF.Property>((Officer)((LocustHorde)f).Commander.DefeatedBy, "Reports") + f.Id, Gears = EF.Property>((Officer)((LocustHorde)f).Commander.DefeatedBy, "Reports") }), elementSorter: e => e.Id, elementAsserter: (e, a) => @@ -5133,21 +5128,16 @@ public virtual Task Join_with_complex_key_selector(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Streaming_correlated_collection_issue_11403_returning_ordered_enumerable_throws(bool async) + public virtual Task Streaming_correlated_collection_issue_11403_returning_ordered_enumerable_throws(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"g => g.Weapons - .Where(w => !(w.IsAutomatic)) - .OrderBy(w => w.Id)", typeof(IOrderedEnumerable).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertFirstOrDefault( - async, - ss => ss.Set() - .OrderBy(g => g.Nickname) - .Select(g => g.Weapons.Where(w => !w.IsAutomatic).OrderBy(w => w.Id)), - asserter: (e, a) => AssertCollection(e, a, ordered: true)))).Message, - ignoreLineEndingDifferences: true); + return AssertInvalidMaterializationType( + () => AssertFirstOrDefault( + async, + ss => ss.Set() + .OrderBy(g => g.Nickname) + .Select(g => g.Weapons.Where(w => !w.IsAutomatic).OrderBy(w => w.Id)), + asserter: (e, a) => AssertCollection(e, a, ordered: true)), + typeof(IOrderedEnumerable).ShortDisplayName()); } [ConditionalTheory] @@ -5947,7 +5937,7 @@ public virtual Task OrderBy_same_expression_containing_IsNull_correctly_deduplic { return AssertQueryScalar( async, - ss => ss.Set().Select(g => g.LeaderNickname != null ? (bool?)(g.Nickname.Length == 5) : (bool?)null) + ss => ss.Set().Select(g => g.LeaderNickname != null ? g.Nickname.Length == 5 : (bool?)null) .OrderBy(e => e.HasValue) .ThenBy(e => e.HasValue).Select(e => e)); } @@ -5986,8 +5976,8 @@ public virtual Task GetValueOrDefault_on_DateTimeOffset(bool async) var defaultValue = default(DateTimeOffset); return AssertQuery( - async, - ss => ss.Set().Where(m => ((DateTimeOffset?)m.Timeline).GetValueOrDefault() == defaultValue)); + async, + ss => ss.Set().Where(m => ((DateTimeOffset?)m.Timeline).GetValueOrDefault() == defaultValue)); } [ConditionalTheory] @@ -7300,7 +7290,7 @@ public virtual Task Checked_context_with_addition_does_not_fail(bool isAsync) { return AssertQuery( isAsync, - ss => ss.Set().Where(w => w.ThreatLevel >= ((int)(long?)5 + (long?)w.ThreatLevel))); + ss => ss.Set().Where(w => w.ThreatLevel >= (5 + (long?)w.ThreatLevel))); } } @@ -7847,11 +7837,7 @@ public virtual Task Correlated_collection_with_inner_collection_references_eleme { o.FullName, Collection = (from r in o.Reports - select new - { - ReportName = r.FullName, - OfficerName = o.FullName - }).ToList() + select new { ReportName = r.FullName, OfficerName = o.FullName }).ToList() }, elementSorter: e => e.FullName, elementAsserter: (e, a) => @@ -7882,7 +7868,6 @@ public virtual Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async, ss => ss.Set().Where(ll => ll.Name.Contains("Queen")).Cast().Include(lc => lc.DefeatedBy), asserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(x => x.DefeatedBy))); - } [ConditionalTheory] @@ -7891,13 +7876,13 @@ public virtual Task Cast_to_derived_followed_by_multiple_includes(bool async) { var expectedIncludes = new IExpectedInclude[] { - new ExpectedInclude(x => x.DefeatedBy), - new ExpectedInclude(x => x.Weapons, "DefeatedBy"), + new ExpectedInclude(x => x.DefeatedBy), new ExpectedInclude(x => x.Weapons, "DefeatedBy"), }; return AssertQuery( async, - ss => ss.Set().Where(ll => ll.Name.Contains("Queen")).Cast().Include(lc => lc.DefeatedBy).ThenInclude(g => g.Weapons), + ss => ss.Set().Where(ll => ll.Name.Contains("Queen")).Cast().Include(lc => lc.DefeatedBy) + .ThenInclude(g => g.Weapons), elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } @@ -7907,7 +7892,13 @@ public virtual Task Correlated_collection_take(bool async) { return AssertQuery( async, - ss => ss.Set().Select(g => new { g.Nickname, Weapons = g.Weapons.Take(10).ToList(), g.CityOfBirth }), + ss => ss.Set().Select( + g => new + { + g.Nickname, + Weapons = g.Weapons.Take(10).ToList(), + g.CityOfBirth + }), elementSorter: e => e.Nickname, elementAsserter: (e, a) => { @@ -7975,11 +7966,7 @@ public virtual Task Project_shadow_properties(bool async) return AssertQuery( async, ss => from g in ss.Set() - select new - { - g.Nickname, - AssignedCityName = EF.Property(g, "AssignedCityName") - }, + select new { g.Nickname, AssignedCityName = EF.Property(g, "AssignedCityName") }, elementSorter: e => e.Nickname); } @@ -8043,11 +8030,19 @@ public virtual Task Projecting_property_converted_to_nullable_with_comparison(bo { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }).Where(x => x.Nullable.SquadId == 1)); + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }).Where(x => x.Nullable.SquadId == 1)); } [ConditionalTheory] @@ -8056,17 +8051,32 @@ public virtual Task Projecting_property_converted_to_nullable_with_addition(bool { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }).Where(x => x.Nullable.SquadId + 1 == 2), - - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }).Where(x => x.Nullable != null && x.Nullable.SquadId + 1 == 2)); + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }).Where(x => x.Nullable.SquadId + 1 == 2), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }).Where(x => x.Nullable != null && x.Nullable.SquadId + 1 == 2)); } [ConditionalTheory] @@ -8075,13 +8085,21 @@ public virtual Task Projecting_property_converted_to_nullable_with_addition_and_ { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .Select(x => new { x.Note, Value = x.Nullable.SquadId + 1 })); + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .Select(x => new { x.Note, Value = x.Nullable.SquadId + 1 })); } [ConditionalTheory] @@ -8090,11 +8108,19 @@ public virtual Task Projecting_property_converted_to_nullable_with_conditional(b { return AssertQueryScalar( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }).Select(x => x.Note != "K.I.A." ? x.Nullable.SquadId : -1)); + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }).Select(x => x.Note != "K.I.A." ? x.Nullable.SquadId : -1)); } [ConditionalTheory] @@ -8103,11 +8129,19 @@ public virtual Task Projecting_property_converted_to_nullable_with_function_call { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }).Select(x => x.Nullable.Nickname.Substring(0, 3)), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }).Select(x => x.Nullable.Nickname.Substring(0, 3)), ss => ss.Set().Select(x => x.GearNickName == null ? null : x.GearNickName.Substring(0, 3))); } @@ -8117,20 +8151,36 @@ public virtual Task Projecting_property_converted_to_nullable_with_function_call { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .Select(x => new { x.Note, Function = x.Note.Substring(0, x.Nullable.SquadId) }), - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .Select(x => new { x.Note, Function = x.Nullable == null ? null : x.Note.Substring(0, x.Nullable.SquadId) })); + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .Select(x => new { x.Note, Function = x.Note.Substring(0, x.Nullable.SquadId) }), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .Select(x => new { x.Note, Function = x.Nullable == null ? null : x.Note.Substring(0, x.Nullable.SquadId) })); } [ConditionalTheory] @@ -8139,20 +8189,29 @@ public virtual Task Projecting_property_converted_to_nullable_into_element_init( { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .OrderBy(x => x.Note) - .Select(x => new List - { - x.Nullable.Nickname.Length, - x.Nullable.SquadId, - x.Nullable.SquadId + 1, - 42 - }), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .OrderBy(x => x.Note) + .Select( + x => new List + { + x.Nullable.Nickname.Length, + x.Nullable.SquadId, + x.Nullable.SquadId + 1, + 42 + }), assertOrder: true); } @@ -8162,14 +8221,22 @@ public virtual Task Projecting_property_converted_to_nullable_into_member_assign { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .OrderBy(x => x.Note) - .Select(x => new Squad { Id = x.Nullable.SquadId }), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .OrderBy(x => x.Note) + .Select(x => new Squad { Id = x.Nullable.SquadId }), assertOrder: true); } @@ -8179,14 +8246,22 @@ public virtual Task Projecting_property_converted_to_nullable_into_new_array(boo { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .OrderBy(x => x.Note) - .Select(x => new int[] { x.Nullable.Nickname.Length, x.Nullable.SquadId, x.Nullable.SquadId + 1, 42 }), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .OrderBy(x => x.Note) + .Select(x => new[] { x.Nullable.Nickname.Length, x.Nullable.SquadId, x.Nullable.SquadId + 1, 42 }), assertOrder: true); } @@ -8196,15 +8271,23 @@ public virtual Task Projecting_property_converted_to_nullable_into_unary(bool as { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .OrderBy(x => x.Note) - .Where(x => !x.Nullable.HasSoulPatch) - .Select(x => x.Note), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .OrderBy(x => x.Note) + .Where(x => !x.Nullable.HasSoulPatch) + .Select(x => x.Note), assertOrder: true); } @@ -8214,16 +8297,17 @@ public virtual Task Projecting_property_converted_to_nullable_into_member_access { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Nickname, - x.CityOfBirthName, - Nullable = x.CityOfBirthName != null ? new { x.Tag.IssueDate } : null - }) - .Where(x => x.CityOfBirthName != null) - .OrderBy(x => x.Nickname) - .Where(x => x.Nullable.IssueDate.Month != 5) - .Select(x => x.Nickname), + ss => ss.Set().Select( + x => new + { + x.Nickname, + x.CityOfBirthName, + Nullable = x.CityOfBirthName != null ? new { x.Tag.IssueDate } : null + }) + .Where(x => x.CityOfBirthName != null) + .OrderBy(x => x.Nickname) + .Where(x => x.Nullable.IssueDate.Month != 5) + .Select(x => x.Nickname), assertOrder: true); } @@ -8233,13 +8317,21 @@ public virtual Task Projecting_property_converted_to_nullable_and_use_it_in_orde { return AssertQuery( async, - ss => ss.Set().Select(x => new - { - x.Note, - Nullable = x.GearNickName != null ? new { x.Gear.Nickname, x.Gear.SquadId, x.Gear.HasSoulPatch } : null - }) - .Where(x => x.Nullable.Nickname != null) - .OrderBy(x => x.Nullable.SquadId).ThenBy(x => x.Note), + ss => ss.Set().Select( + x => new + { + x.Note, + Nullable = x.GearNickName != null + ? new + { + x.Gear.Nickname, + x.Gear.SquadId, + x.Gear.HasSoulPatch + } + : null + }) + .Where(x => x.Nullable.Nickname != null) + .OrderBy(x => x.Nullable.SquadId).ThenBy(x => x.Note), assertOrder: true); } @@ -8286,7 +8378,13 @@ public virtual Task Correlated_collection_with_distinct_projecting_identifier_co { Key = g.Nickname, Subquery = g.Weapons - .Select(w => new { w.Id, w.Name, w.OwnerFullName }) + .Select( + w => new + { + w.Id, + w.Name, + w.OwnerFullName + }) .Distinct().ToList() }), elementSorter: e => e.Key, @@ -8306,7 +8404,6 @@ public virtual Task Correlated_collection_with_distinct_projecting_identifier_co }); } - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_collection_with_distinct_projecting_identifier_column_composite_key(bool async) @@ -8319,7 +8416,13 @@ public virtual Task Correlated_collection_with_distinct_projecting_identifier_co { Key = s.Id, Subquery = s.Members - .Select(m => new { m.Nickname, m.SquadId, m.HasSoulPatch }) + .Select( + m => new + { + m.Nickname, + m.SquadId, + m.HasSoulPatch + }) .Distinct().ToList() }), elementSorter: e => e.Key, @@ -8372,7 +8475,8 @@ public virtual Task Correlated_collection_with_distinct_not_projecting_identifie [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Correlated_collection_with_distinct_not_projecting_identifier_column_also_projecting_complex_expressions(bool async) + public virtual Task Correlated_collection_with_distinct_not_projecting_identifier_column_also_projecting_complex_expressions( + bool async) { return AssertQuery( async, @@ -8382,7 +8486,13 @@ public virtual Task Correlated_collection_with_distinct_not_projecting_identifie { Key = g.Nickname, Subquery = g.Weapons - .Select(w => new { w.Name, w.IsAutomatic, w.OwnerFullName.Length }) + .Select( + w => new + { + w.Name, + w.IsAutomatic, + w.OwnerFullName.Length + }) .Distinct().ToList() }), elementSorter: e => e.Key, @@ -8404,7 +8514,8 @@ public virtual Task Correlated_collection_with_distinct_not_projecting_identifie [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Correlated_collection_with_groupby_not_projecting_identifier_column_but_only_grouping_key_in_final_projection(bool async) + public virtual Task Correlated_collection_with_groupby_not_projecting_identifier_column_but_only_grouping_key_in_final_projection( + bool async) { return AssertQuery( async, @@ -8435,7 +8546,8 @@ public virtual Task Correlated_collection_with_groupby_not_projecting_identifier [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Correlated_collection_with_groupby_not_projecting_identifier_column_with_group_aggregate_in_final_projection(bool async) + public virtual Task Correlated_collection_with_groupby_not_projecting_identifier_column_with_group_aggregate_in_final_projection( + bool async) { return AssertQuery( async, @@ -8467,7 +8579,9 @@ public virtual Task Correlated_collection_with_groupby_not_projecting_identifier [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Correlated_collection_with_groupby_not_projecting_identifier_column_with_group_aggregate_in_final_projection_multiple_grouping_keys(bool async) + public virtual Task + Correlated_collection_with_groupby_not_projecting_identifier_column_with_group_aggregate_in_final_projection_multiple_grouping_keys( + bool async) { return AssertQuery( async, @@ -8500,7 +8614,9 @@ public virtual Task Correlated_collection_with_groupby_not_projecting_identifier [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Correlated_collection_with_groupby_with_complex_grouping_key_not_projecting_identifier_column_with_group_aggregate_in_final_projection(bool async) + public virtual Task + Correlated_collection_with_groupby_with_complex_grouping_key_not_projecting_identifier_column_with_group_aggregate_in_final_projection( + bool async) { return AssertQuery( async, @@ -8538,12 +8654,14 @@ public virtual Task Correlated_collection_via_SelectMany_with_Distinct_missing_i async, ss => ss.Set() .OrderBy(g => g.Nickname) - .Select(g => g.Weapons.SelectMany(x => x.Owner.AssignedCity.BornGears) - .Select(x => (bool?)x.HasSoulPatch).Distinct().ToList()), + .Select( + g => g.Weapons.SelectMany(x => x.Owner.AssignedCity.BornGears) + .Select(x => (bool?)x.HasSoulPatch).Distinct().ToList()), ss => ss.Set() .OrderBy(g => g.Nickname) - .Select(g => g.Weapons.SelectMany(x => x.Owner.AssignedCity.Maybe(x => x.BornGears) ?? new List()) - .Select(x => (bool?)x.HasSoulPatch).Distinct().ToList()), + .Select( + g => g.Weapons.SelectMany(x => x.Owner.AssignedCity.Maybe(x => x.BornGears) ?? new List()) + .Select(x => (bool?)x.HasSoulPatch).Distinct().ToList()), elementAsserter: (e, a) => AssertCollection(e, a, elementSorter: ee => ee), assertOrder: true); } @@ -8568,7 +8686,13 @@ public virtual Task Projecting_some_properties_as_well_as_correlated_collection_ return AssertQuery( async, ss => ss.Set() - .Select(g => new { g.FullName, g.HasSoulPatch, g.Weapons }) + .Select( + g => new + { + g.FullName, + g.HasSoulPatch, + g.Weapons + }) .Distinct(), elementSorter: e => e.FullName, elementAsserter: (e, a) => @@ -8637,15 +8761,13 @@ public virtual Task Correlated_collection_with_distinct_3_levels(bool async) return AssertQuery( async, ss => ss.Set() - .Select(s => new - { - s, - Members = s.Members.Select(m => new + .Select( + s => new { - m, - Weapons = m.Weapons.Where(w => w.OwnerFullName == m.FullName).ToList() - }).Distinct() - }).Distinct(), + s, + Members = s.Members.Select( + m => new { m, Weapons = m.Weapons.Where(w => w.OwnerFullName == m.FullName).ToList() }).Distinct() + }).Distinct(), elementSorter: e => e.s.Id); } @@ -8658,25 +8780,39 @@ public virtual Task Correlated_collection_after_distinct_3_levels(bool async) ss => ss.Set() .Select(s => new { s.Id, s.Name }) .Distinct() - .Select(x => new - { - x.Id, - x.Name, - Subquery1 = (from g in ss.Set() - where g.SquadId == x.Id - select new { g.Nickname, g.FullName, g.HasSoulPatch }) - .Distinct() - .Select(xx => new - { - xx.Nickname, - xx.FullName, - xx.HasSoulPatch, - Subquery2 = (from w in ss.Set() - where w.OwnerFullName == xx.FullName - select new { x.Id, x.Name, xx.Nickname, xx.FullName, xx.HasSoulPatch }).ToList() - }) - .ToList() - }), + .Select( + x => new + { + x.Id, + x.Name, + Subquery1 = (from g in ss.Set() + where g.SquadId == x.Id + select new + { + g.Nickname, + g.FullName, + g.HasSoulPatch + }) + .Distinct() + .Select( + xx => new + { + xx.Nickname, + xx.FullName, + xx.HasSoulPatch, + Subquery2 = (from w in ss.Set() + where w.OwnerFullName == xx.FullName + select new + { + x.Id, + x.Name, + xx.Nickname, + xx.FullName, + xx.HasSoulPatch + }).ToList() + }) + .ToList() + }), elementSorter: e => e.Id, elementAsserter: (e, a) => { @@ -8716,22 +8852,29 @@ public virtual Task Correlated_collection_after_distinct_3_levels_without_origin ss => ss.Set() .Select(s => new { s.Name.Length }) .Distinct() - .Select(x => new - { - x.Length, - Subquery1 = (from g in ss.Set() - where g.Nickname.Length == x.Length - select new { g.HasSoulPatch, g.CityOfBirthName }) - .Distinct() - .Select(xx => new - { - xx.HasSoulPatch, - Subquery2 = (from w in ss.Set() - where w.OwnerFullName == xx.CityOfBirthName - select new { w.Id, x.Length, xx.HasSoulPatch }).ToList() - }) - .ToList() - }), + .Select( + x => new + { + x.Length, + Subquery1 = (from g in ss.Set() + where g.Nickname.Length == x.Length + select new { g.HasSoulPatch, g.CityOfBirthName }) + .Distinct() + .Select( + xx => new + { + xx.HasSoulPatch, + Subquery2 = (from w in ss.Set() + where w.OwnerFullName == xx.CityOfBirthName + select new + { + w.Id, + x.Length, + xx.HasSoulPatch + }).ToList() + }) + .ToList() + }), elementSorter: e => e.Length, elementAsserter: (e, a) => { @@ -8945,11 +9088,7 @@ public virtual Task Include_on_entity_that_is_not_present_in_final_projection_bu ss => ss.Set() .Include(x => x.Weapons) .Include(x => x.Tag) - .Select(g => new - { - g.Nickname, - IsOfficer = g is Officer - }), + .Select(g => new { g.Nickname, IsOfficer = g is Officer }), elementSorter: e => e.Nickname, elementAsserter: (e, a) => { @@ -8984,50 +9123,52 @@ public virtual Task Project_navigation_defined_on_base_from_entity_with_inherita { return AssertQuery( async, - ss => ss.Set().Select(g => new - { - Gear = g, - Tag = (g as Officer).Tag, - IsNull = (g as Officer).Tag == null, - Property = (g as Officer).Nickname, - PropertyAfterNavigation = (g as Officer).Tag.Id, - NestedOuter = new + ss => ss.Set().Select( + g => new { - CityOfBirth = (g as Officer).CityOfBirth, - IsNull = (g as Officer).CityOfBirth == null, + Gear = g, + (g as Officer).Tag, + IsNull = (g as Officer).Tag == null, Property = (g as Officer).Nickname, - PropertyAfterNavigation = (g as Officer).CityOfBirth.Name, - NestedInner = new + PropertyAfterNavigation = (g as Officer).Tag.Id, + NestedOuter = new { - Squad = (g as Officer).Squad, - IsNull = (g as Officer).Squad == null, + (g as Officer).CityOfBirth, + IsNull = (g as Officer).CityOfBirth == null, Property = (g as Officer).Nickname, - PropertyAfterNavigation = (g as Officer).Squad.Id + PropertyAfterNavigation = (g as Officer).CityOfBirth.Name, + NestedInner = new + { + (g as Officer).Squad, + IsNull = (g as Officer).Squad == null, + Property = (g as Officer).Nickname, + PropertyAfterNavigation = (g as Officer).Squad.Id + } } - } - }), - ss => ss.Set().Select(g => new - { - Gear = g, - Tag = g.Tag, - IsNull = g.Tag == null, - Property = g.Nickname, - PropertyAfterNavigation = g.Tag.Id, - NestedOuter = new + }), + ss => ss.Set().Select( + g => new { - CityOfBirth = g.CityOfBirth, - IsNull = g.CityOfBirth == null, + Gear = g, + g.Tag, + IsNull = g.Tag == null, Property = g.Nickname, - PropertyAfterNavigation = g.CityOfBirth.Name, - NestedInner = new + PropertyAfterNavigation = g.Tag.Id, + NestedOuter = new { - Squad = g.Squad, - IsNull = g.Squad == null, + g.CityOfBirth, + IsNull = g.CityOfBirth == null, Property = g.Nickname, - PropertyAfterNavigation = g.Squad.Id + PropertyAfterNavigation = g.CityOfBirth.Name, + NestedInner = new + { + g.Squad, + IsNull = g.Squad == null, + Property = g.Nickname, + PropertyAfterNavigation = g.Squad.Id + } } - } - }), + }), elementSorter: e => e.Gear.Nickname, elementAsserter: (e, a) => { @@ -9055,50 +9196,52 @@ public virtual Task Project_navigation_defined_on_derived_from_entity_with_inher { return AssertQuery( async, - ss => ss.Set().Select(l => new - { - Leader = l, - DefeatedBy = (l as LocustCommander).DefeatedBy, - IsNull = (l as LocustCommander).DefeatedBy == null, - Property = (l as LocustCommander).DefeatedByNickname, - PropertyAfterNavigation = (bool?)(l as LocustCommander).DefeatedBy.HasSoulPatch, - NestedOuter = new + ss => ss.Set().Select( + l => new { - CommandingFaction = (l as LocustCommander).CommandingFaction, - IsNull = (l as LocustCommander).CommandingFaction == null, - Property = (int?)(l as LocustCommander).HighCommandId, - PropertyAfterNavigation = (l as LocustCommander).CommandingFaction.Eradicated, - NestedInner = new + Leader = l, + (l as LocustCommander).DefeatedBy, + IsNull = (l as LocustCommander).DefeatedBy == null, + Property = (l as LocustCommander).DefeatedByNickname, + PropertyAfterNavigation = (bool?)(l as LocustCommander).DefeatedBy.HasSoulPatch, + NestedOuter = new { - HighCommand = (l as LocustCommander).HighCommand, - IsNull = (l as LocustCommander).HighCommand == null, - Property = (l as LocustCommander).DefeatedBySquadId, - PropertyAfterNavigation = (l as LocustCommander).HighCommand.Name + (l as LocustCommander).CommandingFaction, + IsNull = (l as LocustCommander).CommandingFaction == null, + Property = (int?)(l as LocustCommander).HighCommandId, + PropertyAfterNavigation = (l as LocustCommander).CommandingFaction.Eradicated, + NestedInner = new + { + (l as LocustCommander).HighCommand, + IsNull = (l as LocustCommander).HighCommand == null, + Property = (l as LocustCommander).DefeatedBySquadId, + PropertyAfterNavigation = (l as LocustCommander).HighCommand.Name + } } - } - }), - ss => ss.Set().Select(l => new - { - Leader = l, - DefeatedBy = (l as LocustCommander).DefeatedBy, - IsNull = (l as LocustCommander).DefeatedBy == null, - Property = (l as LocustCommander).DefeatedByNickname, - PropertyAfterNavigation = (bool?)(l as LocustCommander).DefeatedBy.HasSoulPatch, - NestedOuter = new + }), + ss => ss.Set().Select( + l => new { - CommandingFaction = (l as LocustCommander).CommandingFaction, - IsNull = (l as LocustCommander).CommandingFaction == null, - Property = (int?)(l as LocustCommander).HighCommandId, - PropertyAfterNavigation = (l as LocustCommander).CommandingFaction.MaybeScalar(x => x.Eradicated), - NestedInner = new + Leader = l, + (l as LocustCommander).DefeatedBy, + IsNull = (l as LocustCommander).DefeatedBy == null, + Property = (l as LocustCommander).DefeatedByNickname, + PropertyAfterNavigation = (bool?)(l as LocustCommander).DefeatedBy.HasSoulPatch, + NestedOuter = new { - HighCommand = (l as LocustCommander).HighCommand, - IsNull = (l as LocustCommander).HighCommand == null, - Property = (l as LocustCommander).MaybeScalar(x => x.DefeatedBySquadId), - PropertyAfterNavigation = (l as LocustCommander).HighCommand.Name + (l as LocustCommander).CommandingFaction, + IsNull = (l as LocustCommander).CommandingFaction == null, + Property = (int?)(l as LocustCommander).HighCommandId, + PropertyAfterNavigation = (l as LocustCommander).CommandingFaction.MaybeScalar(x => x.Eradicated), + NestedInner = new + { + (l as LocustCommander).HighCommand, + IsNull = (l as LocustCommander).HighCommand == null, + Property = (l as LocustCommander).MaybeScalar(x => x.DefeatedBySquadId), + PropertyAfterNavigation = (l as LocustCommander).HighCommand.Name + } } - } - }), + }), elementSorter: e => e.Leader.Name, elementAsserter: (e, a) => { @@ -9125,7 +9268,8 @@ public virtual Task Join_entity_with_itself_grouped_by_key_followed_by_include_s return AssertQuery( async, ss => (from g1 in ss.Set() - join g2 in ss.Set().Where(x => x.Nickname != "Dom").GroupBy(x => x.HasSoulPatch).Select(g => g.Min(x => x.Nickname.Length)) on g1.Nickname.Length equals g2 + join g2 in ss.Set().Where(x => x.Nickname != "Dom").GroupBy(x => x.HasSoulPatch) + .Select(g => g.Min(x => x.Nickname.Length)) on g1.Nickname.Length equals g2 select g1).Include(x => x.Weapons).OrderBy(x => x.Nickname).Skip(0).Take(10)); } diff --git a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs index 6f89bffc442..3a2b0db3b03 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; @@ -38,15 +37,19 @@ public virtual Task GroupBy_Property_Select_Average(bool async) ss => ss.Set().GroupBy(o => o.CustomerID).Select(g => g.Average(o => o.OrderID))); } - [ConditionalTheory(Skip = "issue #18923")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_Property_Select_Average_with_group_enumerable_projected(bool async) { - return AssertQueryScalar( - async, - ss => ss.Set().Where(o => o.Customer.City != "London") - .GroupBy(o => o.CustomerID, (k, es) => new { k, es }) - .Select(g => g.es.Average(o => o.OrderID))); + // Select with aggregate after grouping. Issue #18923. + + return AssertTranslationFailed( + () => + AssertQueryScalar( + async, + ss => ss.Set().Where(o => o.Customer.City != "London") + .GroupBy(o => o.CustomerID, (k, es) => new { k, es }) + .Select(g => g.es.Average(o => o.OrderID)))); } [ConditionalTheory] @@ -1123,14 +1126,11 @@ public virtual Task Odata_groupby_empty_key(bool async) return AssertQuery( async, ss => ss.Set().GroupBy(e => new NoGroupByWrapper()) - .Select(e => new NoGroupByAggregationWrapper - { - Container = new LastInChain + .Select( + e => new NoGroupByAggregationWrapper { - Name = "TotalAmount", - Value = (object)((IEnumerable)e).Sum(e => (decimal)e.OrderID) - } - }), + Container = new LastInChain { Name = "TotalAmount", Value = e.Sum(e => (decimal)e.OrderID) } + }), assertOrder: true, elementAsserter: (e, a) => { @@ -1144,7 +1144,7 @@ public override bool Equals(object obj) { return obj != null && (ReferenceEquals(this, obj) - || obj is NoGroupByWrapper); + || obj is NoGroupByWrapper); } public override int GetHashCode() @@ -1367,10 +1367,9 @@ public virtual Task Element_selector_with_case_block_repeated_inside_another_cas async, ss => from order in ss.Set() group new - { - IsAlfki = order.CustomerID == "ALFKI", - OrderId = order.OrderID > 1000 ? order.OrderID : -order.OrderID - } by + { + IsAlfki = order.CustomerID == "ALFKI", OrderId = order.OrderID > 1000 ? order.OrderID : -order.OrderID + } by new { order.OrderID } into g select new { g.Key.OrderID, Aggregate = g.Sum(s => s.IsAlfki ? s.OrderId : -s.OrderId) }); @@ -1917,9 +1916,9 @@ public virtual Task GroupBy_Aggregate_Join_converted_from_SelectMany(bool async) async, ss => from c in ss.Set() from o in ss.Set().GroupBy(o => o.CustomerID) - .Where(g => g.Count() > 5) - .Select(g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) }) - .Where(c1 => c.CustomerID == c1.CustomerID) + .Where(g => g.Count() > 5) + .Select(g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) }) + .Where(c1 => c.CustomerID == c1.CustomerID) select c, entryCount: 63); } @@ -1932,10 +1931,10 @@ public virtual Task GroupBy_Aggregate_LeftJoin_converted_from_SelectMany(bool as async, ss => from c in ss.Set() from o in ss.Set().GroupBy(o => o.CustomerID) - .Where(g => g.Count() > 5) - .Select(g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) }) - .Where(c1 => c.CustomerID == c1.CustomerID) - .DefaultIfEmpty() + .Where(g => g.Count() > 5) + .Select(g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) }) + .Where(c1 => c.CustomerID == c1.CustomerID) + .DefaultIfEmpty() select c, entryCount: 91); } @@ -2160,11 +2159,12 @@ public virtual Task Select_uncorrelated_collection_with_groupby_multiple_collect ss => ss.Set() .Where(c => c.CustomerID.StartsWith("A")) .Select(c => c.Customer.City) - .Select(c => new - { - c1 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Key).ToArray(), - c2 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Count()).ToArray() - }), + .Select( + c => new + { + c1 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Key).ToArray(), + c2 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Count()).ToArray() + }), assertOrder: true, elementAsserter: (e, a) => { @@ -2324,18 +2324,22 @@ public virtual Task GroupBy_orderby_projection_with_coalesce_operation(bool asyn .Select(x => new { Locality = x.Key ?? "Unknown", Count = x.Count() })); } - [ConditionalTheory(Skip = "issue #18923")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_let_orderby_projection_with_coalesce_operation(bool async) { - return AssertQuery( - async, - ss => ss.Set() - .GroupBy(c => c.City) - .Select(g => new { citiesCount = g.Count(), g }) - .OrderByDescending(x => x.citiesCount) - .ThenBy(x => x.g.Key) - .Select(x => new { Locality = x.g.Key ?? "Unknown", Count = x.citiesCount })); + // Select with grouping. Issue #18923. + + return AssertTranslationFailedWithDetails( + () => AssertQuery( + async, + ss => ss.Set() + .GroupBy(c => c.City) + .Select(g => new { citiesCount = g.Count(), g }) + .OrderByDescending(x => x.citiesCount) + .ThenBy(x => x.g.Key) + .Select(x => new { Locality = x.g.Key ?? "Unknown", Count = x.citiesCount })), + CoreStrings.QuerySelectContainsGrouping); } [ConditionalTheory] @@ -2509,7 +2513,8 @@ public virtual async Task GroupBy_aggregate_SelectMany(bool async) () => AssertQuery( async, ss => from o in ss.Set() - group o by o.CustomerID into g + group o by o.CustomerID + into g let id = g.Min(x => x.OrderID) from o in ss.Set() where o.OrderID == id @@ -2528,7 +2533,8 @@ public virtual Task GroupBy_aggregate_without_selectMany_selecting_first(bool as async, ss => from id in (from o in ss.Set() - group o by o.CustomerID into g + group o by o.CustomerID + into g select g.Min(x => x.OrderID)) from o in ss.Set() where o.OrderID == id @@ -2733,8 +2739,7 @@ public virtual Task GroupBy_group_Distinct_Select_Distinct_aggregate(bool async) g => new { - g.Key, - Max = g.Distinct().Select(e => e.OrderDate).Distinct().Max(), + g.Key, Max = g.Distinct().Select(e => e.OrderDate).Distinct().Max(), }), elementSorter: e => e.Key); } @@ -2751,8 +2756,7 @@ public virtual Task GroupBy_group_Where_Select_Distinct_aggregate(bool async) g => new { - g.Key, - Max = g.Where(e => e.OrderDate.HasValue).Select(e => e.OrderDate).Distinct().Max(), + g.Key, Max = g.Where(e => e.OrderDate.HasValue).Select(e => e.OrderDate).Distinct().Max(), }), elementSorter: e => e.Key); } @@ -2765,73 +2769,80 @@ public virtual Task GroupBy_group_Where_Select_Distinct_aggregate(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_as_final_operator(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().GroupBy(c => c.City))); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_Where_with_grouping_result(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().GroupBy(c => c.City).Where(e => e.Key.StartsWith("s")))); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City).Where(e => e.Key.StartsWith("s")))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_OrderBy_with_grouping_result(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().GroupBy(c => c.City).OrderBy(e => e.Key), - assertOrder: true)); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City).OrderBy(e => e.Key), + assertOrder: true)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_SelectMany(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().GroupBy(c => c.City).SelectMany(g => g), - entryCount: 91)); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City).SelectMany(g => g), + entryCount: 91)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task OrderBy_GroupBy_SelectMany(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().OrderBy(o => o.OrderID) - .GroupBy(o => o.CustomerID) - .SelectMany(g => g), - entryCount: 830)); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().OrderBy(o => o.OrderID) + .GroupBy(o => o.CustomerID) + .SelectMany(g => g), + entryCount: 830)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task OrderBy_GroupBy_SelectMany_shadow(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().OrderBy(e => e.EmployeeID) - .GroupBy(e => e.EmployeeID) - .SelectMany(g => g) - .Select(g => EF.Property(g, "Title")))); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().OrderBy(e => e.EmployeeID) + .GroupBy(e => e.EmployeeID) + .SelectMany(g => g) + .Select(g => EF.Property(g, "Title")))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_with_orderby_take_skip_distinct_followed_by_group_key_projection(bool async) { - return AssertTranslationFailed(() => AssertQuery( - async, - ss => ss.Set().GroupBy(o => o.CustomerID).OrderBy(g => g.Key).Take(5).Skip(3).Distinct().Select(g => g.Key), - assertOrder: true, - entryCount: 31)); + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().GroupBy(o => o.CustomerID).OrderBy(g => g.Key).Take(5).Skip(3).Distinct().Select(g => g.Key), + assertOrder: true, + entryCount: 31)); } [ConditionalTheory] @@ -2958,80 +2969,95 @@ public virtual Task GroupBy_select_grouping_composed_list_2(bool async) #region GroupByEntityType - [ConditionalTheory(Skip = "Issue #18923")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_GroupBy_SelectMany(bool async) { - return AssertQuery( - async, - ss => ss.Set().Select( - o => new ProjectedType { Order = o.OrderID, Customer = o.CustomerID }) - .GroupBy(p => p.Customer) - .SelectMany(g => g), - elementSorter: g => g.Order); + // Entity equality. Issue #15938. + + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set().Select( + o => new ProjectedType { Order = o.OrderID, Customer = o.CustomerID }) + .GroupBy(p => p.Customer) + .SelectMany(g => g), + elementSorter: g => g.Order)); } - [ConditionalTheory(Skip = "issue #15938")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_with_group_key_being_navigation(bool async) { - return AssertQuery( - async, - ss => ss.Set() - .GroupBy(od => od.Order) - .Select(g => new { g.Key, Aggregate = g.Sum(od => od.OrderID) }), - elementSorter: e => e.Key); + // Entity equality. Issue #15938. + + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set() + .GroupBy(od => od.Order) + .Select(g => new { g.Key, Aggregate = g.Sum(od => od.OrderID) }), + elementSorter: e => e.Key)); } - [ConditionalTheory(Skip = "issue #15938")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_with_group_key_being_nested_navigation(bool async) { - return AssertQuery( - async, - ss => ss.Set() - .GroupBy(od => od.Order.Customer) - .Select(g => new { g.Key, Aggregate = g.Sum(od => od.OrderID) }), - elementSorter: e => e.Key); + // Entity equality. Issue #15938. + + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set() + .GroupBy(od => od.Order.Customer) + .Select(g => new { g.Key, Aggregate = g.Sum(od => od.OrderID) }), + elementSorter: e => e.Key)); } - [ConditionalTheory(Skip = "issue #15938")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_with_group_key_being_navigation_with_entity_key_projection(bool async) { - return AssertQuery( - async, - ss => ss.Set() - .GroupBy(od => od.Order) - .Select(g => g.Key)); + // Entity equality. Issue #15938. + + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set() + .GroupBy(od => od.Order) + .Select(g => g.Key))); } - [ConditionalTheory(Skip = "issue #15938")] + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_with_group_key_being_navigation_with_complex_projection(bool async) { - return AssertQuery( - async, - ss => ss.Set() - .GroupBy(od => od.Order) - .Select( - g => new - { - g.Key, - Id1 = g.Key.CustomerID, - Id2 = g.Key.Customer.CustomerID, - Id3 = g.Key.OrderID, - Aggregate = g.Sum(od => od.OrderID) - }), - elementSorter: e => e.Id3, - elementAsserter: (e, a) => - { - AssertEqual(e.Key, a.Key); - Assert.Equal(e.Id1, a.Id1); - Assert.Equal(e.Id2, a.Id2); - Assert.Equal(e.Id3, a.Id3); - Assert.Equal(e.Aggregate, a.Aggregate); - }); + // Entity equality. Issue #15938. + + return AssertTranslationFailed( + () => AssertQuery( + async, + ss => ss.Set() + .GroupBy(od => od.Order) + .Select( + g => new + { + g.Key, + Id1 = g.Key.CustomerID, + Id2 = g.Key.Customer.CustomerID, + Id3 = g.Key.OrderID, + Aggregate = g.Sum(od => od.OrderID) + }), + elementSorter: e => e.Id3, + elementAsserter: (e, a) => + { + AssertEqual(e.Key, a.Key); + Assert.Equal(e.Id1, a.Id1); + Assert.Equal(e.Id2, a.Id2); + Assert.Equal(e.Id3, a.Id3); + Assert.Equal(e.Aggregate, a.Aggregate); + })); } #endregion @@ -3164,18 +3190,15 @@ public virtual Task GroupBy_aggregate_followed_by_another_GroupBy_aggregate(bool return AssertQuery( async, ss => ss.Set().GroupBy(o => o.CustomerID) - .Select(g => new - { - g.Key, - Count = g.Count(), - LastOrder = g.Max(e => e.OrderID) - }) + .Select( + g => new + { + g.Key, + Count = g.Count(), + LastOrder = g.Max(e => e.OrderID) + }) .GroupBy(e => 1) - .Select(g => new - { - g.Key, - Count = g.Sum(e => e.Count) - })); + .Select(g => new { g.Key, Count = g.Sum(e => e.Count) })); } [ConditionalTheory] @@ -3186,18 +3209,15 @@ public virtual Task GroupBy_Count_in_projection(bool async) async, ss => ss.Set() .Where(o => o.OrderDate.HasValue) - .Select(o => new - { - o, - OrderDetails = o.OrderDetails.Where(od => od.ProductID < 25) - }) - .Select(info => new - { - info.o.OrderID, - info.o.OrderDate, - HasOrderDetails = info.OrderDetails.Any(), - HasMultipleProducts = info.OrderDetails.GroupBy(e => e.Product.ProductName).Count() > 1 - })); + .Select(o => new { o, OrderDetails = o.OrderDetails.Where(od => od.ProductID < 25) }) + .Select( + info => new + { + info.o.OrderID, + info.o.OrderDate, + HasOrderDetails = info.OrderDetails.Any(), + HasMultipleProducts = info.OrderDetails.GroupBy(e => e.Product.ProductName).Count() > 1 + })); } #endregion @@ -3308,7 +3328,8 @@ public virtual Task Complex_query_with_group_by_in_subquery5(bool async) async, ss => from od in ss.Set() where od.Order.Customer.CustomerID == "ALFKI" - group od by od.ProductID into grouping + group od by od.ProductID + into grouping select new { Sum = grouping.Sum(x => x.ProductID + x.OrderID * 1000), @@ -3366,16 +3387,17 @@ public virtual Task AsEnumerable_in_subquery_for_GroupBy(bool async) async, ss => ss.Set() .Where(c => c.CustomerID.StartsWith("F")) - .Select(c => new - { - Customer = c, - Orders = ss.Set() - .Where(o => o.CustomerID == c.CustomerID) - .AsEnumerable() - .GroupBy(o => o.CustomerID) - .Select(g => g.OrderByDescending(e => e.OrderDate).FirstOrDefault()) - .ToList() - }), + .Select( + c => new + { + Customer = c, + Orders = ss.Set() + .Where(o => o.CustomerID == c.CustomerID) + .AsEnumerable() + .GroupBy(o => o.CustomerID) + .Select(g => g.OrderByDescending(e => e.OrderDate).FirstOrDefault()) + .ToList() + }), elementSorter: e => e.Customer.CustomerID, elementAsserter: (e, a) => { @@ -3399,11 +3421,12 @@ public virtual Task Select_uncorrelated_collection_with_groupby_when_outer_is_di .Where(c => c.CustomerID.StartsWith("A")) .Select(c => c.Customer.City) .Distinct() - .Select(c => new - { - c1 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Key).ToArray(), - c2 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Count()).ToArray() - }), + .Select( + c => new + { + c1 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Key).ToArray(), + c2 = ss.Set().GroupBy(p => p.ProductID).Select(g => g.Count()).ToArray() + }), assertOrder: true, elementAsserter: (e, a) => { @@ -3422,11 +3445,7 @@ public virtual Task Select_correlated_collection_after_GroupBy_aggregate_when_id .GroupBy(e => e.CustomerID) .Where(g => g.Key.StartsWith("F")) .Select(e => e.Key) - .Select(c => new - { - c, - Orders = ss.Set().Where(o => o.CustomerID == c).ToList() - }), + .Select(c => new { c, Orders = ss.Set().Where(o => o.CustomerID == c).ToList() }), elementSorter: e => e.c, elementAsserter: (e, a) => { @@ -3446,11 +3465,7 @@ public virtual Task Select_correlated_collection_after_GroupBy_aggregate_when_id .GroupBy(e => e.CustomerID) .Where(g => g.Key.StartsWith("F")) .Select(e => e.Key) - .Select(c => new - { - c, - Orders = ss.Set().Where(o => o.CustomerID == c).ToList() - }), + .Select(c => new { c, Orders = ss.Set().Where(o => o.CustomerID == c).ToList() }), elementSorter: e => e.c, elementAsserter: (e, a) => { @@ -3470,11 +3485,7 @@ public virtual Task Select_correlated_collection_after_GroupBy_aggregate_when_id .GroupBy(e => e.CustomerID + "A") .Where(g => g.Key.StartsWith("F")) .Select(e => e.Key) - .Select(c => new - { - c, - Orders = ss.Set().Where(o => o.CustomerID + "A" == c).ToList() - }), + .Select(c => new { c, Orders = ss.Set().Where(o => o.CustomerID + "A" == c).ToList() }), elementSorter: e => e.c, elementAsserter: (e, a) => { diff --git a/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs index 6d570fdea50..d0b0809fbdc 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs @@ -17,7 +17,6 @@ #pragma warning disable RCS1202 // Avoid NullReferenceException. -// ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Query { public abstract class NorthwindMiscellaneousQueryTestBase : QueryTestBase @@ -792,8 +791,7 @@ public virtual Task Ternary_should_not_evaluate_both_sides_with_parameter(bool a o => new { // ReSharper disable SimplifyConditionalTernaryExpression - Data1 = param != null ? o.OrderDate == param.Value : true, - Data2 = param == null ? true : o.OrderDate == param.Value + Data1 = param != null ? o.OrderDate == param.Value : true, Data2 = param == null ? true : o.OrderDate == param.Value // ReSharper restore SimplifyConditionalTernaryExpression })); } @@ -1448,22 +1446,14 @@ public virtual void Select_DTO_constructor_distinct_with_collection_projection_t .Where(o => o.OrderID < 10300) .Select(o => new { A = new OrderCountDTO(o.CustomerID), o.CustomerID }) .Distinct() - .Select(e => new - { - e.A, - Orders = context.Set().Where(o => o.CustomerID == e.CustomerID).ToList() - }) + .Select(e => new { e.A, Orders = context.Set().Where(o => o.CustomerID == e.CustomerID).ToList() }) .ToList().OrderBy(e => e.A.Id).ToList(); var expected = Fixture.GetExpectedData().Set() .Where(o => o.OrderID < 10300) .Select(o => new { A = new OrderCountDTO(o.CustomerID), o.CustomerID }) .Distinct() - .Select(e => new - { - e.A, - Orders = Fixture.GetExpectedData().Set().Where(o => o.CustomerID == e.CustomerID).ToList() - }) + .Select(e => new { e.A, Orders = Fixture.GetExpectedData().Set().Where(o => o.CustomerID == e.CustomerID).ToList() }) .ToList().OrderBy(e => e.A.Id).ToList(); Assert.Equal(expected.Count, actual.Count); @@ -1616,68 +1606,50 @@ public override int GetHashCode() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Select_correlated_subquery_filtered_returning_queryable_throws(bool async) + public virtual Task Select_correlated_subquery_filtered_returning_queryable_throws(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"c => DbSet() - .Where(o => o.CustomerID == c.CustomerID)", typeof(IQueryable).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => - from c in ss.Set() - where c.CustomerID.StartsWith("A") - orderby c.CustomerID - select ss.Set().Where(o => o.CustomerID == c.CustomerID), - assertOrder: true, - elementAsserter: (e, a) => AssertCollection(e, a)))).Message, - ignoreLineEndingDifferences: true); + return AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => + from c in ss.Set() + where c.CustomerID.StartsWith("A") + orderby c.CustomerID + select ss.Set().Where(o => o.CustomerID == c.CustomerID), + assertOrder: true, + elementAsserter: (e, a) => AssertCollection(e, a)), + typeof(IQueryable).ShortDisplayName()); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Select_correlated_subquery_ordered_returning_queryable_throws(bool async) + public virtual Task Select_correlated_subquery_ordered_returning_queryable_throws(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"c => DbSet() - .OrderBy(o => o.OrderID) - .ThenBy(o => c.CustomerID) - .Skip(100) - .Take(2)", typeof(IQueryable).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => - from c in ss.Set().OrderBy(c => c.CustomerID).Take(3) - select ss.Set().OrderBy(o => o.OrderID).ThenBy(o => c.CustomerID).Skip(100).Take(2), - elementSorter: e => e.Count(), - elementAsserter: (e, a) => AssertCollection(e, a, ordered: true)))).Message, - ignoreLineEndingDifferences: true); + return AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => + from c in ss.Set().OrderBy(c => c.CustomerID).Take(3) + select ss.Set().OrderBy(o => o.OrderID).ThenBy(o => c.CustomerID).Skip(100).Take(2), + elementSorter: e => e.Count(), + elementAsserter: (e, a) => AssertCollection(e, a, ordered: true)), + typeof(IQueryable).ShortDisplayName()); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Select_correlated_subquery_ordered_returning_queryable_in_DTO_throws(bool async) + public virtual Task Select_correlated_subquery_ordered_returning_queryable_in_DTO_throws(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"c => DbSet() - .OrderBy(o => o.OrderID) - .ThenBy(o => c.CustomerID) - .Skip(100) - .Take(2)", typeof(IQueryable).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => - from c in ss.Set().OrderBy(c => c.CustomerID).Take(3) - select new QueryableDto - { - Orders = ss.Set().OrderBy(o => o.OrderID).ThenBy(o => c.CustomerID).Skip(100).Take(2) - }))).Message, - ignoreLineEndingDifferences: true); + return AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => + from c in ss.Set().OrderBy(c => c.CustomerID).Take(3) + select new QueryableDto + { + Orders = ss.Set().OrderBy(o => o.OrderID).ThenBy(o => c.CustomerID).Skip(100).Take(2) + }), + typeof(IQueryable).ShortDisplayName()); } private class QueryableDto @@ -1717,65 +1689,54 @@ select ss.Set().OrderBy(o => o.OrderID).ThenBy(o => c.CustomerID).Skip(10 [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Select_nested_collection_in_anonymous_type_returning_ordered_queryable(bool async) + public virtual Task Select_nested_collection_in_anonymous_type_returning_ordered_queryable(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"c => DbSet() - .Where(o => o.CustomerID == c.CustomerID && o.OrderDate.Value.Year == 1997) - .Select(o => o.OrderID) - .OrderBy(o => o)", typeof(IOrderedQueryable).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => - from c in ss.Set() - where c.CustomerID == "ALFKI" - select new - { - CustomerId = c.CustomerID, - OrderIds - = ss.Set().Where( - o => o.CustomerID == c.CustomerID - && o.OrderDate.Value.Year == 1997) - .Select(o => o.OrderID) - .OrderBy(o => o), - Customer = c - }, - elementAsserter: (e, a) => + return AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => + from c in ss.Set() + where c.CustomerID == "ALFKI" + select new { - Assert.Equal(e.CustomerId, a.CustomerId); - AssertCollection(e.OrderIds, a.OrderIds); - AssertEqual(e.Customer, a.Customer); + CustomerId = c.CustomerID, + OrderIds + = ss.Set().Where( + o => o.CustomerID == c.CustomerID + && o.OrderDate.Value.Year == 1997) + .Select(o => o.OrderID) + .OrderBy(o => o), + Customer = c }, - entryCount: 1))).Message, - ignoreLineEndingDifferences: true); + elementAsserter: (e, a) => + { + Assert.Equal(e.CustomerId, a.CustomerId); + AssertCollection(e.OrderIds, a.OrderIds); + AssertEqual(e.Customer, a.Customer); + }, + entryCount: 1), + typeof(IOrderedQueryable).ShortDisplayName()); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Select_subquery_recursive_trivial_returning_queryable(bool async) + public virtual Task Select_subquery_recursive_trivial_returning_queryable(bool async) { - Assert.Equal( - CoreStrings.QueryInvalidMaterializationType( - @"e1 => DbSet() - .Select(e2 => DbSet() - .OrderBy(e3 => e3.EmployeeID))", typeof(IQueryable>).ShortDisplayName()), - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => from e1 in ss.Set() - select (from e2 in ss.Set() - select (from e3 in ss.Set() - orderby e3.EmployeeID - select e3)), - elementSorter: e => e.Count(), - elementAsserter: (e, a) => AssertCollection( - e, - a, - elementSorter: ee => ee.Count(), - elementAsserter: (ee, aa) => AssertCollection(ee, aa, ordered: true))))).Message, - ignoreLineEndingDifferences: true); + return AssertInvalidMaterializationType( + () => AssertQuery( + async, + ss => from e1 in ss.Set() + select (from e2 in ss.Set() + select (from e3 in ss.Set() + orderby e3.EmployeeID + select e3)), + elementSorter: e => e.Count(), + elementAsserter: (e, a) => AssertCollection( + e, + a, + elementSorter: ee => ee.Count(), + elementAsserter: (ee, aa) => AssertCollection(ee, aa, ordered: true))), + typeof(IQueryable>).ShortDisplayName()); } [ConditionalTheory] @@ -3474,7 +3435,7 @@ public virtual void Select_Where_Subquery_Equality() using var context = CreateContext(); var orders = (from o in context.Orders.OrderBy(o => o.OrderID).Take(1) - // ReSharper disable once UseMethodAny.0 + // ReSharper disable once UseMethodAny.0 where (from od in context.OrderDetails.OrderBy(od => od.OrderID).Take(2) where (from c in context.Set() where c.CustomerID == o.CustomerID @@ -5985,7 +5946,7 @@ public virtual Task Checked_context_with_case_to_same_nullable_type_does_not_fai isAsync, ss => ss.Set(), ss => ss.Set(), - detail => (short?)detail.Quantity, + detail => detail.Quantity, detail => (short?)detail.Quantity ); } @@ -6112,10 +6073,10 @@ public virtual async Task Perform_identity_resolution_reuses_same_instances_acro join o in context.Orders.Where(o => o.OrderID < 10500).Include(o => o.Customer) on c.CustomerID equals o.CustomerID select new { c, o }); - + query = useAsTracking - ? query.AsTracking(QueryTrackingBehavior.NoTrackingWithIdentityResolution) - : query.AsNoTrackingWithIdentityResolution(); + ? query.AsTracking(QueryTrackingBehavior.NoTrackingWithIdentityResolution) + : query.AsNoTrackingWithIdentityResolution(); var result = async ? await query.ToListAsync() @@ -6296,13 +6257,14 @@ public virtual Task Entity_equality_on_subquery_with_null_check(bool async) return AssertQuery( async, ss => ss.Set() - .Select(c => new - { - c.CustomerID, - Order = (c.Orders.Any() ? c.Orders.FirstOrDefault() : null) == null - ? null - : new { c.Orders.OrderBy(o => o.OrderID).FirstOrDefault().OrderDate } - }), + .Select( + c => new + { + c.CustomerID, + Order = (c.Orders.Any() ? c.Orders.FirstOrDefault() : null) == null + ? null + : new { c.Orders.OrderBy(o => o.OrderID).FirstOrDefault().OrderDate } + }), elementSorter: c => c.CustomerID, elementAsserter: (e, a) => AssertEqual(e.Order, a.Order)); } @@ -6324,13 +6286,14 @@ public virtual Task FirstOrDefault_with_predicate_nested(bool async) async, ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).OrderBy(c => c.CustomerID).Select(TestDto.Projection), ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).OrderBy(c => c.CustomerID) - .Select(x => new TestDto - { - CustomerID = x.CustomerID, - OrderDate = x.Orders - .FirstOrDefault(t => t.OrderID == t.OrderID) - .MaybeScalar(e => e.OrderDate) - }), + .Select( + x => new TestDto + { + CustomerID = x.CustomerID, + OrderDate = x.Orders + .FirstOrDefault(t => t.OrderID == t.OrderID) + .MaybeScalar(e => e.OrderDate) + }), assertOrder: true, elementAsserter: (e, a) => { @@ -6360,11 +6323,7 @@ public virtual Task First_on_collection_in_projection(bool async) return AssertQuery( async, ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).OrderBy(c => c.CustomerID) - .Select(c => new - { - c.CustomerID, - OrderDate = c.Orders.Any() ? c.Orders.First().OrderDate : default - }), + .Select(c => new { c.CustomerID, OrderDate = c.Orders.Any() ? c.Orders.First().OrderDate : default }), assertOrder: true, elementAsserter: (e, a) => { @@ -6404,8 +6363,8 @@ public virtual Task Skip_0_Take_0_works_when_constant(bool async) return AssertQueryScalar( async, ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")) - .OrderBy(c => c.CustomerID) - .Select(e => e.Orders.OrderBy(o => o.OrderID).Skip(0).Take(0).Any()), + .OrderBy(c => c.CustomerID) + .Select(e => e.Orders.OrderBy(o => o.OrderID).Skip(0).Take(0).Any()), assertOrder: true); } @@ -6539,7 +6498,13 @@ public virtual Task Correlated_collection_with_distinct_without_default_identifi { Key = c.CustomerID, Subquery = c.Orders - .Select(o => new { First = o.OrderID, Second = o.OrderDate, Third = o.Customer.City }) + .Select( + o => new + { + First = o.OrderID, + Second = o.OrderDate, + Third = o.Customer.City + }) .Distinct().ToList() }), elementSorter: e => e.Key, @@ -6557,7 +6522,6 @@ public virtual Task Correlated_collection_with_distinct_without_default_identifi Assert.Equal(ee.Third, aa.Third); }); }); - } [ConditionalTheory] @@ -6577,8 +6541,6 @@ public virtual Task Select_nested_collection_with_distinct(bool async) elementAsserter: (e, a) => AssertCollection(e, a)); } - - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Collection_projection_after_DefaultIfEmpty(bool async) @@ -6587,10 +6549,7 @@ public virtual Task Collection_projection_after_DefaultIfEmpty(bool async) async, ss => ss.Set().Where(c => c.City == "Seattle").DefaultIfEmpty() .OrderBy(c => c.CustomerID) - .Select(e => new - { - e.Orders - }), + .Select(e => new { e.Orders }), assertOrder: true, elementAsserter: (e, a) => AssertCollection(e.Orders, a.Orders), entryCount: 14); diff --git a/test/EFCore.Specification.Tests/Query/QueryTestBase.cs b/test/EFCore.Specification.Tests/Query/QueryTestBase.cs index 32e9190ea64..2d29588b787 100644 --- a/test/EFCore.Specification.Tests/Query/QueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/QueryTestBase.cs @@ -1141,6 +1141,36 @@ protected static async Task AssertTranslationFailedWithDetails(Func query, (await Assert.ThrowsAsync(query)) .Message); + protected static async Task AssertInvalidMaterializationType(Func query, string queryableType) + => Assert.Contains( + CoreStrings.QueryInvalidMaterializationType("", queryableType)[64..], + (await Assert.ThrowsAsync(query)) + .Message); + + protected static async Task AssertIncludeOnNonEntity(Func query) + => Assert.Contains( + CoreStrings.IncludeOnNonEntity("")[64..], + (await Assert.ThrowsAsync(query)) + .Message); + + protected static async Task AssertInvalidIncludeExpression(Func query) + => Assert.Contains( + CoreStrings.InvalidIncludeExpression("")[64..], + (await Assert.ThrowsAsync(query)) + .Message); + + protected static async Task AssertUnableToTranslateEFProperty(Func query) + => Assert.Contains( + CoreStrings.QueryUnableToTranslateEFProperty("")[64..], + (await Assert.ThrowsAsync(query)) + .Message); + + protected static async Task AssertInvalidSetSharedType(Func query, string typeName) + => Assert.Equal( + CoreStrings.InvalidSetSharedType(typeName), + (await Assert.ThrowsAsync(query)) + .Message); + #endregion } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs index 356ebcdac45..010b417e955 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqlServerTest.cs @@ -1,13 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; -// ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsQuerySqlServerTest : ComplexNavigationsCollectionsQueryRelationalTestBase + public class ComplexNavigationsCollectionsQuerySqlServerTest + : ComplexNavigationsCollectionsQueryRelationalTestBase { public ComplexNavigationsCollectionsQuerySqlServerTest( ComplexNavigationsQuerySqlServerFixture fixture, @@ -18,6 +21,10 @@ public ComplexNavigationsCollectionsQuerySqlServerTest( //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + public override async Task Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(bool async) { await base.Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(async); @@ -33,9 +40,11 @@ FROM [LevelTwo] AS [l0] ORDER BY [l].[Id], [t].[Id]"); } - public override async Task Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(bool async) + public override async Task + Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(bool async) { - await base.Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(async); + await base + .Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(async); AssertSql( @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[Id00], [t0].[Date0], [t0].[Level1_Optional_Id0], [t0].[Level1_Required_Id0], [t0].[Name00], [t0].[OneToMany_Optional_Inverse2Id0], [t0].[OneToMany_Optional_Self_Inverse2Id0], [t0].[OneToMany_Required_Inverse2Id0], [t0].[OneToMany_Required_Self_Inverse2Id0], [t0].[OneToOne_Optional_PK_Inverse2Id0], [t0].[OneToOne_Optional_Self2Id0], [t0].[Id1], [t0].[Level2_Optional_Id0], [t0].[Level2_Required_Id0], [t0].[Name1], [t0].[OneToMany_Optional_Inverse3Id0], [t0].[OneToMany_Optional_Self_Inverse3Id0], [t0].[OneToMany_Required_Inverse3Id0], [t0].[OneToMany_Required_Self_Inverse3Id0], [t0].[OneToOne_Optional_PK_Inverse3Id0], [t0].[OneToOne_Optional_Self3Id0] @@ -434,9 +443,11 @@ FROM [LevelTwo] AS [l0] ORDER BY [l].[Id], [t].[Id]"); } - public override async Task Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) + public override async Task + Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) { - await base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(async); + await base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top( + async); AssertSql( @"SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l].[Id], [l0].[Id], [l1].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2], [t0].[Id], [t0].[Id0], [t0].[Id1], [t0].[Id2], [l11].[Id], [l12].[Id], [l13].[Id], [l14].[Id], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [l14].[Name] @@ -1835,7 +1846,8 @@ OFFSET 2 ROWS FETCH NEXT 4 ROWS ONLY ORDER BY [t].[Id] DESC, [t0].[Name] DESC, [t0].[Id]"); } - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) { await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async); @@ -1858,7 +1870,8 @@ FROM [LevelTwo] AS [l1] ORDER BY [t].[Id], [t0].[Id]"); } - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) { await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async); @@ -2174,8 +2187,8 @@ FROM [LevelTwo] AS [l0] ) AS [t0] ON ([l].[Id] = [t0].[OneToMany_Optional_Inverse2Id]) AND ([l].[Id] = [t0].[Id])"); } - - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) { await base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async); @@ -2242,6 +2255,190 @@ OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY ORDER BY [t].[Name], [t].[Id], [t].[Id0], [t0].[Name], [t0].[Id]"); } + public override async Task SelectMany_over_conditional_null_source(bool async) + { + await base.SelectMany_over_conditional_null_source(async); + + AssertSql(); + } + + public override async Task SelectMany_over_conditional_empty_source(bool async) + { + await base.SelectMany_over_conditional_empty_source(async); + + AssertSql(); + } + + public override async Task Queryable_in_subquery_works_when_final_projection_is_List(bool async) + { + await base.Queryable_in_subquery_works_when_final_projection_is_List(async); + + AssertSql(); + } + + public override async Task Include_after_Select(bool async) + { + await base.Include_after_Select(async); + + AssertSql(); + } + + public override async Task Include_after_SelectMany_and_reference_navigation(bool async) + { + await base.Include_after_SelectMany_and_reference_navigation(async); + + AssertSql(); + } + + public override async Task Filtered_include_different_filter_set_on_same_navigation_twice(bool async) + { + await base.Filtered_include_different_filter_set_on_same_navigation_twice(async); + + AssertSql(); + } + + public override async Task Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(bool async) + { + await base.Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(async); + + AssertSql(); + } + + public override async Task Filtered_include_include_parameter_used_inside_filter_throws(bool async) + { + await base.Filtered_include_include_parameter_used_inside_filter_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_with_Distinct_throws(bool async) + { + await base.Filtered_include_with_Distinct_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_calling_methods_directly_on_parameter_throws(bool async) + { + await base.Filtered_include_calling_methods_directly_on_parameter_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_is_considered_loaded(bool async) + { + await base.Filtered_include_is_considered_loaded(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Select_nav_prop_collection_one_to_many_required(bool async) + { + await base.Select_nav_prop_collection_one_to_many_required(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Project_collection_navigation_nested_with_take(bool async) + { + await base.Project_collection_navigation_nested_with_take(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id] + FROM ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Id]) AS [row] + FROM [LevelThree] AS [l1] + ) AS [t] + WHERE [t].[row] <= 50 +) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [t0].[OneToMany_Optional_Inverse3Id], [t0].[Id]"); + } + + public override async Task Multiple_optional_navigation_with_Include(bool async) + { + await base.Multiple_optional_navigation_with_Include(async); + + AssertSql( + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l].[Id], [l0].[Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + { + // Nested collection with ToList. Issue #23303. + await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT [l1].[Name], [l1].[Id] + FROM [LevelOne] AS [l1] + WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l2] + WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND ([l2].[Id] = [t0].[Id])) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_complex_repeated_checked(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex_repeated_checked(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY -[l].[Level1_Required_Id], [l].[Name], [l].[Id]"); + } + + public override async Task Multiple_optional_navigation_with_string_based_Include(bool async) + { + await base.Multiple_optional_navigation_with_string_based_Include(async); + + AssertSql( + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l].[Id], [l0].[Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs index 9f64f135c0f..c2a66df5fa2 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs @@ -1,13 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest : ComplexNavigationsCollectionsSharedTypeQueryRelationalTestBase< - ComplexNavigationsSharedTypeQuerySqlServerFixture> + public class ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest + : ComplexNavigationsCollectionsSharedTypeQueryRelationalTestBase { public ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest( ComplexNavigationsSharedTypeQuerySqlServerFixture fixture, @@ -18,6 +21,43 @@ public ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest( //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + { + // Nested collection with ToList. Issue #23303. + await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Name], [t1].[Id], [t0].[c] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT [l2].[Name], [l2].[Id] + FROM [Level1] AS [l2] + WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ((([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] = [l3].[OneToMany_Optional_Inverse2Id])) AND ([l3].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END)) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0]"); + } + public override async Task SelectMany_with_Include1(bool async) { await base.SelectMany_with_Include1(async); @@ -138,6 +178,3950 @@ OFFSET 1 ROWS FETCH NEXT 3 ROWS ONLY ORDER BY [t].[Id], [t0].[c], [t0].[Id1], [t0].[Id00]"); } + public override async Task FirstOrDefault_with_predicate_on_correlated_collection_in_projection(bool async) + { + await base.FirstOrDefault_with_predicate_on_correlated_collection_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON ([l].[Id] = [t0].[OneToMany_Optional_Inverse2Id]) AND ([l].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END)"); + } + + public override async Task Filtered_include_same_filter_set_on_same_navigation_twice(bool async) + { + await base.Filtered_include_same_filter_set_on_same_navigation_twice(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END DESC) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 2 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c] DESC, [t0].[Id]"); + } + + public override async Task Filtered_include_basic_Where(bool async) + { + await base.Filtered_include_basic_Where(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l0].[Id] > 5) +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Optional_navigation_with_order_by_and_Include(bool async) + { + await base.Optional_navigation_with_order_by_and_Include(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [t].[Level2_Name], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Filtered_include_basic_OrderBy_Skip(bool async) + { + await base.Filtered_include_basic_OrderBy_Skip(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Level2_Name]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE 1 < [t].[row] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Level2_Name], [t0].[Id]"); + } + + public override async Task Multiple_include_with_multiple_optional_navigations(bool async) + { + await base.Multiple_include_with_multiple_optional_navigations(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00], [t4].[Id], [t4].[Id0], [t5].[Id], [t5].[Id0], [t5].[Id00], [t7].[Id], [t7].[Level2_Optional_Id], [t7].[Level2_Required_Id], [t7].[Level3_Name], [t7].[OneToMany_Optional_Inverse3Id], [t7].[OneToMany_Required_Inverse3Id], [t7].[OneToOne_Optional_PK_Inverse3Id], [t7].[Id0], [t7].[Id00], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t5].[Level2_Optional_Id], [t5].[Level2_Required_Id], [t5].[Level3_Name], [t5].[OneToMany_Optional_Inverse3Id], [t5].[OneToMany_Required_Inverse3Id], [t5].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level3_Name], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t2].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l8].[Id], [l8].[OneToOne_Required_PK_Date], [l8].[Level1_Optional_Id], [l8].[Level1_Required_Id], [l8].[Level2_Name], [l8].[OneToMany_Optional_Inverse2Id], [l8].[OneToMany_Required_Inverse2Id], [l8].[OneToOne_Optional_PK_Inverse2Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l10].[Id], [l10].[Level2_Optional_Id], [l10].[Level2_Required_Id], [l10].[Level3_Name], [l10].[OneToMany_Optional_Inverse3Id], [l10].[OneToMany_Required_Inverse3Id], [l10].[OneToOne_Optional_PK_Inverse3Id], [t6].[Id] AS [Id0], [t6].[Id0] AS [Id00] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id], [l12].[Id] AS [Id0] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l10].[Id] = [t6].[Id] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t5] ON CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] +END = [t5].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l13].[Id], [l13].[Level2_Optional_Id], [l13].[Level2_Required_Id], [l13].[Level3_Name], [l13].[OneToMany_Optional_Inverse3Id], [l13].[OneToMany_Required_Inverse3Id], [l13].[OneToOne_Optional_PK_Inverse3Id], [t8].[Id] AS [Id0], [t8].[Id0] AS [Id00] + FROM [Level1] AS [l13] + INNER JOIN ( + SELECT [l14].[Id], [l15].[Id] AS [Id0] + FROM [Level1] AS [l14] + INNER JOIN [Level1] AS [l15] ON [l14].[Id] = [l15].[Id] + WHERE ([l14].[OneToOne_Required_PK_Date] IS NOT NULL AND [l14].[Level1_Required_Id] IS NOT NULL) AND [l14].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t8] ON [l13].[Id] = [t8].[Id] + WHERE [l13].[Level2_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t7] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t7].[OneToMany_Optional_Inverse3Id] +WHERE ([t0].[Level3_Name] <> N'Foo') OR [t0].[Level3_Name] IS NULL +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00], [t4].[Id], [t4].[Id0], [t5].[Id], [t5].[Id0], [t5].[Id00], [t7].[Id], [t7].[Id0]"); + } + + public override async Task Filtered_include_Take_with_another_Take_on_top_level(bool async) + { + await base.Filtered_include_Take_with_another_Take_on_top_level(async); + + AssertSql( + @"@__p_0='5' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id00], [t2].[Id01], [t2].[Id000] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id] AS [Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000] + FROM ( + SELECT TOP(4) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) + ORDER BY [l0].[Level2_Name] DESC + ) AS [t0] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l2].[Id] = [t3].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level2_Optional_Id] +) AS [t2] +ORDER BY [t].[Id], [t2].[Level2_Name] DESC, [t2].[Id], [t2].[Id00], [t2].[Id0], [t2].[Id01]"); + } + + public override async Task Filtered_include_after_different_filtered_include_different_level(bool async) + { + await base.Filtered_include_after_different_filtered_include_different_level(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t3].[Id], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Optional_Id], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Optional_Inverse2Id], [t3].[OneToMany_Required_Inverse2Id], [t3].[OneToOne_Optional_PK_Inverse2Id], [t3].[Id0], [t3].[Id1], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id00], [t3].[Id000] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t1].[Id] AS [Id1], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0] AS [Id00], [t1].[Id00] AS [Id000] + FROM ( + SELECT TOP(3) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ((([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id])) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ORDER BY [l0].[Level2_Name] + ) AS [t] + LEFT JOIN ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] + FROM ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Required_Inverse3Id] ORDER BY [l2].[Level3_Name] DESC) AS [row] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (([l2].[Level3_Name] <> N'Bar') OR [l2].[Level3_Name] IS NULL) + ) AS [t0] + WHERE 1 < [t0].[row] + ) AS [t1] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [t1].[OneToMany_Required_Inverse3Id] +) AS [t3] +ORDER BY [l].[Id], [t3].[Level2_Name], [t3].[Id], [t3].[Id0], [t3].[OneToMany_Required_Inverse3Id], [t3].[Level3_Name] DESC, [t3].[Id1], [t3].[Id00]"); + } + + public override async Task Project_collection_navigation_composed(bool async) + { + await base.Project_collection_navigation_composed(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE [l].[Id] < 3 +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Filtered_include_basic_OrderBy_Skip_Take(bool async) + { + await base.Filtered_include_basic_OrderBy_Skip_Take(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Level2_Name]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE (1 < [t].[row]) AND ([t].[row] <= 4) +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Level2_Name], [t0].[Id]"); + } + + public override async Task Filtered_include_on_ThenInclude(bool async) + { + await base.Filtered_include_on_ThenInclude(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] + FROM ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Optional_Inverse3Id] ORDER BY [l2].[Level3_Name]) AS [row] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (([l2].[Level3_Name] <> N'Foo') OR [l2].[Level3_Name] IS NULL) + ) AS [t0] + WHERE (1 < [t0].[row]) AND ([t0].[row] <= 4) +) AS [t1] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[Level3_Name], [t1].[Id], [t1].[Id0]"); + } + + public override async Task Include_collection_with_conditional_order_by(bool async) + { + await base.Include_collection_with_conditional_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY CASE + WHEN [l].[Name] IS NOT NULL AND ([l].[Name] LIKE N'%03') THEN 1 + ELSE 2 +END, [l].[Id], [t].[Id]"); + } + + public override async Task Include_nested_with_optional_navigation(bool async) + { + await base.Include_nested_with_optional_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t3].[Id], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id0], [t3].[Level3_Optional_Id], [t3].[Level3_Required_Id], [t3].[Level4_Name], [t3].[OneToMany_Optional_Inverse4Id], [t3].[OneToMany_Required_Inverse4Id], [t3].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id1], [t3].[Id00], [t3].[Id01], [t3].[Id000], [t3].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t0].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000], [t1].[Id000] AS [Id0000] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END = [t1].[Level3_Required_Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t3] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t3].[OneToMany_Required_Inverse3Id] +WHERE ([t].[Level2_Name] <> N'L2 09') OR [t].[Level2_Name] IS NULL +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t3].[Id], [t3].[Id1], [t3].[Id00], [t3].[Id0], [t3].[Id01], [t3].[Id000]"); + } + + public override async Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key(bool async) + { + await base.Complex_multi_include_with_order_by_and_paging_joins_on_correct_key(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0], [t1].[Id], [t1].[Id0], [t2].[Id], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id0], [t2].[Id00], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id0], [t4].[Id00] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Name] + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t].[Id] = [t1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l4] + INNER JOIN ( + SELECT [l5].[Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l4].[Id] = [t3].[Id] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t2] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l7].[Id] = [t5].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t4] ON CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] +END = [t4].[OneToMany_Required_Inverse3Id] +ORDER BY [t].[Name], [t].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Id0], [t2].[Id], [t2].[Id0], [t2].[Id00], [t4].[Id], [t4].[Id0]"); + } + + public override async Task Select_subquery_single_nested_subquery2(bool async) + { + await base.Select_subquery_single_nested_subquery2(async); + + AssertSql( + @"SELECT [l].[Id], [t5].[Id], [t5].[Id0], [t5].[Id1], [t5].[Id00], [t5].[Id000], [t5].[Id2], [t5].[Id01], [t5].[Id10], [t5].[Id001], [t5].[Id0000], [t5].[c] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0], [t1].[Id] AS [Id1], [t1].[Id0] AS [Id00], [t1].[Id00] AS [Id000], [t2].[Id] AS [Id2], [t2].[Id0] AS [Id01], [t2].[Id1] AS [Id10], [t2].[Id00] AS [Id001], [t2].[Id000] AS [Id0000], [t1].[c], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c0], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [t0].[c], [t0].[Id], [t0].[Id0], [t0].[Id00], [t0].[Level2_Required_Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Optional_Inverse3Id] + FROM ( + SELECT 1 AS [c], [l2].[Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Optional_Inverse3Id], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Optional_Inverse3Id] ORDER BY CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END) AS [row] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] + WHERE [t0].[row] <= 1 + ) AS [t1] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t1].[OneToMany_Optional_Inverse3Id] + LEFT JOIN ( + SELECT CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] + END AS [Id], [l5].[Id] AS [Id0], [t3].[Id] AS [Id1], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000], [l5].[OneToMany_Optional_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t2] ON CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] + END = [t2].[OneToMany_Optional_Inverse4Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t5] ON [l].[Id] = [t5].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t5].[c0], [t5].[Id], [t5].[Id0], [t5].[Id1], [t5].[Id00], [t5].[Id000], [t5].[Id2], [t5].[Id01], [t5].[Id10], [t5].[Id001]"); + } + + public override async Task SelectMany_with_Include_and_order_by(bool async) + { + await base.SelectMany_with_Include_and_order_by(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [t].[Level2_Name], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Multiple_complex_includes(bool async) + { + await base.Multiple_complex_includes(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id1], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [t3].[Id] AS [Id0], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [l6].[Id] AS [Id1], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l7].[Id] = [t4].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END = [t3].[Level2_Optional_Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id1], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task Include_collection_then_reference(bool async) + { + await base.Include_collection_then_reference(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id1], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l1].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[Level2_Optional_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id1], [t1].[Id0], [t1].[Id00]"); + } + + public override async Task Include_reference_followed_by_include_collection(bool async) + { + await base.Include_reference_followed_by_include_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Multiple_optional_navigation_with_string_based_Include(bool async) + { + await base.Multiple_optional_navigation_with_string_based_Include(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id0], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task SelectMany_navigation_property_with_include_and_followed_by_select_collection_navigation(bool async) + { + await base.SelectMany_navigation_property_with_include_and_followed_by_select_collection_navigation(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id0], [t2].[Id00] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Required_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t2].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0]"); + } + + public override async Task SelectMany_with_Include_ThenInclude(bool async) + { + await base.SelectMany_with_Include_ThenInclude(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l].[Id], [t].[Id0], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id0], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task Filtered_include_and_non_filtered_include_on_same_navigation2(bool async) + { + await base.Filtered_include_and_non_filtered_include_on_same_navigation2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c], [t0].[Id]"); + } + + public override async Task + Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(bool async) + { + await base + .Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id0], [t4].[Id1], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id00], [t4].[OneToOne_Required_PK_Date0], [t4].[Level1_Optional_Id0], [t4].[Level1_Required_Id0], [t4].[Level2_Name0], [t4].[OneToMany_Optional_Inverse2Id0], [t4].[OneToMany_Required_Inverse2Id0], [t4].[OneToOne_Optional_PK_Inverse2Id0], [t4].[Id10], [t4].[Id000], [t4].[Id01], [t4].[Id2], [t4].[Level2_Optional_Id0], [t4].[Level2_Required_Id0], [t4].[Level3_Name0], [t4].[OneToMany_Optional_Inverse3Id0], [t4].[OneToMany_Required_Inverse3Id0], [t4].[OneToOne_Optional_PK_Inverse3Id0], [t4].[Id02], [t4].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], [t3].[Id] AS [Id1], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id0] AS [Id00], [t3].[OneToOne_Required_PK_Date] AS [OneToOne_Required_PK_Date0], [t3].[Level1_Optional_Id] AS [Level1_Optional_Id0], [t3].[Level1_Required_Id] AS [Level1_Required_Id0], [t3].[Level2_Name] AS [Level2_Name0], [t3].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [t3].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [t3].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [t3].[Id1] AS [Id10], [t3].[Id00] AS [Id000], [t3].[Id01], [t3].[Id2], [t3].[Level2_Optional_Id0], [t3].[Level2_Required_Id0], [t3].[Level3_Name0], [t3].[OneToMany_Optional_Inverse3Id0], [t3].[OneToMany_Required_Inverse3Id0], [t3].[OneToOne_Optional_PK_Inverse3Id0], [t3].[Id02], [t3].[Id000] AS [Id0000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id] AS [Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t].[Id] AS [Id1], [t].[Id0] AS [Id00], [t0].[Id0] AS [Id01], [t1].[Id] AS [Id2], [t1].[Level2_Optional_Id] AS [Level2_Optional_Id0], [t1].[Level2_Required_Id] AS [Level2_Required_Id0], [t1].[Level3_Name] AS [Level3_Name0], [t1].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [t1].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [t1].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [t1].[Id0] AS [Id02], [t1].[Id00] AS [Id000] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + INNER JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[OneToMany_Required_Inverse3Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l7].[Id] = [t2].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[OneToMany_Optional_Inverse3Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t3].[OneToMany_Optional_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t4].[Id], [t4].[Id0], [t4].[Id1], [t4].[Id10], [t4].[Id000], [t4].[Id00], [t4].[Id01], [t4].[Id2], [t4].[Id02]"); + } + + public override async Task Include_after_SelectMany(bool async) + { + await base.Include_after_SelectMany(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Required_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Filtered_include_context_accessed_inside_filter_correlated(bool async) + { + await base.Filtered_include_context_accessed_inside_filter_correlated(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (( + SELECT COUNT(*) + FROM [Level1] AS [l2] + WHERE [l2].[Id] <> [l0].[Id]) > 1) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c], [t0].[Id]"); + } + + public override async Task Skip_Take_on_grouping_element(bool async) + { + await base.Skip_Take_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task SelectMany_with_Include2(bool async) + { + await base.SelectMany_with_Include2(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id]"); + } + + public override async Task Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(bool async) + { + await base.Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t5].[Id], [t5].[OneToOne_Required_PK_Date], [t5].[Level1_Optional_Id], [t5].[Level1_Required_Id], [t5].[Level2_Name], [t5].[OneToMany_Optional_Inverse2Id], [t5].[OneToMany_Required_Inverse2Id], [t5].[OneToOne_Optional_PK_Inverse2Id], [t5].[Id0], [t5].[Level2_Optional_Id], [t5].[Level2_Required_Id], [t5].[Level3_Name], [t5].[OneToMany_Optional_Inverse3Id], [t5].[OneToMany_Required_Inverse3Id], [t5].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id00], [t5].[Id01], [t5].[Id000], [t5].[Id1], [t5].[Level3_Optional_Id], [t5].[Level3_Required_Id], [t5].[Level4_Name], [t5].[OneToMany_Optional_Inverse4Id], [t5].[OneToMany_Required_Inverse4Id], [t5].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id02], [t5].[Id001], [t5].[Id0000] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t].[Id0] AS [Id00], [t0].[Id0] AS [Id01], [t0].[Id00] AS [Id000], [t2].[Id] AS [Id1], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id0] AS [Id02], [t2].[Id00] AS [Id001], [t2].[Id000] AS [Id0000], [t].[c] + FROM ( + SELECT TOP(1) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ((([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id])) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END + ) AS [t] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE ([l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL) AND ([l5].[Id] > 1) + ) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t2].[OneToMany_Optional_Inverse4Id] +) AS [t5] +ORDER BY [l].[Id], [t5].[c], [t5].[Id], [t5].[Id00], [t5].[Id0], [t5].[Id01], [t5].[Id000], [t5].[Id1], [t5].[Id02], [t5].[Id001]"); + } + + public override async Task Include_collection_with_groupby_in_subquery(bool async) + { + await base.Include_collection_with_groupby_in_subquery(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] +FROM ( + SELECT [l].[Name] + FROM [Level1] AS [l] + GROUP BY [l].[Name] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Name] = [t0].[Name] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Name], [t0].[Id], [t2].[Id]"); + } + + public override async Task Skip_Take_ToList_on_grouping_element(bool async) + { + await base.Skip_Take_ToList_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task Project_collection_navigation_nested_with_take(bool async) + { + await base.Project_collection_navigation_nested_with_take(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Id0], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] + FROM ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Optional_Inverse3Id] ORDER BY [l2].[Id], [t2].[Id], [t2].[Id0]) AS [row] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] + WHERE [t0].[row] <= 50 +) AS [t1] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[Id], [t1].[Id0], [t1].[Id00]"); + } + + public override async Task Multiple_SelectMany_navigation_property_followed_by_select_collection_navigation(bool async) + { + await base.Multiple_SelectMany_navigation_property_followed_by_select_collection_navigation(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END, [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id0], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task Skip_Take_on_grouping_element_with_reference_include(bool async) + { + await base.Skip_Take_on_grouping_element_with_reference_include(async); + + AssertSql( + @"SELECT [t].[Date], [t1].[Id], [t1].[Date], [t1].[Name], [t1].[Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id00] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] AS [Id00] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name] + FROM [Level1] AS [l0] + WHERE [t].[Date] = [l0].[Date] + ORDER BY [l0].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [t0].[Id] = [t2].[Level1_Optional_Id] +) AS [t1] +ORDER BY [t].[Date], [t1].[Name], [t1].[Id], [t1].[Id0]"); + } + + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) + { + await base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0], [t0].[Id00], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l0].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([t].[Level1_Required_Id] = ([l].[Id] * 2)) OR ((CAST(LEN([t].[Level2_Name]) AS int) = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END) OR ([t].[Level2_Name] IS NULL AND CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL))) +) AS [t0] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[Id0], [t0].[Id], [t0].[Id00], [t1].[Id]"); + } + + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) + { + await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async); + + AssertSql( + @"SELECT [t].[Id], [t].[Date], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id00], [t2].[Id01], [t2].[Id000] +FROM ( + SELECT TOP(1) [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id] AS [Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000] + FROM ( + SELECT TOP(40) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) + ) AS [t0] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l2].[Id] = [t3].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level2_Optional_Id] +) AS [t2] +ORDER BY [t].[Id], [t2].[Id], [t2].[Id00], [t2].[Id0], [t2].[Id01]"); + } + + public override async Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key2(bool async) + { + await base.Complex_multi_include_with_order_by_and_paging_joins_on_correct_key2(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t1].[Id0], [t1].[Id00], [t3].[Id], [t3].[Level3_Optional_Id], [t3].[Level3_Required_Id], [t3].[Level4_Name], [t3].[OneToMany_Optional_Inverse4Id], [t3].[OneToMany_Required_Inverse4Id], [t3].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id0], [t3].[Id00], [t3].[Id000] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Name] + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00], [t4].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l6].[Id] = [t5].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON [l5].[Id] = [t4].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t3] ON CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] +END = [t3].[OneToMany_Optional_Inverse4Id] +ORDER BY [t].[Name], [t].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Id0], [t1].[Id00], [t3].[Id], [t3].[Id0], [t3].[Id00]"); + } + + public override async Task SelectMany_navigation_property_followed_by_select_collection_navigation(bool async) + { + await base.SelectMany_navigation_property_followed_by_select_collection_navigation(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_collection_with_groupby_in_subquery_and_filter_before_groupby(bool async) + { + await base.Include_collection_with_groupby_in_subquery_and_filter_before_groupby(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] +FROM ( + SELECT [l].[Name] + FROM [Level1] AS [l] + WHERE [l].[Id] > 3 + GROUP BY [l].[Name] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [Level1] AS [l0] + WHERE [l0].[Id] > 3 + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Name] = [t0].[Name] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Name], [t0].[Id], [t2].[Id]"); + } + + public override async Task Filtered_include_after_reference_navigation(bool async) + { + await base.Filtered_include_after_reference_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] + FROM ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Optional_Inverse3Id] ORDER BY [l2].[Level3_Name]) AS [row] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (([l2].[Level3_Name] <> N'Foo') OR [l2].[Level3_Name] IS NULL) + ) AS [t0] + WHERE (1 < [t0].[row]) AND ([t0].[row] <= 4) +) AS [t1] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[Level3_Name], [t1].[Id], [t1].[Id0]"); + } + + public override async Task Project_collection_navigation_nested(bool async) + { + await base.Project_collection_navigation_nested(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Lift_projection_mapping_when_pushing_down_subquery(bool async) + { + await base.Lift_projection_mapping_when_pushing_down_subquery(async); + + AssertSql( + @"@__p_0='25' + +SELECT [t].[Id], [t0].[Id0], [t0].[Id1], [t2].[Id], [t2].[Id0], [t2].[Id1], [t0].[Id], [t0].[c] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [Level1] AS [l] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[c], [t1].[Id0], [t1].[Id1], [t1].[OneToMany_Required_Inverse2Id] + FROM ( + SELECT CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [Id], 1 AS [c], [l0].[Id] AS [Id0], [l1].[Id] AS [Id1], [l0].[OneToMany_Required_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Required_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Id] = [t0].[OneToMany_Required_Inverse2Id] +LEFT JOIN ( + SELECT CASE + WHEN ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l2].[Id] + END AS [Id], [l2].[Id] AS [Id0], [l3].[Id] AS [Id1], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t].[Id] = [t2].[OneToMany_Required_Inverse2Id] +ORDER BY [t].[Id], [t0].[Id0], [t0].[Id1], [t2].[Id0]"); + } + + public override async Task Include_collection_ThenInclude_reference_followed_by_projection_into_anonmous_type(bool async) + { + await base.Include_collection_ThenInclude_reference_followed_by_projection_into_anonmous_type(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id1], [t1].[Id00], [t1].[Id000], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id1], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l1].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [t3].[Id] AS [Id0], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [l6].[Id] AS [Id1], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l7].[Id] = [t4].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END = [t3].[OneToOne_Optional_PK_Inverse3Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id1], [t1].[Id0], [t1].[Id00], [t1].[Id000], [t2].[Id], [t2].[Id1], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task Project_collection_navigation_nested_anonymous(bool async) + { + await base.Project_collection_navigation_nested_anonymous(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Filtered_include_after_different_filtered_include_same_level(bool async) + { + await base.Filtered_include_after_different_filtered_include_same_level(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Level2_Name]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] + FROM ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Required_Inverse2Id] ORDER BY [l2].[Level2_Name] DESC) AS [row] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE (([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l2].[Level2_Name] <> N'Bar') OR [l2].[Level2_Name] IS NULL) + ) AS [t2] + WHERE 1 < [t2].[row] +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Level2_Name], [t0].[Id], [t0].[Id0], [t1].[OneToMany_Required_Inverse2Id], [t1].[Level2_Name] DESC, [t1].[Id]"); + } + + public override async Task Include_collection_followed_by_complex_includes_and_projecting_the_included_collection(bool async) + { + await base.Include_collection_followed_by_complex_includes_and_projecting_the_included_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t9].[Id], [t9].[OneToOne_Required_PK_Date], [t9].[Level1_Optional_Id], [t9].[Level1_Required_Id], [t9].[Level2_Name], [t9].[OneToMany_Optional_Inverse2Id], [t9].[OneToMany_Required_Inverse2Id], [t9].[OneToOne_Optional_PK_Inverse2Id], [t9].[Id0], [t9].[Level2_Optional_Id], [t9].[Level2_Required_Id], [t9].[Level3_Name], [t9].[OneToMany_Optional_Inverse3Id], [t9].[OneToMany_Required_Inverse3Id], [t9].[OneToOne_Optional_PK_Inverse3Id], [t9].[Id1], [t9].[Level3_Optional_Id], [t9].[Level3_Required_Id], [t9].[Level4_Name], [t9].[OneToMany_Optional_Inverse4Id], [t9].[OneToMany_Required_Inverse4Id], [t9].[OneToOne_Optional_PK_Inverse4Id], [t9].[Id2], [t9].[Level2_Optional_Id0], [t9].[Level2_Required_Id0], [t9].[Level3_Name0], [t9].[OneToMany_Optional_Inverse3Id0], [t9].[OneToMany_Required_Inverse3Id0], [t9].[OneToOne_Optional_PK_Inverse3Id0], [t9].[Id3], [t9].[Id00], [t9].[Id000], [t9].[Id01], [t9].[Id001], [t9].[Id0000], [t9].[Id02], [t9].[Id002], [t9].[Id4], [t9].[Level3_Optional_Id0], [t9].[Level3_Required_Id0], [t9].[Level4_Name0], [t9].[OneToMany_Optional_Inverse4Id0], [t9].[OneToMany_Required_Inverse4Id0], [t9].[OneToOne_Optional_PK_Inverse4Id0], [t9].[Id03], [t9].[Id003], [t9].[Id0001] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id] AS [Id2], [t4].[Level2_Optional_Id] AS [Level2_Optional_Id0], [t4].[Level2_Required_Id] AS [Level2_Required_Id0], [t4].[Level3_Name] AS [Level3_Name0], [t4].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [t4].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [t4].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l1].[Id] AS [Id3], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id001], [t1].[Id000] AS [Id0000], [t4].[Id0] AS [Id02], [t4].[Id00] AS [Id002], [t6].[Id] AS [Id4], [t6].[Level3_Optional_Id] AS [Level3_Optional_Id0], [t6].[Level3_Required_Id] AS [Level3_Required_Id0], [t6].[Level4_Name] AS [Level4_Name0], [t6].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [t6].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [t6].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [t6].[Id0] AS [Id03], [t6].[Id00] AS [Id003], [t6].[Id000] AS [Id0001] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level3_Optional_Id] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level2_Optional_Id], [l9].[Level2_Required_Id], [l9].[Level3_Name], [l9].[OneToMany_Optional_Inverse3Id], [l9].[OneToMany_Required_Inverse3Id], [l9].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [l11].[Id] AS [Id0] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t4].[Level2_Optional_Id] + LEFT JOIN ( + SELECT [l12].[Id], [l12].[Level3_Optional_Id], [l12].[Level3_Required_Id], [l12].[Level4_Name], [l12].[OneToMany_Optional_Inverse4Id], [l12].[OneToMany_Required_Inverse4Id], [l12].[OneToOne_Optional_PK_Inverse4Id], [t7].[Id] AS [Id0], [t7].[Id0] AS [Id00], [t7].[Id00] AS [Id000] + FROM [Level1] AS [l12] + INNER JOIN ( + SELECT [l13].[Id], [t8].[Id] AS [Id0], [t8].[Id0] AS [Id00] + FROM [Level1] AS [l13] + INNER JOIN ( + SELECT [l14].[Id], [l15].[Id] AS [Id0] + FROM [Level1] AS [l14] + INNER JOIN [Level1] AS [l15] ON [l14].[Id] = [l15].[Id] + WHERE ([l14].[OneToOne_Required_PK_Date] IS NOT NULL AND [l14].[Level1_Required_Id] IS NOT NULL) AND [l14].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t8] ON [l13].[Id] = [t8].[Id] + WHERE [l13].[Level2_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t7] ON [l12].[Id] = [t7].[Id] + WHERE [l12].[Level3_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t6] ON CASE + WHEN [t4].[Level2_Required_Id] IS NOT NULL AND [t4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t4].[Id] + END = [t6].[OneToMany_Optional_Inverse4Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t9] ON [l].[Id] = [t9].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t9].[Id], [t9].[Id3], [t9].[Id0], [t9].[Id00], [t9].[Id000], [t9].[Id1], [t9].[Id01], [t9].[Id001], [t9].[Id0000], [t9].[Id2], [t9].[Id02], [t9].[Id002], [t9].[Id4], [t9].[Id03], [t9].[Id003]"); + } + + public override async Task Filtered_include_context_accessed_inside_filter(bool async) + { + await base.Filtered_include_context_accessed_inside_filter(async); + + AssertSql( + @"SELECT COUNT(*) +FROM [Level1] AS [l]", + // + @"@__p_0='True' + +SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (@__p_0 = CAST(1 AS bit)) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c], [t0].[Id]"); + } + + public override async Task Include_collection_followed_by_include_reference(bool async) + { + await base.Include_collection_followed_by_include_reference(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id1], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l1].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id1], [t1].[Id0], [t1].[Id00]"); + } + + public override async Task Complex_multi_include_with_order_by_and_paging(bool async) + { + await base.Complex_multi_include_with_order_by_and_paging(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00], [t3].[Id], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id0], [t3].[Id00] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Name] + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l5].[Id] = [t4].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t3] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t3].[OneToMany_Required_Inverse3Id] +ORDER BY [t].[Name], [t].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Id0], [t1].[Id00], [t3].[Id], [t3].[Id0]"); + } + + public override async Task Filtered_include_Skip_Take_with_another_Skip_Take_on_top_level(bool async) + { + await base.Filtered_include_Skip_Take_with_another_Skip_Take_on_top_level(async); + + AssertSql( + @"@__p_0='10' +@__p_1='5' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id00], [t2].[Id01], [t2].[Id000] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Id] DESC + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id] AS [Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) + ORDER BY [l0].[Level2_Name] DESC + OFFSET 2 ROWS FETCH NEXT 4 ROWS ONLY + ) AS [t0] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l2].[Id] = [t3].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level2_Optional_Id] +) AS [t2] +ORDER BY [t].[Id] DESC, [t2].[Level2_Name] DESC, [t2].[Id], [t2].[Id00], [t2].[Id0], [t2].[Id01]"); + } + + public override async Task Skip_Take_on_grouping_element_with_collection_include(bool async) + { + await base.Skip_Take_on_grouping_element_with_collection_include(async); + + AssertSql( + @"SELECT [t].[Date], [t1].[Id], [t1].[Date], [t1].[Name], [t1].[Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id00] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] AS [Id00] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name] + FROM [Level1] AS [l0] + WHERE [t].[Date] = [l0].[Date] + ORDER BY [l0].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [t0].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +) AS [t1] +ORDER BY [t].[Date], [t1].[Name], [t1].[Id], [t1].[Id0]"); + } + + public override async Task Null_check_in_anonymous_type_projection_should_not_be_removed(bool async) + { + await base.Null_check_in_anonymous_type_projection_should_not_be_removed(async); + + AssertSql( + @"SELECT [l].[Id], [t1].[c], [t1].[Level3_Name], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NULL OR [t0].[OneToMany_Required_Inverse3Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [c], [t0].[Level3_Name], [l0].[Id], [l1].[Id] AS [Id0], [t0].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[Level2_Required_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[Id00]"); + } + + public override async Task Filtered_include_Take_without_OrderBy(bool async) + { + await base.Filtered_include_Take_without_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_collection_followed_by_projecting_the_included_collection(bool async) + { + await base.Include_collection_followed_by_projecting_the_included_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Include_collection_and_another_navigation_chain_followed_by_projecting_the_first_collection(bool async) + { + await base.Include_collection_and_another_navigation_chain_followed_by_projecting_the_first_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id0], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id1], [t4].[Level3_Optional_Id], [t4].[Level3_Required_Id], [t4].[Level4_Name], [t4].[OneToMany_Optional_Inverse4Id], [t4].[OneToMany_Required_Inverse4Id], [t4].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id2], [t4].[Id00], [t4].[Id000], [t4].[Id01], [t4].[Id001], [t4].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [l1].[Id] AS [Id2], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id001], [t1].[Id000] AS [Id0000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level3_Optional_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t4].[Id], [t4].[Id2], [t4].[Id0], [t4].[Id00], [t4].[Id000], [t4].[Id1], [t4].[Id01], [t4].[Id001]"); + } + + public override async Task Filtered_include_ThenInclude_OrderBy(bool async) + { + await base.Filtered_include_ThenInclude_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Id1], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], [t0].[Id] AS [Id1], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToMany_Optional_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Level2_Name], [t1].[Id], [t1].[Id0], [t1].[Level3_Name] DESC, [t1].[Id1], [t1].[Id00]"); + } + + public override async Task Filtered_include_complex_three_level_with_middle_having_filter2(bool async) + { + await base.Filtered_include_complex_three_level_with_middle_having_filter2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t8].[Id], [t8].[OneToOne_Required_PK_Date], [t8].[Level1_Optional_Id], [t8].[Level1_Required_Id], [t8].[Level2_Name], [t8].[OneToMany_Optional_Inverse2Id], [t8].[OneToMany_Required_Inverse2Id], [t8].[OneToOne_Optional_PK_Inverse2Id], [t8].[Id0], [t8].[Id1], [t8].[Level2_Optional_Id], [t8].[Level2_Required_Id], [t8].[Level3_Name], [t8].[OneToMany_Optional_Inverse3Id], [t8].[OneToMany_Required_Inverse3Id], [t8].[OneToOne_Optional_PK_Inverse3Id], [t8].[Id00], [t8].[Id000], [t8].[Id10], [t8].[Level3_Optional_Id], [t8].[Level3_Required_Id], [t8].[Level4_Name], [t8].[OneToMany_Optional_Inverse4Id], [t8].[OneToMany_Required_Inverse4Id], [t8].[OneToOne_Optional_PK_Inverse4Id], [t8].[Id01], [t8].[Id0000], [t8].[Id00000], [t8].[Id2], [t8].[Level3_Optional_Id0], [t8].[Level3_Required_Id0], [t8].[Level4_Name0], [t8].[OneToMany_Optional_Inverse4Id0], [t8].[OneToMany_Required_Inverse4Id0], [t8].[OneToOne_Optional_PK_Inverse4Id0], [t8].[Id02], [t8].[Id001], [t8].[Id0001] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], [t7].[Id] AS [Id1], [t7].[Level2_Optional_Id], [t7].[Level2_Required_Id], [t7].[Level3_Name], [t7].[OneToMany_Optional_Inverse3Id], [t7].[OneToMany_Required_Inverse3Id], [t7].[OneToOne_Optional_PK_Inverse3Id], [t7].[Id0] AS [Id00], [t7].[Id00] AS [Id000], [t7].[Id1] AS [Id10], [t7].[Level3_Optional_Id], [t7].[Level3_Required_Id], [t7].[Level4_Name], [t7].[OneToMany_Optional_Inverse4Id], [t7].[OneToMany_Required_Inverse4Id], [t7].[OneToOne_Optional_PK_Inverse4Id], [t7].[Id01], [t7].[Id000] AS [Id0000], [t7].[Id0000] AS [Id00000], [t7].[Id2], [t7].[Level3_Optional_Id0], [t7].[Level3_Required_Id0], [t7].[Level4_Name0], [t7].[OneToMany_Optional_Inverse4Id0], [t7].[OneToMany_Required_Inverse4Id0], [t7].[OneToOne_Optional_PK_Inverse4Id0], [t7].[Id02], [t7].[Id001], [t7].[Id0001], [t7].[c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + OUTER APPLY ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00], [t1].[Id] AS [Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000], [t1].[Id000] AS [Id0000], [t4].[Id] AS [Id2], [t4].[Level3_Optional_Id] AS [Level3_Optional_Id0], [t4].[Level3_Required_Id] AS [Level3_Required_Id0], [t4].[Level4_Name] AS [Level4_Name0], [t4].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [t4].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [t4].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [t4].[Id0] AS [Id02], [t4].[Id00] AS [Id001], [t4].[Id000] AS [Id0001], [t0].[c] + FROM ( + SELECT TOP(1) [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00], CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END AS [c] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE (([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END IS NOT NULL AND ((CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)))) AND (([l2].[Level3_Name] <> N'Foo') OR [l2].[Level3_Name] IS NULL) + ORDER BY CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END + ) AS [t0] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[OneToMany_Optional_Inverse4Id] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level3_Optional_Id], [l9].[Level3_Required_Id], [l9].[Level4_Name], [l9].[OneToMany_Optional_Inverse4Id], [l9].[OneToMany_Required_Inverse4Id], [l9].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00], [t5].[Id00] AS [Id000] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [t6].[Id] AS [Id0], [t6].[Id0] AS [Id00] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id], [l12].[Id] AS [Id0] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l10].[Id] = [t6].[Id] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level3_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t4].[OneToMany_Required_Inverse4Id] + ) AS [t7] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t8] ON [l].[Id] = [t8].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t8].[Id], [t8].[Id0], [t8].[c], [t8].[Id1], [t8].[Id00], [t8].[Id000], [t8].[Id10], [t8].[Id01], [t8].[Id0000], [t8].[Id00000], [t8].[Id2], [t8].[Id02], [t8].[Id001]"); + } + + public override async Task Project_collection_and_root_entity(bool async) + { + await base.Project_collection_and_root_entity(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Include_reference_collection_order_by_reference_navigation(bool async) + { + await base.Include_reference_collection_order_by_reference_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Multiple_optional_navigation_with_Include(bool async) + { + await base.Multiple_optional_navigation_with_Include(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id0], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task SelectMany_with_order_by_and_Include(bool async) + { + await base.SelectMany_with_order_by_and_Include(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [t].[Level2_Name], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_and_ThenInclude_collections_followed_by_projecting_the_first_collection(bool async) + { + await base.Include_and_ThenInclude_collections_followed_by_projecting_the_first_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id1], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l1].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id1], [t1].[Id0], [t1].[Id00]"); + } + + public override async Task Select_nav_prop_collection_one_to_many_required(bool async) + { + await base.Select_nav_prop_collection_one_to_many_required(async); + + AssertSql( + @"SELECT [l].[Id], [t].[c], [t].[Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Include_collection(bool async) + { + await base.Include_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Multiple_complex_include_select(bool async) + { + await base.Multiple_complex_include_select(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id1], [t2].[Id00], [t2].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [t3].[Id] AS [Id0], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [l6].[Id] AS [Id1], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l7].[Id] = [t4].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END = [t3].[Level2_Optional_Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id1], [t2].[Id0], [t2].[Id00]"); + } + + public override async Task Project_collection_navigation_using_ef_property(bool async) + { + await base.Project_collection_navigation_using_ef_property(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Filtered_include_and_non_filtered_include_on_same_navigation1(bool async) + { + await base.Filtered_include_and_non_filtered_include_on_same_navigation1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c], [t0].[Id]"); + } + + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) + { + await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async); + + AssertSql( + @"@__p_0='30' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id00], [t2].[Id01], [t2].[Id000] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id] AS [Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000] + FROM ( + SELECT TOP(40) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) + ) AS [t0] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l2].[Id] = [t3].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level2_Optional_Id] +) AS [t2] +ORDER BY [t].[Id], [t2].[Id], [t2].[Id00], [t2].[Id0], [t2].[Id01]"); + } + + public override async Task Project_collection_and_include(bool async) + { + await base.Project_collection_and_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id]"); + } + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) + { + await base.Complex_query_with_let_collection_projection_FirstOrDefault(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Name], [t1].[Id], [t0].[c] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT [l2].[Name], [l2].[Id] + FROM [Level1] AS [l2] + WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ((([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] = [l3].[OneToMany_Optional_Inverse2Id])) AND ([l3].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END)) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_partially_added_before_Where_and_then_build_upon_with_filtered_include(bool async) + { + await base.Include_partially_added_before_Where_and_then_build_upon_with_filtered_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t].[Id], [t].[Id0], [t0].[Id0], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00], [t4].[Id], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id0], [t4].[Level3_Optional_Id], [t4].[Level3_Required_Id], [t4].[Level4_Name], [t4].[OneToMany_Optional_Inverse4Id], [t4].[OneToMany_Required_Inverse4Id], [t4].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id1], [t4].[Id00], [t4].[Id01], [t4].[Id000], [t4].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t2].[Id], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id0], [t2].[Id00], [t2].[c] + FROM ( + SELECT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], ROW_NUMBER() OVER(PARTITION BY [l4].[OneToMany_Optional_Inverse3Id] ORDER BY CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END) AS [row], CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END AS [c] + FROM [Level1] AS [l4] + INNER JOIN ( + SELECT [l5].[Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l4].[Id] = [t3].[Id] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] + WHERE [t2].[row] <= 3 +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t6].[Id] AS [Id0], [t6].[Level3_Optional_Id], [t6].[Level3_Required_Id], [t6].[Level4_Name], [t6].[OneToMany_Optional_Inverse4Id], [t6].[OneToMany_Required_Inverse4Id], [t6].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id] AS [Id1], [t5].[Id0] AS [Id00], [t6].[Id0] AS [Id01], [t6].[Id00] AS [Id000], [t6].[Id000] AS [Id0000] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l7].[Id] = [t5].[Id] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[Level3_Optional_Id], [l10].[Level3_Required_Id], [l10].[Level4_Name], [l10].[OneToMany_Optional_Inverse4Id], [l10].[OneToMany_Required_Inverse4Id], [l10].[OneToOne_Optional_PK_Inverse4Id], [t7].[Id] AS [Id0], [t7].[Id0] AS [Id00], [t7].[Id00] AS [Id000] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id], [t8].[Id] AS [Id0], [t8].[Id0] AS [Id00] + FROM [Level1] AS [l11] + INNER JOIN ( + SELECT [l12].[Id], [l13].[Id] AS [Id0] + FROM [Level1] AS [l12] + INNER JOIN [Level1] AS [l13] ON [l12].[Id] = [l13].[Id] + WHERE ([l12].[OneToOne_Required_PK_Date] IS NOT NULL AND [l12].[Level1_Required_Id] IS NOT NULL) AND [l12].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t8] ON [l11].[Id] = [t8].[Id] + WHERE [l11].[Level2_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t7] ON [l10].[Id] = [t7].[Id] + WHERE [l10].[Level3_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t6] ON CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END = [t6].[Level3_Optional_Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t4] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t4].[OneToMany_Required_Inverse3Id] +WHERE (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END < 3) OR (CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END > 8) +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[c], [t1].[Id], [t1].[Id0], [t1].[Id00], [t4].[Id], [t4].[Id1], [t4].[Id00], [t4].[Id0], [t4].[Id01], [t4].[Id000]"); + } + + public override async Task Multiple_SelectMany_with_Include(bool async) + { + await base.Multiple_SelectMany_with_Include(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id0], [t0].[Id00], [t2].[Id0], [t2].[Id00], [t2].[Id000], [t5].[Id], [t5].[Level3_Optional_Id], [t5].[Level3_Required_Id], [t5].[Level4_Name], [t5].[OneToMany_Optional_Inverse4Id], [t5].[OneToMany_Required_Inverse4Id], [t5].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id0], [t5].[Id00], [t5].[Id000] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[Level3_Required_Id] +LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level3_Optional_Id], [l9].[Level3_Required_Id], [l9].[Level4_Name], [l9].[OneToMany_Optional_Inverse4Id], [l9].[OneToMany_Required_Inverse4Id], [l9].[OneToOne_Optional_PK_Inverse4Id], [t6].[Id] AS [Id0], [t6].[Id0] AS [Id00], [t6].[Id00] AS [Id000] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [t7].[Id] AS [Id0], [t7].[Id0] AS [Id00] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id], [l12].[Id] AS [Id0] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t7] ON [l10].[Id] = [t7].[Id] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t6] ON [l9].[Id] = [t6].[Id] + WHERE [l9].[Level3_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t5] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t5].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[Id0], [t2].[Id00], [t2].[Id000], [t5].[Id], [t5].[Id0], [t5].[Id00]"); + } + + public override async Task Projecting_collection_with_FirstOrDefault(bool async) + { + await base.Projecting_collection_with_FirstOrDefault(async); + + AssertSql( + @"SELECT [t].[Id], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM ( + SELECT TOP(1) [l].[Id] + FROM [Level1] AS [l] + WHERE [l].[Id] = 1 +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Id], [t0].[Id]"); + } + + public override async Task Orderby_SelectMany_with_Include1(bool async) + { + await base.Orderby_SelectMany_with_Include1(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Select_subquery_single_nested_subquery(bool async) + { + await base.Select_subquery_single_nested_subquery(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[Id00], [t0].[c] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END AS [Id], [l2].[Id] AS [Id0], [t2].[Id] AS [Id1], [t2].[Id0] AS [Id00], [l2].[OneToMany_Optional_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Id0], [t1].[Id1]"); + } + + public override async Task Filtered_include_OrderBy(bool async) + { + await base.Filtered_include_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Level2_Name], [t].[Id]"); + } + + public override async Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) + { + await base.Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id0], [t4].[Id1], [t4].[Id00], [t4].[Id000], [t4].[Id2], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id01], [t4].[Id001], [t4].[Level2_Optional_Id0], [t4].[Level2_Required_Id0], [t4].[Level3_Name0], [t4].[OneToMany_Optional_Inverse3Id0], [t4].[OneToMany_Required_Inverse3Id0], [t4].[OneToOne_Optional_PK_Inverse3Id0] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t2].[Id] AS [Id2], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id0] AS [Id01], [t2].[Id00] AS [Id001], [t0].[Level2_Optional_Id] AS [Level2_Optional_Id0], [t0].[Level2_Required_Id] AS [Level2_Required_Id0], [t0].[Level3_Name] AS [Level3_Name0], [t0].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [t0].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [t0].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [t].[c] + FROM ( + SELECT TOP(2) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ((([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id])) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END + ) AS [t] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [t0].[Level2_Required_Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [t2].[OneToMany_Optional_Inverse3Id] +) AS [t4] +ORDER BY [l].[Id], [t4].[c], [t4].[Id], [t4].[Id0], [t4].[Id1], [t4].[Id00], [t4].[Id000], [t4].[Id2], [t4].[Id01]"); + } + + public override async Task Include_collection_with_groupby_in_subquery_and_filter_after_groupby(bool async) + { + await base.Include_collection_with_groupby_in_subquery_and_filter_after_groupby(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t].[Name], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] +FROM ( + SELECT [l].[Name] + FROM [Level1] AS [l] + GROUP BY [l].[Name] + HAVING ([l].[Name] <> N'Foo') OR [l].[Name] IS NULL +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Name] = [t0].[Name] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Name], [t0].[Id], [t2].[Id]"); + } + + public override async Task Filtered_include_variable_used_inside_filter(bool async) + { + await base.Filtered_include_variable_used_inside_filter(async); + + AssertSql( + @"@__prm_0='Foo' (Size = 4000) + +SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l0].[Level2_Name] <> @__prm_0) OR [l0].[Level2_Name] IS NULL) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c], [t0].[Id]"); + } + + public override async Task Filtered_ThenInclude_OrderBy(bool async) + { + await base.Filtered_ThenInclude_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Id1], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], [t0].[Id] AS [Id1], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToMany_Optional_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Level3_Name], [t1].[Id1], [t1].[Id00]"); + } + + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(bool async) + { + await base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id0], [t4].[Id1], [t4].[Id00], [t4].[Id000], [t4].[Id2], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id01], [t4].[Id001], [t4].[Level2_Optional_Id0], [t4].[Level2_Required_Id0], [t4].[Level3_Name0], [t4].[OneToMany_Optional_Inverse3Id0], [t4].[OneToMany_Required_Inverse3Id0], [t4].[OneToOne_Optional_PK_Inverse3Id0] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t2].[Id] AS [Id2], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id0] AS [Id01], [t2].[Id00] AS [Id001], [t0].[Level2_Optional_Id] AS [Level2_Optional_Id0], [t0].[Level2_Required_Id] AS [Level2_Required_Id0], [t0].[Level3_Name] AS [Level3_Name0], [t0].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [t0].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [t0].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [t].[c] + FROM ( + SELECT TOP(2) [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ((([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id])) AND (([l0].[Level2_Name] <> N'Foo') OR [l0].[Level2_Name] IS NULL) + ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END + ) AS [t] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [t0].[Level2_Required_Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [t2].[OneToMany_Optional_Inverse3Id] +) AS [t4] +ORDER BY [l].[Id], [t4].[c], [t4].[Id], [t4].[Id0], [t4].[Id1], [t4].[Id00], [t4].[Id000], [t4].[Id2], [t4].[Id01]"); + } + + public override async Task Filtered_include_Skip_without_OrderBy(bool async) + { + await base.Filtered_include_Skip_without_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE 1 < [t].[row] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Skip_Take_on_grouping_element_into_non_entity(bool async) + { + await base.Skip_Take_on_grouping_element_into_non_entity(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Name], [t0].[Id] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Name], [t1].[Id], [t1].[Date] + FROM ( + SELECT [l0].[Name], [l0].[Id], [l0].[Date], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task Include_collection_multiple(bool async) + { + await base.Include_collection_multiple(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t9].[Id], [t9].[OneToOne_Required_PK_Date], [t9].[Level1_Optional_Id], [t9].[Level1_Required_Id], [t9].[Level2_Name], [t9].[OneToMany_Optional_Inverse2Id], [t9].[OneToMany_Required_Inverse2Id], [t9].[OneToOne_Optional_PK_Inverse2Id], [t9].[Id0], [t9].[Level2_Optional_Id], [t9].[Level2_Required_Id], [t9].[Level3_Name], [t9].[OneToMany_Optional_Inverse3Id], [t9].[OneToMany_Required_Inverse3Id], [t9].[OneToOne_Optional_PK_Inverse3Id], [t9].[Id1], [t9].[Level3_Optional_Id], [t9].[Level3_Required_Id], [t9].[Level4_Name], [t9].[OneToMany_Optional_Inverse4Id], [t9].[OneToMany_Required_Inverse4Id], [t9].[OneToOne_Optional_PK_Inverse4Id], [t9].[Id2], [t9].[Level2_Optional_Id0], [t9].[Level2_Required_Id0], [t9].[Level3_Name0], [t9].[OneToMany_Optional_Inverse3Id0], [t9].[OneToMany_Required_Inverse3Id0], [t9].[OneToOne_Optional_PK_Inverse3Id0], [t9].[Id3], [t9].[Id00], [t9].[Id000], [t9].[Id01], [t9].[Id001], [t9].[Id0000], [t9].[Id02], [t9].[Id002], [t9].[Id4], [t9].[Level3_Optional_Id0], [t9].[Level3_Required_Id0], [t9].[Level4_Name0], [t9].[OneToMany_Optional_Inverse4Id0], [t9].[OneToMany_Required_Inverse4Id0], [t9].[OneToOne_Optional_PK_Inverse4Id0], [t9].[Id03], [t9].[Id003], [t9].[Id0001] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id] AS [Id2], [t4].[Level2_Optional_Id] AS [Level2_Optional_Id0], [t4].[Level2_Required_Id] AS [Level2_Required_Id0], [t4].[Level3_Name] AS [Level3_Name0], [t4].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [t4].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [t4].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l1].[Id] AS [Id3], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id001], [t1].[Id000] AS [Id0000], [t4].[Id0] AS [Id02], [t4].[Id00] AS [Id002], [t6].[Id] AS [Id4], [t6].[Level3_Optional_Id] AS [Level3_Optional_Id0], [t6].[Level3_Required_Id] AS [Level3_Required_Id0], [t6].[Level4_Name] AS [Level4_Name0], [t6].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [t6].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [t6].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [t6].[Id0] AS [Id03], [t6].[Id00] AS [Id003], [t6].[Id000] AS [Id0001] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level3_Optional_Id] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level2_Optional_Id], [l9].[Level2_Required_Id], [l9].[Level3_Name], [l9].[OneToMany_Optional_Inverse3Id], [l9].[OneToMany_Required_Inverse3Id], [l9].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [l11].[Id] AS [Id0] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t4].[Level2_Optional_Id] + LEFT JOIN ( + SELECT [l12].[Id], [l12].[Level3_Optional_Id], [l12].[Level3_Required_Id], [l12].[Level4_Name], [l12].[OneToMany_Optional_Inverse4Id], [l12].[OneToMany_Required_Inverse4Id], [l12].[OneToOne_Optional_PK_Inverse4Id], [t7].[Id] AS [Id0], [t7].[Id0] AS [Id00], [t7].[Id00] AS [Id000] + FROM [Level1] AS [l12] + INNER JOIN ( + SELECT [l13].[Id], [t8].[Id] AS [Id0], [t8].[Id0] AS [Id00] + FROM [Level1] AS [l13] + INNER JOIN ( + SELECT [l14].[Id], [l15].[Id] AS [Id0] + FROM [Level1] AS [l14] + INNER JOIN [Level1] AS [l15] ON [l14].[Id] = [l15].[Id] + WHERE ([l14].[OneToOne_Required_PK_Date] IS NOT NULL AND [l14].[Level1_Required_Id] IS NOT NULL) AND [l14].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t8] ON [l13].[Id] = [t8].[Id] + WHERE [l13].[Level2_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t7] ON [l12].[Id] = [t7].[Id] + WHERE [l12].[Level3_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t6] ON CASE + WHEN [t4].[Level2_Required_Id] IS NOT NULL AND [t4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t4].[Id] + END = [t6].[OneToMany_Optional_Inverse4Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t9] ON [l].[Id] = [t9].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t9].[Id], [t9].[Id3], [t9].[Id0], [t9].[Id00], [t9].[Id000], [t9].[Id1], [t9].[Id01], [t9].[Id001], [t9].[Id0000], [t9].[Id2], [t9].[Id02], [t9].[Id002], [t9].[Id4], [t9].[Id03], [t9].[Id003]"); + } + + public override async Task Take_on_correlated_collection_in_projection(bool async) + { + await base.Take_on_correlated_collection_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE [t].[row] <= 50 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Optional_navigation_with_Include_ThenInclude(bool async) + { + await base.Optional_navigation_with_Include_ThenInclude(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t3].[Id], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id0], [t3].[Level3_Optional_Id], [t3].[Level3_Required_Id], [t3].[Level4_Name], [t3].[OneToMany_Optional_Inverse4Id], [t3].[OneToMany_Required_Inverse4Id], [t3].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id1], [t3].[Id00], [t3].[Id01], [t3].[Id000], [t3].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t0].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000], [t1].[Id000] AS [Id0000] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END = [t1].[Level3_Optional_Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t3] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t3].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t3].[Id], [t3].[Id1], [t3].[Id00], [t3].[Id0], [t3].[Id01], [t3].[Id000]"); + } + + public override async Task Including_reference_navigation_and_projecting_collection_navigation(bool async) + { + await base.Including_reference_navigation_and_projecting_collection_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t].[Id0], [t0].[Id0], [t0].[Id00], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l].[Id] = [t2].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t0].[Id00], [t2].[Id]"); + } + + public override async Task Optional_navigation_with_Include_and_order(bool async) + { + await base.Optional_navigation_with_Include_and_order(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [t].[Level2_Name], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_partially_added_before_Where_and_then_build_upon(bool async) + { + await base.Include_partially_added_before_Where_and_then_build_upon(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t].[Id], [t].[Id0], [t0].[Id0], [t3].[Id], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id0], [t3].[Level3_Optional_Id], [t3].[Level3_Required_Id], [t3].[Level4_Name], [t3].[OneToMany_Optional_Inverse4Id], [t3].[OneToMany_Required_Inverse4Id], [t3].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id1], [t3].[Id00], [t3].[Id01], [t3].[Id000], [t3].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t1].[Id] AS [Id1], [t1].[Id0] AS [Id00], [t2].[Id0] AS [Id01], [t2].[Id00] AS [Id000], [t2].[Id000] AS [Id0000] + FROM [Level1] AS [l4] + INNER JOIN ( + SELECT [l5].[Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l4].[Id] = [t1].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level3_Optional_Id], [l7].[Level3_Required_Id], [l7].[Level4_Name], [l7].[OneToMany_Optional_Inverse4Id], [l7].[OneToMany_Required_Inverse4Id], [l7].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00], [t4].[Id00] AS [Id000] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l8] + INNER JOIN ( + SELECT [l9].[Id], [l10].[Id] AS [Id0] + FROM [Level1] AS [l9] + INNER JOIN [Level1] AS [l10] ON [l9].[Id] = [l10].[Id] + WHERE ([l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL) AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l8].[Id] = [t5].[Id] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON [l7].[Id] = [t4].[Id] + WHERE [l7].[Level3_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t2] ON CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END = [t2].[Level3_Optional_Id] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t3] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t3].[OneToMany_Optional_Inverse3Id] +WHERE (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END < 3) OR (CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END > 8) +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0], [t3].[Id], [t3].[Id1], [t3].[Id00], [t3].[Id0], [t3].[Id01], [t3].[Id000]"); + } + + public override async Task Include_collection_multiple_with_filter(bool async) + { + await base.Include_collection_multiple_with_filter(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id0], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id1], [t4].[Level3_Optional_Id], [t4].[Level3_Required_Id], [t4].[Level4_Name], [t4].[OneToMany_Optional_Inverse4Id], [t4].[OneToMany_Required_Inverse4Id], [t4].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id2], [t4].[Id00], [t4].[Id000], [t4].[Id01], [t4].[Id001], [t4].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id] AS [Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id1], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [l6].[Id] AS [Id2], [t1].[Id0] AS [Id00], [t1].[Id00] AS [Id000], [t2].[Id0] AS [Id01], [t2].[Id00] AS [Id001], [t2].[Id000] AS [Id0000] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l7].[Id] = [t3].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END = [t1].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[Level3_Optional_Id], [l10].[Level3_Required_Id], [l10].[Level4_Name], [l10].[OneToMany_Optional_Inverse4Id], [l10].[OneToMany_Required_Inverse4Id], [l10].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00], [t5].[Id00] AS [Id000] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id], [t6].[Id] AS [Id0], [t6].[Id0] AS [Id00] + FROM [Level1] AS [l11] + INNER JOIN ( + SELECT [l12].[Id], [l13].[Id] AS [Id0] + FROM [Level1] AS [l12] + INNER JOIN [Level1] AS [l13] ON [l12].[Id] = [l13].[Id] + WHERE ([l12].[OneToOne_Required_PK_Date] IS NOT NULL AND [l12].[Level1_Required_Id] IS NOT NULL) AND [l12].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l11].[Id] = [t6].[Id] + WHERE [l11].[Level2_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t5] ON [l10].[Id] = [t5].[Id] + WHERE [l10].[Level3_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t2] ON CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] + END = [t2].[Level3_Optional_Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[OneToMany_Optional_Inverse2Id] +WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + WHERE ((([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id])) AND (([t0].[Level3_Name] <> N'Foo') OR [t0].[Level3_Name] IS NULL)) > 0 +ORDER BY [l].[Id], [t4].[Id], [t4].[Id2], [t4].[Id0], [t4].[Id00], [t4].[Id000], [t4].[Id1], [t4].[Id01], [t4].[Id001]"); + } + + public override async Task Project_collection_navigation(bool async) + { + await base.Project_collection_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(bool async) + { + await base.LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(async); + + AssertSql( + @"SELECT CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NULL OR [t0].[Level1_Required_Id] IS NULL) OR [t0].[OneToMany_Required_Inverse2Id] IS NULL THEN 0 + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END, [l].[Id], [t0].[Id], [t0].[Id0], [t0].[Id00], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l3].[Id] = [t2].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END = [t1].[OneToMany_Required_Inverse3Id] +WHERE [l].[Name] IN (N'L1 01', N'L1 02') +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0], [t0].[Id00], [t1].[Id], [t1].[Id0]"); + } + + public override async Task Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(bool async) + { + await base.Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[Id1], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], [t0].[Id] AS [Id1], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToMany_Optional_Inverse3Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[Id00]"); + } + + public override async Task Take_on_grouping_element(bool async) + { + await base.Take_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name] DESC) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 10 +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name] DESC"); + } + + public override async Task Null_check_in_Dto_projection_should_not_be_removed(bool async) + { + await base.Null_check_in_Dto_projection_should_not_be_removed(async); + + AssertSql( + @"SELECT [l].[Id], [t1].[c], [t1].[Level3_Name], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[Id00], [t1].[Id000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NULL OR [t0].[OneToMany_Required_Inverse3Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [c], [t0].[Level3_Name], [l0].[Id], [l1].[Id] AS [Id0], [t0].[Id] AS [Id1], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[Level2_Required_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id1], [t1].[Id00]"); + } + + public override async Task Filtered_include_basic_OrderBy_Take(bool async) + { + await base.Filtered_include_basic_OrderBy_Take(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Level2_Name]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Level2_Name], [t0].[Id]"); + } + + public override async Task Skip_Take_on_grouping_element_inside_collection_projection(bool async) + { + await base.Skip_Take_on_grouping_element_inside_collection_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t2].[Date], [t2].[Id], [t2].[Date0], [t2].[Name] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t].[Date], [t0].[Id], [t0].[Date] AS [Date0], [t0].[Name] + FROM ( + SELECT [l0].[Date] + FROM [Level1] AS [l0] + WHERE ([l0].[Name] = [l].[Name]) OR ([l0].[Name] IS NULL AND [l].[Name] IS NULL) + GROUP BY [l0].[Date] + ) AS [t] + LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], ROW_NUMBER() OVER(PARTITION BY [l1].[Date] ORDER BY [l1].[Name]) AS [row] + FROM [Level1] AS [l1] + WHERE ([l1].[Name] = [l].[Name]) OR ([l1].[Name] IS NULL AND [l].[Name] IS NULL) + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) + ) AS [t0] ON [t].[Date] = [t0].[Date] +) AS [t2] +ORDER BY [l].[Id], [t2].[Date], [t2].[Date0], [t2].[Name]"); + } + + public override async Task Filtered_include_is_considered_loaded(bool async) + { + await base.Filtered_include_is_considered_loaded(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t].[c] + FROM ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row], CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END AS [c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[c], [t0].[Id]"); + } + + public override async Task Skip_on_grouping_element(bool async) + { + await base.Skip_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [Level1] AS [l0] + ) AS [t1] + WHERE 1 < [t1].[row] +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task Include_reference_and_collection_order_by(bool async) + { + await base.Include_reference_and_collection_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Skip_Take_Distinct_on_grouping_element(bool async) + { + await base.Skip_Take_Distinct_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name] +FROM ( + SELECT [l].[Date] + FROM [Level1] AS [l] + GROUP BY [l].[Date] +) AS [t] +OUTER APPLY ( + SELECT DISTINCT [t1].[Id], [t1].[Date], [t1].[Name] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name] + FROM [Level1] AS [l0] + WHERE [t].[Date] = [l0].[Date] + ORDER BY [l0].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t1] +) AS [t0] +ORDER BY [t].[Date]"); + } + + public override async Task Include_collection_ThenInclude_two_references(bool async) + { + await base.Include_collection_ThenInclude_two_references(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t4].[Id0], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id1], [t4].[Level3_Optional_Id], [t4].[Level3_Required_Id], [t4].[Level4_Name], [t4].[OneToMany_Optional_Inverse4Id], [t4].[OneToMany_Required_Inverse4Id], [t4].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id2], [t4].[Id00], [t4].[Id000], [t4].[Id01], [t4].[Id001], [t4].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [l1].[Id] AS [Id2], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id001], [t1].[Id000] AS [Id0000] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level3_Optional_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t4].[Id], [t4].[Id2], [t4].[Id0], [t4].[Id00], [t4].[Id000], [t4].[Id1], [t4].[Id01], [t4].[Id001]"); + } + + public override async Task Filtered_include_complex_three_level_with_middle_having_filter1(bool async) + { + await base.Filtered_include_complex_three_level_with_middle_having_filter1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t8].[Id], [t8].[OneToOne_Required_PK_Date], [t8].[Level1_Optional_Id], [t8].[Level1_Required_Id], [t8].[Level2_Name], [t8].[OneToMany_Optional_Inverse2Id], [t8].[OneToMany_Required_Inverse2Id], [t8].[OneToOne_Optional_PK_Inverse2Id], [t8].[Id0], [t8].[Id1], [t8].[Level2_Optional_Id], [t8].[Level2_Required_Id], [t8].[Level3_Name], [t8].[OneToMany_Optional_Inverse3Id], [t8].[OneToMany_Required_Inverse3Id], [t8].[OneToOne_Optional_PK_Inverse3Id], [t8].[Id00], [t8].[Id000], [t8].[Id10], [t8].[Level3_Optional_Id], [t8].[Level3_Required_Id], [t8].[Level4_Name], [t8].[OneToMany_Optional_Inverse4Id], [t8].[OneToMany_Required_Inverse4Id], [t8].[OneToOne_Optional_PK_Inverse4Id], [t8].[Id01], [t8].[Id0000], [t8].[Id00000], [t8].[Id2], [t8].[Level3_Optional_Id0], [t8].[Level3_Required_Id0], [t8].[Level4_Name0], [t8].[OneToMany_Optional_Inverse4Id0], [t8].[OneToMany_Required_Inverse4Id0], [t8].[OneToOne_Optional_PK_Inverse4Id0], [t8].[Id02], [t8].[Id001], [t8].[Id0001] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0], [t7].[Id] AS [Id1], [t7].[Level2_Optional_Id], [t7].[Level2_Required_Id], [t7].[Level3_Name], [t7].[OneToMany_Optional_Inverse3Id], [t7].[OneToMany_Required_Inverse3Id], [t7].[OneToOne_Optional_PK_Inverse3Id], [t7].[Id0] AS [Id00], [t7].[Id00] AS [Id000], [t7].[Id1] AS [Id10], [t7].[Level3_Optional_Id], [t7].[Level3_Required_Id], [t7].[Level4_Name], [t7].[OneToMany_Optional_Inverse4Id], [t7].[OneToMany_Required_Inverse4Id], [t7].[OneToOne_Optional_PK_Inverse4Id], [t7].[Id01], [t7].[Id000] AS [Id0000], [t7].[Id0000] AS [Id00000], [t7].[Id2], [t7].[Level3_Optional_Id0], [t7].[Level3_Required_Id0], [t7].[Level4_Name0], [t7].[OneToMany_Optional_Inverse4Id0], [t7].[OneToMany_Required_Inverse4Id0], [t7].[OneToOne_Optional_PK_Inverse4Id0], [t7].[Id02], [t7].[Id001], [t7].[Id0001], [t7].[c] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + OUTER APPLY ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00], [t1].[Id] AS [Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id000], [t1].[Id000] AS [Id0000], [t4].[Id] AS [Id2], [t4].[Level3_Optional_Id] AS [Level3_Optional_Id0], [t4].[Level3_Required_Id] AS [Level3_Required_Id0], [t4].[Level4_Name] AS [Level4_Name0], [t4].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [t4].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [t4].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [t4].[Id0] AS [Id02], [t4].[Id00] AS [Id001], [t4].[Id000] AS [Id0001], [t0].[c] + FROM ( + SELECT TOP(1) [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00], CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END AS [c] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE (([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END IS NOT NULL AND ((CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)))) AND (([l2].[Level3_Name] <> N'Foo') OR [l2].[Level3_Name] IS NULL) + ORDER BY CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END + ) AS [t0] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[OneToMany_Optional_Inverse4Id] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level3_Optional_Id], [l9].[Level3_Required_Id], [l9].[Level4_Name], [l9].[OneToMany_Optional_Inverse4Id], [l9].[OneToMany_Required_Inverse4Id], [l9].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00], [t5].[Id00] AS [Id000] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [t6].[Id] AS [Id0], [t6].[Id0] AS [Id00] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id], [l12].[Id] AS [Id0] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l10].[Id] = [t6].[Id] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level3_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t4].[OneToMany_Required_Inverse4Id] + ) AS [t7] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t8] ON [l].[Id] = [t8].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t8].[Id], [t8].[Id0], [t8].[c], [t8].[Id1], [t8].[Id00], [t8].[Id000], [t8].[Id10], [t8].[Id01], [t8].[Id0000], [t8].[Id00000], [t8].[Id2], [t8].[Id02], [t8].[Id001]"); + } + + public override async Task Include_ThenInclude_ThenInclude_followed_by_two_nested_selects(bool async) + { + await base.Include_ThenInclude_ThenInclude_followed_by_two_nested_selects(async); + + AssertSql( + @"SELECT [l].[Id], [t4].[Id], [t4].[Level2_Optional_Id], [t4].[Level2_Required_Id], [t4].[Level3_Name], [t4].[OneToMany_Optional_Inverse3Id], [t4].[OneToMany_Required_Inverse3Id], [t4].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id0], [t4].[Level3_Optional_Id], [t4].[Level3_Required_Id], [t4].[Level4_Name], [t4].[OneToMany_Optional_Inverse4Id], [t4].[OneToMany_Required_Inverse4Id], [t4].[OneToOne_Optional_PK_Inverse4Id], [t4].[Id1], [t4].[Id2], [t4].[Id00], [t4].[Id000], [t4].[Id01], [t4].[Id001], [t4].[Id0000] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Level4_Name], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [l0].[Id] AS [Id1], [l1].[Id] AS [Id2], [t0].[Id0] AS [Id00], [t0].[Id00] AS [Id000], [t1].[Id0] AS [Id01], [t1].[Id00] AS [Id001], [t1].[Id000] AS [Id0000], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00], [t2].[Id00] AS [Id000] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [t1].[Level3_Optional_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t4].[Id1], [t4].[Id2], [t4].[Id], [t4].[Id00], [t4].[Id000], [t4].[Id0], [t4].[Id01], [t4].[Id001]"); + } + + public override async Task Project_navigation_and_collection(bool async) + { + await base.Project_navigation_and_collection(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [l].[Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_reference_ThenInclude_collection_order_by(bool async) + { + await base.Include_reference_ThenInclude_collection_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id0], [t0].[Id00] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Id], [t].[Id], [t].[Id0], [t0].[Id], [t0].[Id0]"); + } + + public override async Task SelectMany_with_navigation_and_Distinct_projecting_columns_including_join_key(bool async) + { + await base.SelectMany_with_navigation_and_Distinct_projecting_columns_including_join_key(async); + + AssertSql(); + } + + public override async Task Multiple_complex_includes_self_ref(bool async) + { + await base.Multiple_complex_includes_self_ref(async); + + AssertSql(); + } + + public override async Task + Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) + { + await base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top( + async); + + AssertSql(); + } + + public override async Task Include_collection_with_multiple_orderbys_complex(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex(async); + + AssertSql(); + } + + public override async Task Include_collection_with_multiple_orderbys_complex_repeated(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex_repeated(async); + + AssertSql(); + } + + public override async Task Include_collection_with_multiple_orderbys_complex_repeated_checked(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex_repeated_checked(async); + + AssertSql(); + } + + public override async Task Include_collection_with_multiple_orderbys_member(bool async) + { + await base.Include_collection_with_multiple_orderbys_member(async); + + AssertSql(); + } + + public override async Task Include_collection_with_multiple_orderbys_methodcall(bool async) + { + await base.Include_collection_with_multiple_orderbys_methodcall(async); + + AssertSql(); + } + + public override async Task Include_collection_with_multiple_orderbys_property(bool async) + { + await base.Include_collection_with_multiple_orderbys_property(async); + + AssertSql(); + } + + public override async Task Include_inside_subquery(bool async) + { + await base.Include_inside_subquery(async); + + AssertSql(); + } + + public override async Task Filtered_include_outer_parameter_used_inside_filter(bool async) + { + await base.Filtered_include_outer_parameter_used_inside_filter(async); + + AssertSql(); + } + + public override async Task Include_after_multiple_SelectMany_and_reference_navigation(bool async) + { + await base.Include_after_multiple_SelectMany_and_reference_navigation(async); + + AssertSql(); + } + + public override async Task Include_after_SelectMany_and_multiple_reference_navigations(bool async) + { + await base.Include_after_SelectMany_and_multiple_reference_navigations(async); + + AssertSql(); + } + + public override async Task Required_navigation_with_Include(bool async) + { + await base.Required_navigation_with_Include(async); + + AssertSql(); + } + + public override async Task Required_navigation_with_Include_ThenInclude(bool async) + { + await base.Required_navigation_with_Include_ThenInclude(async); + + AssertSql(); + } + + public override async Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async) + { + await base.SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(async); + + AssertSql(); + } + + public override async Task Complex_query_issue_21665(bool async) + { + await base.Complex_query_issue_21665(async); + + AssertSql(); + } + + public override async Task SelectMany_over_conditional_null_source(bool async) + { + await base.SelectMany_over_conditional_null_source(async); + + AssertSql(); + } + + public override async Task SelectMany_over_conditional_empty_source(bool async) + { + await base.SelectMany_over_conditional_empty_source(async); + + AssertSql(); + } + + public override async Task Queryable_in_subquery_works_when_final_projection_is_List(bool async) + { + await base.Queryable_in_subquery_works_when_final_projection_is_List(async); + + AssertSql(); + } + + public override async Task Include_after_Select(bool async) + { + await base.Include_after_Select(async); + + AssertSql(); + } + + public override async Task Include_after_SelectMany_and_reference_navigation(bool async) + { + await base.Include_after_SelectMany_and_reference_navigation(async); + + AssertSql(); + } + + public override async Task Filtered_include_different_filter_set_on_same_navigation_twice(bool async) + { + await base.Filtered_include_different_filter_set_on_same_navigation_twice(async); + + AssertSql(); + } + + public override async Task Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(bool async) + { + await base.Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(async); + + AssertSql(); + } + + public override async Task Filtered_include_include_parameter_used_inside_filter_throws(bool async) + { + await base.Filtered_include_include_parameter_used_inside_filter_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_with_Distinct_throws(bool async) + { + await base.Filtered_include_with_Distinct_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_calling_methods_directly_on_parameter_throws(bool async) + { + await base.Filtered_include_calling_methods_directly_on_parameter_throws(async); + + AssertSql(); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs index 509624571d8..3287a2b9b60 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqlServerTest.cs @@ -1,14 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using Xunit.Abstractions; -// ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSplitQuerySqlServerTest : ComplexNavigationsCollectionsSplitQueryRelationalTestBase + public class ComplexNavigationsCollectionsSplitQuerySqlServerTest + : ComplexNavigationsCollectionsSplitQueryRelationalTestBase { public ComplexNavigationsCollectionsSplitQuerySqlServerTest( ComplexNavigationsQuerySqlServerFixture fixture, @@ -19,6 +21,10 @@ public ComplexNavigationsCollectionsSplitQuerySqlServerTest( //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + public override async Task Filtered_include_basic_Where(bool async) { await base.Filtered_include_basic_Where(async); @@ -413,9 +419,11 @@ ORDER BY [l1].[Id] ORDER BY [l].[Id], [t0].[Id], [t0].[Id0]"); } - public override async Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(bool async) + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(bool async) { - await base.Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async); + await base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async); AssertSql( @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] @@ -770,7 +778,6 @@ INNER JOIN [LevelThree] AS [l1] ON ([l0].[Id] = [l1].[OneToMany_Optional_Inverse ORDER BY [l].[Id], [l0].[Id]"); } - public override async Task Select_nav_prop_collection_one_to_many_required(bool async) { await base.Select_nav_prop_collection_one_to_many_required(async); @@ -786,9 +793,11 @@ FROM [LevelOne] AS [l] ORDER BY [l].[Id]"); } - public override async Task Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) + public override async Task + Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) { - await base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(async); + await base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top( + async); AssertSql( @"SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l].[Id], [l0].[Id], [l1].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2], [t0].[Id], [t0].[Id0], [t0].[Id1], [t0].[Id2], [l11].[Id], [l12].[Id], [l13].[Id], [l14].[Id], [l14].[Name] @@ -1264,14 +1273,49 @@ public override async Task Queryable_in_subquery_works_when_final_projection_is_ { await base.Queryable_in_subquery_works_when_final_projection_is_List(async); - AssertSql(" "); + AssertSql(); } public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) { - await base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async); + // Nested collection with ToList. Issue #23303. + await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); - AssertSql(" "); + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[c] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[Id]", + // + @"SELECT [t1].[Name], [l].[Id], [t0].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +CROSS APPLY ( + SELECT [l1].[Name] + FROM [LevelOne] AS [l1] + WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l2] + WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND ([l2].[Id] = [t0].[Id])) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id]"); } public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) @@ -1465,9 +1509,11 @@ FROM [LevelOne] AS [l] ORDER BY [l].[Id], [l0].[Id]"); } - public override async Task Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(bool async) + public override async Task + Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(bool async) { - await base.Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(async); + await base + .Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(async); AssertSql( @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] @@ -2723,7 +2769,7 @@ public override async Task Filtered_include_different_filter_set_on_same_navigat await base.Filtered_include_different_filter_set_on_same_navigation_twice(async); AssertSql( - ); + ); } public override async Task Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(bool async) @@ -2731,7 +2777,7 @@ public override async Task Filtered_include_different_filter_set_on_same_navigat await base.Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(async); AssertSql( - ); + ); } public override async Task Filtered_include_include_parameter_used_inside_filter_throws(bool async) @@ -2739,7 +2785,7 @@ public override async Task Filtered_include_include_parameter_used_inside_filter await base.Filtered_include_include_parameter_used_inside_filter_throws(async); AssertSql( - ); + ); } public override async Task Filtered_include_is_considered_loaded(bool async) @@ -2765,7 +2811,7 @@ public override async Task Filtered_include_with_Distinct_throws(bool async) await base.Filtered_include_with_Distinct_throws(async); AssertSql( - ); + ); } public override async Task Filtered_include_calling_methods_directly_on_parameter_throws(bool async) @@ -2773,7 +2819,7 @@ public override async Task Filtered_include_calling_methods_directly_on_paramete await base.Filtered_include_calling_methods_directly_on_parameter_throws(async); AssertSql( - ); + ); } public override async Task Filtered_include_Take_with_another_Take_on_top_level(bool async) @@ -2845,7 +2891,8 @@ OFFSET 2 ROWS FETCH NEXT 4 ROWS ONLY ORDER BY [t].[Id] DESC, [t0].[Name] DESC"); } - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) { await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async); @@ -2872,7 +2919,8 @@ FROM [LevelTwo] AS [l1] ORDER BY [t].[Id]"); } - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) { await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async); @@ -3286,9 +3334,10 @@ FROM [LevelTwo] AS [l0] ) AS [t0] ON ([l].[Id] = [t0].[OneToMany_Optional_Inverse2Id]) AND ([l].[Id] = [t0].[Id])"); } - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) { - await base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async); + await base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async); AssertSql( @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id] @@ -3368,6 +3417,34 @@ OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY ORDER BY [t].[Name], [t].[Id], [t].[Id0], [t0].[Name]"); } + public override async Task SelectMany_over_conditional_null_source(bool async) + { + await base.SelectMany_over_conditional_null_source(async); + + AssertSql(); + } + + public override async Task SelectMany_over_conditional_empty_source(bool async) + { + await base.SelectMany_over_conditional_empty_source(async); + + AssertSql(); + } + + public override async Task Include_after_Select(bool async) + { + await base.Include_after_Select(async); + + AssertSql(); + } + + public override async Task Include_after_SelectMany_and_reference_navigation(bool async) + { + await base.Include_after_SelectMany_and_reference_navigation(async); + + AssertSql(); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs index b47a4cee6b9..fee5411a4a0 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest.cs @@ -1,12 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Threading.Tasks; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest : ComplexNavigationsCollectionsSplitSharedTypeQueryRelationalTestBase< - ComplexNavigationsSharedTypeQuerySqlServerFixture> + public class ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest + : ComplexNavigationsCollectionsSplitSharedTypeQueryRelationalTestBase { public ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest( ComplexNavigationsSharedTypeQuerySqlServerFixture fixture, @@ -16,5 +19,10 @@ public ComplexNavigationsCollectionsSplitSharedTypeQuerySqlServerTest( Fixture.TestSqlLoggerFactory.Clear(); //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } + + public override Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + // Nested collection with ToList. Issue #23303. + => Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index c4b4a4c94c0..cdc90882e88 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -1,12 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using Xunit.Abstractions; +using Xunit.Sdk; -// ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Query { public class ComplexNavigationsQuerySqlServerTest : ComplexNavigationsQueryRelationalTestBase @@ -23,6 +26,10 @@ public ComplexNavigationsQuerySqlServerTest( protected override bool CanExecuteQueryString => true; + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + public override async Task Entity_equality_empty(bool async) { await base.Entity_equality_empty(async); @@ -155,9 +162,9 @@ FROM [LevelTwo] AS [l] WHERE [l0].[Id] IN (1, 2)"); } - public override void Multi_level_include_with_short_circuiting() + public override async Task Multi_level_include_with_short_circuiting(bool async) { - base.Multi_level_include_with_short_circuiting(); + await base.Multi_level_include_with_short_circuiting(async); AssertSql( @"SELECT [f].[Name], [f].[LabelDefaultText], [f].[PlaceholderDefaultText], [m].[DefaultText], [m0].[DefaultText], [t].[Text], [t].[ComplexNavigationStringDefaultText], [t].[LanguageName], [t].[Name], [t].[CultureString], [t0].[Text], [t0].[ComplexNavigationStringDefaultText], [t0].[LanguageName], [t0].[Name], [t0].[CultureString] @@ -1432,59 +1439,35 @@ public override async Task Multiple_required_navigations_with_Include(bool async { await base.Multiple_required_navigations_with_Include(async); - AssertSql( - @"SELECT [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Date], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Level1_Optional_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Level1_Required_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Name], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Optional_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Optional_Self_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Required_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Required_Self_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToOne_Optional_PK_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToOne_Optional_Self2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Optional_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Required_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Name], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Optional_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Optional_Self_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Required_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Required_Self_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToOne_Optional_PK_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToOne_Optional_Self3Id] -FROM [LevelFour] AS [l4] -INNER JOIN [LevelThree] AS [l4.OneToOne_Required_FK_Inverse4] ON [l4].[Level3_Required_Id] = [l4.OneToOne_Required_FK_Inverse4].[Id] -INNER JOIN [LevelTwo] AS [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3] ON [l4.OneToOne_Required_FK_Inverse4].[Level2_Required_Id] = [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id] -LEFT JOIN [LevelThree] AS [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2] ON [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id] = [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Optional_Id]"); + AssertSql(); } public override async Task Multiple_required_navigation_using_multiple_selects_with_Include(bool async) { await base.Multiple_required_navigation_using_multiple_selects_with_Include(async); - AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] -FROM [LevelFour] AS [l1] -INNER JOIN [LevelThree] AS [l2] ON [l1].[Level3_Required_Id] = [l2].[Id] -INNER JOIN [LevelTwo] AS [l] ON [l2].[Level2_Required_Id] = [l].[Id] -LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[Level2_Optional_Id]"); + AssertSql(); } public override async Task Multiple_required_navigation_with_string_based_Include(bool async) { await base.Multiple_required_navigation_with_string_based_Include(async); - AssertSql( - @"SELECT [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Date], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Level1_Optional_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Level1_Required_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Name], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Optional_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Optional_Self_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Required_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Required_Self_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToOne_Optional_PK_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToOne_Optional_Self2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Optional_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Required_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Name], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Optional_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Optional_Self_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Required_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Required_Self_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToOne_Optional_PK_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToOne_Optional_Self3Id] -FROM [LevelFour] AS [l4] -INNER JOIN [LevelThree] AS [l4.OneToOne_Required_FK_Inverse4] ON [l4].[Level3_Required_Id] = [l4.OneToOne_Required_FK_Inverse4].[Id] -INNER JOIN [LevelTwo] AS [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3] ON [l4.OneToOne_Required_FK_Inverse4].[Level2_Required_Id] = [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id] -LEFT JOIN [LevelThree] AS [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2] ON [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id] = [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Optional_Id]"); + AssertSql(); } public override async Task Multiple_required_navigation_using_multiple_selects_with_string_based_Include(bool async) { await base.Multiple_required_navigation_using_multiple_selects_with_string_based_Include(async); - AssertSql( - @"SELECT [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Date], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Level1_Optional_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Level1_Required_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Name], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Optional_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Optional_Self_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Required_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToMany_Required_Self_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToOne_Optional_PK_Inverse2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[OneToOne_Optional_Self2Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Optional_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Required_Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Name], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Optional_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Optional_Self_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Required_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToMany_Required_Self_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToOne_Optional_PK_Inverse3Id], [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[OneToOne_Optional_Self3Id] -FROM [LevelFour] AS [l4] -INNER JOIN [LevelThree] AS [l4.OneToOne_Required_FK_Inverse4] ON [l4].[Level3_Required_Id] = [l4.OneToOne_Required_FK_Inverse4].[Id] -INNER JOIN [LevelTwo] AS [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3] ON [l4.OneToOne_Required_FK_Inverse4].[Level2_Required_Id] = [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id] -LEFT JOIN [LevelThree] AS [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2] ON [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3].[Id] = [l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK2].[Level2_Optional_Id]"); + AssertSql(); } public override async Task Optional_navigation_with_Include(bool async) { await base.Optional_navigation_with_Include(async); - AssertSql( - @"SELECT [l1.OneToOne_Optional_FK1].[Id], [l1.OneToOne_Optional_FK1].[Date], [l1.OneToOne_Optional_FK1].[Level1_Optional_Id], [l1.OneToOne_Optional_FK1].[Level1_Required_Id], [l1.OneToOne_Optional_FK1].[Name], [l1.OneToOne_Optional_FK1].[OneToMany_Optional_Inverse2Id], [l1.OneToOne_Optional_FK1].[OneToMany_Optional_Self_Inverse2Id], [l1.OneToOne_Optional_FK1].[OneToMany_Required_Inverse2Id], [l1.OneToOne_Optional_FK1].[OneToMany_Required_Self_Inverse2Id], [l1.OneToOne_Optional_FK1].[OneToOne_Optional_PK_Inverse2Id], [l1.OneToOne_Optional_FK1].[OneToOne_Optional_Self2Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[Level2_Optional_Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[Level2_Required_Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[Name], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[OneToMany_Optional_Inverse3Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[OneToMany_Optional_Self_Inverse3Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[OneToMany_Required_Inverse3Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[OneToMany_Required_Self_Inverse3Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[OneToOne_Optional_PK_Inverse3Id], [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[OneToOne_Optional_Self3Id] -FROM [LevelOne] AS [l1] -LEFT JOIN [LevelTwo] AS [l1.OneToOne_Optional_FK1] ON [l1].[Id] = [l1.OneToOne_Optional_FK1].[Level1_Optional_Id] -LEFT JOIN [LevelThree] AS [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2] ON [l1.OneToOne_Optional_FK1].[Id] = [l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2].[Level2_Optional_Id]"); + AssertSql(); } public override async Task SelectMany_with_navigation_and_explicit_DefaultIfEmpty(bool async) @@ -1966,16 +1949,7 @@ public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_ { await base.GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer_with_client_method(async); - AssertSql( - @"SELECT [l2_outer].[Level1_Optional_Id], [l2_outer].[Name] -FROM [LevelTwo] AS [l2_outer]", - // - @"@__p_0='2' - -SELECT TOP(@__p_0) [l10].[Id], [l10].[Date], [l10].[Name], [l10].[OneToMany_Optional_Self_Inverse1Id], [l10].[OneToMany_Required_Self_Inverse1Id], [l10].[OneToOne_Optional_Self1Id] -FROM [LevelOne] AS [l10] -LEFT JOIN [LevelTwo] AS [l20] ON [l10].[Id] = [l20].[Level1_Optional_Id] -ORDER BY [l10].[Id]"); + AssertSql(); } public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_inner(bool async) @@ -2069,17 +2043,12 @@ public override async Task GroupJoin_in_subquery_with_client_projection(bool asy await base.GroupJoin_in_subquery_with_client_projection(async); AssertSql( - @"SELECT [l1].[Id], [l1].[Name] -FROM [LevelOne] AS [l1] -WHERE [l1].[Id] < 3", - // - @"SELECT COUNT(*) -FROM [LevelOne] AS [l1_inner0] -LEFT JOIN [LevelTwo] AS [l2_inner0] ON [l1_inner0].[Id] = [l2_inner0].[Level1_Optional_Id]", - // - @"SELECT COUNT(*) -FROM [LevelOne] AS [l1_inner0] -LEFT JOIN [LevelTwo] AS [l2_inner0] ON [l1_inner0].[Id] = [l2_inner0].[Level1_Optional_Id]"); + @"SELECT [l].[Name] +FROM [LevelOne] AS [l] +WHERE (( + SELECT COUNT(*) + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id]) > 7) AND ([l].[Id] < 3)"); } public override async Task GroupJoin_in_subquery_with_client_projection_nested1(bool async) @@ -2087,22 +2056,20 @@ public override async Task GroupJoin_in_subquery_with_client_projection_nested1( await base.GroupJoin_in_subquery_with_client_projection_nested1(async); AssertSql( - @"SELECT [l1_outer].[Id], [l1_outer].[Name] -FROM [LevelOne] AS [l1_outer] -WHERE [l1_outer].[Id] < 2", - // - @"SELECT 1 -FROM [LevelOne] AS [l1_middle0] -LEFT JOIN [LevelTwo] AS [l2_middle0] ON [l1_middle0].[Id] = [l2_middle0].[Level1_Optional_Id] -ORDER BY [l1_middle0].[Id]", - // - @"SELECT COUNT(*) -FROM [LevelOne] AS [l1_inner2] -LEFT JOIN [LevelTwo] AS [l2_inner2] ON [l1_inner2].[Id] = [l2_inner2].[Level1_Optional_Id]", - // - @"SELECT COUNT(*) -FROM [LevelOne] AS [l1_inner2] -LEFT JOIN [LevelTwo] AS [l2_inner2] ON [l1_inner2].[Id] = [l2_inner2].[Level1_Optional_Id]"); + @"SELECT [l].[Name] +FROM [LevelOne] AS [l] +WHERE (( + SELECT COUNT(*) + FROM ( + SELECT TOP(10) [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l1].[Id] AS [Id0], [l1].[Date] AS [Date0], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + WHERE ( + SELECT COUNT(*) + FROM [LevelOne] AS [l2] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Level1_Optional_Id]) > 7 + ORDER BY [l0].[Id] + ) AS [t]) > 4) AND ([l].[Id] < 2)"); } public override async Task GroupJoin_in_subquery_with_client_projection_nested2(bool async) @@ -2110,18 +2077,16 @@ public override async Task GroupJoin_in_subquery_with_client_projection_nested2( await base.GroupJoin_in_subquery_with_client_projection_nested2(async); AssertSql( - @"SELECT [l1_outer].[Id], [l1_outer].[Name] -FROM [LevelOne] AS [l1_outer] -WHERE [l1_outer].[Id] < 2", - // - @"SELECT COUNT(*) -FROM [LevelOne] AS [l1_middle0] -LEFT JOIN [LevelTwo] AS [l2_middle0] ON [l1_middle0].[Id] = [l2_middle0].[Level1_Optional_Id] -WHERE ( + @"SELECT [l].[Name] +FROM [LevelOne] AS [l] +WHERE (( SELECT COUNT(*) - FROM [LevelOne] AS [l1_inner0] - LEFT JOIN [LevelTwo] AS [l2_inner0] ON [l1_inner0].[Id] = [l2_inner0].[Level1_Optional_Id] -) > 7"); + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + WHERE ( + SELECT COUNT(*) + FROM [LevelOne] AS [l2] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Level1_Optional_Id]) > 7) > 4) AND ([l].[Id] < 2)"); } public override async Task GroupJoin_client_method_on_outer(bool async) @@ -2136,12 +2101,13 @@ FROM [LevelOne] AS [l] public override async Task GroupJoin_client_method_in_OrderBy(bool async) { - await base.GroupJoin_client_method_in_OrderBy(async); + await AssertTranslationFailedWithDetails( + () => base.GroupJoin_client_method_in_OrderBy(async), + CoreStrings.QueryUnableToTranslateMethod( + "Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase", + "ClientMethodNullableInt")); - AssertSql( - @"SELECT [l1].[Id], [l2].[Id] -FROM [LevelOne] AS [l1] -LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id]"); + AssertSql(); } public override async Task GroupJoin_without_DefaultIfEmpty(bool async) @@ -2158,22 +2124,14 @@ public override async Task GroupJoin_with_subquery_on_inner(bool async) { await base.GroupJoin_with_subquery_on_inner(async); - AssertSql( - @"SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id] -FROM [LevelOne] AS [l1] -LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id] -ORDER BY [l1].[Id]"); + AssertSql(); } public override async Task GroupJoin_with_subquery_on_inner_and_no_DefaultIfEmpty(bool async) { await base.GroupJoin_with_subquery_on_inner_and_no_DefaultIfEmpty(async); - AssertSql( - @"SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id] -FROM [LevelOne] AS [l1] -LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id] -ORDER BY [l1].[Id]"); + AssertSql(); } public override async Task Optional_navigation_in_subquery_with_unrelated_projection(bool async) @@ -2434,16 +2392,7 @@ public override async Task Level4_Include(bool async) { await base.Level4_Include(async); - AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] -FROM [LevelOne] AS [l1] -LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Id] -LEFT JOIN [LevelThree] AS [l3] ON [l2].[Id] = [l3].[Id] -LEFT JOIN [LevelFour] AS [l4] ON [l3].[Id] = [l4].[Id] -LEFT JOIN [LevelThree] AS [l5] ON [l4].[Level3_Required_Id] = [l5].[Id] -LEFT JOIN [LevelTwo] AS [l] ON [l5].[Level2_Required_Id] = [l].[Id] -LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[Level2_Optional_Id] -WHERE ([l2].[Id] IS NOT NULL AND [l3].[Id] IS NOT NULL) AND [l4].[Id] IS NOT NULL"); + AssertSql(); } public override async Task Comparing_collection_navigation_on_optional_reference_to_null(bool async) @@ -2898,19 +2847,11 @@ FROM [LevelOne] AS [l] LEFT JOIN [LevelThree] AS [l2] ON [l0].[Id] = [l2].[Level2_Optional_Id]"); } - public override void Include17() + public override async Task Include17(bool async) { - base.Include17(); + await base.Include17(async); - AssertSql( - @"SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [t].[Id0], [t].[Date0], [t].[Level1_Optional_Id0], [t].[Level1_Required_Id0], [t].[Name0], [t].[OneToMany_Optional_Inverse2Id0], [t].[OneToMany_Optional_Self_Inverse2Id0], [t].[OneToMany_Required_Inverse2Id0], [t].[OneToMany_Required_Self_Inverse2Id0], [t].[OneToOne_Optional_PK_Inverse2Id0], [t].[OneToOne_Optional_Self2Id0] -FROM ( - SELECT DISTINCT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l0].[Id] AS [Id0], [l0].[Date] AS [Date0], [l0].[Level1_Optional_Id] AS [Level1_Optional_Id0], [l0].[Level1_Required_Id] AS [Level1_Required_Id0], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [l0].[OneToMany_Optional_Self_Inverse2Id] AS [OneToMany_Optional_Self_Inverse2Id0], [l0].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [l0].[OneToMany_Required_Self_Inverse2Id] AS [OneToMany_Required_Self_Inverse2Id0], [l0].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [l0].[OneToOne_Optional_Self2Id] AS [OneToOne_Optional_Self2Id0] - FROM [LevelOne] AS [l1] - LEFT JOIN [LevelTwo] AS [l] ON [l1].[Id] = [l].[Level1_Optional_Id] - LEFT JOIN [LevelTwo] AS [l0] ON [l1].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] -) AS [t] -LEFT JOIN [LevelThree] AS [l2] ON [t].[Id] = [l2].[Level2_Optional_Id]"); + AssertSql(); } public override async Task Include18_1(bool async) @@ -2959,11 +2900,10 @@ FROM [LevelOne] AS [l] LEFT JOIN [LevelTwo] AS [l1] ON [t].[Id] = [l1].[Level1_Optional_Id]"); } - public override void Include18_3() + public override async Task Include18_3(bool async) { - base.Include18_3(); + await base.Include18_3(async); - // issue #15783 AssertSql( @"@__p_0='10' @@ -2978,9 +2918,9 @@ ORDER BY [l0].[Name] ORDER BY [t].[Name0]"); } - public override void Include18_3_1() + public override async Task Include18_3_1(bool async) { - base.Include18_3_1(); + await base.Include18_3_1(async); // issue #15783 AssertSql( @@ -2997,9 +2937,9 @@ ORDER BY [l0].[Name] ORDER BY [t].[Name0]"); } - public override void Include18_3_2() + public override async Task Include18_3_2(bool async) { - base.Include18_3_2(); + await base.Include18_3_2(async); // issue #15783 AssertSql( @@ -3030,9 +2970,9 @@ FROM [LevelOne] AS [l] LEFT JOIN [LevelThree] AS [l1] ON [t].[Id] = [l1].[Level2_Optional_Id]"); } - public override void Include18_4() + public override async Task Include18_4(bool async) { - base.Include18_4(); + await base.Include18_4(async); // issue #15783 AssertSql( @@ -3045,9 +2985,9 @@ FROM [LevelOne] AS [l] LEFT JOIN [LevelTwo] AS [l1] ON [t].[Id] = [l1].[Level1_Optional_Id]"); } - public override void Include18() + public override async Task Include18(bool async) { - base.Include18(); + await base.Include18(async); AssertSql( @"@__p_0='10' @@ -3063,9 +3003,9 @@ ORDER BY [l].[Id] ORDER BY [t].[Id]"); } - public override void Include19() + public override async Task Include19(bool async) { - base.Include19(); + await base.Include19(async); AssertSql( @"SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[Id0], [t].[Date0], [t].[Level1_Optional_Id0], [t].[Level1_Required_Id0], [t].[Name0], [t].[OneToMany_Optional_Inverse2Id0], [t].[OneToMany_Optional_Self_Inverse2Id0], [t].[OneToMany_Required_Inverse2Id0], [t].[OneToMany_Required_Self_Inverse2Id0], [t].[OneToOne_Optional_PK_Inverse2Id0], [t].[OneToOne_Optional_Self2Id0] @@ -3102,9 +3042,9 @@ FROM [LevelOne] AS [l] LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id]"); } - public override void Join_with_navigations_in_the_result_selector2() + public override async Task Join_with_navigations_in_the_result_selector2(bool async) { - base.Join_with_navigations_in_the_result_selector2(); + await base.Join_with_navigations_in_the_result_selector2(async); AssertSql( @"SELECT [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l].[Id], [l0].[Id], [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id] @@ -3115,9 +3055,9 @@ FROM [LevelOne] AS [l] ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); } - public override void Member_pushdown_chain_3_levels_deep() + public override async Task Member_pushdown_chain_3_levels_deep(bool async) { - base.Member_pushdown_chain_3_levels_deep(); + await base.Member_pushdown_chain_3_levels_deep(async); AssertSql( @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] @@ -3150,9 +3090,9 @@ FROM [LevelTwo] AS [l0] ORDER BY [l].[Id]"); } - public override void Member_pushdown_chain_3_levels_deep_entity() + public override async Task Member_pushdown_chain_3_levels_deep_entity(bool async) { - base.Member_pushdown_chain_3_levels_deep_entity(); + await base.Member_pushdown_chain_3_levels_deep_entity(async); AssertSql( @"SELECT [t0].[c], [t1].[c], [t3].[Id], [t3].[Level3_Optional_Id], [t3].[Level3_Required_Id], [t3].[Name], [t3].[OneToMany_Optional_Inverse4Id], [t3].[OneToMany_Optional_Self_Inverse4Id], [t3].[OneToMany_Required_Inverse4Id], [t3].[OneToMany_Required_Self_Inverse4Id], [t3].[OneToOne_Optional_PK_Inverse4Id], [t3].[OneToOne_Optional_Self4Id] @@ -3184,9 +3124,9 @@ FROM [LevelFour] AS [l2] ORDER BY [l].[Id]"); } - public override void Member_pushdown_with_collection_navigation_in_the_middle() + public override async Task Member_pushdown_with_collection_navigation_in_the_middle(bool async) { - base.Member_pushdown_with_collection_navigation_in_the_middle(); + await base.Member_pushdown_with_collection_navigation_in_the_middle(async); AssertSql( @"SELECT ( @@ -3371,15 +3311,30 @@ FROM [LevelOne] AS [l] public override async Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async) { - await base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async); + // DefaultIfEmpty on child collection. Issue #19095. + await Assert.ThrowsAsync( + async () => await base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async)); AssertSql( - @""); + @"SELECT [t0].[l1Name], [t0].[l2Name], [t0].[l3Name] +FROM [LevelOne] AS [l] +OUTER APPLY ( + SELECT [t].[l1Name], [t].[l2Name], [t].[l3Name] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Id] + CROSS APPLY ( + SELECT [l].[Name] AS [l1Name], [l1].[Name] AS [l2Name], [l3].[Name] AS [l3Name] + FROM [LevelFour] AS [l2] + LEFT JOIN [LevelThree] AS [l3] ON [l2].[OneToOne_Optional_PK_Inverse4Id] = [l3].[Id] + WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id]) OR ([l1].[Id] IS NULL AND [l2].[OneToMany_Optional_Inverse4Id] IS NULL) + ) AS [t] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +) AS [t0]"); } - public override void Contains_over_optional_navigation_with_null_constant() + public override async Task Contains_over_optional_navigation_with_null_constant(bool async) { - base.Contains_over_optional_navigation_with_null_constant(); + await base.Contains_over_optional_navigation_with_null_constant(async); AssertSql( @"SELECT CASE @@ -3714,7 +3669,8 @@ FROM [LevelOne] AS [l] WHERE [l].[Id] < 2"); } - public override async Task Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(bool async) + public override async Task Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct( + bool async) { await base.Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(async); @@ -3734,15 +3690,7 @@ public override async Task Complex_query_with_let_collection_SelectMany(bool asy { await base.Complex_query_with_let_collection_SelectMany(async); - AssertSql( - @"SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] -FROM [LevelOne] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id] - FROM [LevelOne] AS [l0] - WHERE [l0].[Id] > 5 -) AS [t] ON [l].[Id] = [t].[Id] -WHERE [l].[Name] IS NOT NULL AND ([l].[Name] LIKE N'L1 0%')"); + AssertSql(); } public override async Task SelectMany_without_collection_selector_returning_queryable(bool async) @@ -3763,72 +3711,253 @@ public override async Task Select_projecting_queryable_followed_by_SelectMany(bo { await base.Select_projecting_queryable_followed_by_SelectMany(async); - AssertSql( - @"SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id] -FROM [LevelOne] AS [l] -CROSS JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] - FROM [LevelTwo] AS [l0] - WHERE [l0].[Id] < 10 -) AS [t]"); + AssertSql(); } public override async Task Select_projecting_queryable_followed_by_Join(bool async) { await base.Select_projecting_queryable_followed_by_Join(async); - AssertSql( - @"SELECT [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] -FROM [LevelOne] AS [l] -INNER JOIN [LevelThree] AS [l0] ON 7 = [l0].[Id]"); + AssertSql(); } public override async Task Select_projecting_queryable_in_anonymous_projection_followed_by_Join(bool async) { await base.Select_projecting_queryable_in_anonymous_projection_followed_by_Join(async); + AssertSql(); + } + + public override async Task Complex_query_with_optional_navigations_and_client_side_evaluation(bool async) + { + await base.Complex_query_with_optional_navigations_and_client_side_evaluation(async); + + AssertSql(); + } + + public override async Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) + { + // Expression cannot be used for return type. Issue #23302. + await Assert.ThrowsAsync( + () => base.Join_with_result_selector_returning_queryable_throws_validation_error(async)); + + AssertSql(); + } + + public override async Task Prune_does_not_throw_null_ref(bool async) + { + await base.Prune_does_not_throw_null_ref(async); + AssertSql( - @"SELECT [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id] + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id] +FROM ( + SELECT NULL AS [empty] +) AS [e] +LEFT JOIN ( + SELECT [l].[Level1_Required_Id] + FROM [LevelTwo] AS [l] + WHERE [l].[Id] < 5 +) AS [t] ON 1 = 1 +CROSS APPLY ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l0] + WHERE [l0].[Id] <> COALESCE([t].[Level1_Required_Id], 0) +) AS [t0]"); + } + + public override async Task Entries_for_detached_entities_are_removed(bool async) + { + await base.Entries_for_detached_entities_are_removed(async); + + AssertSql( + @"SELECT TOP(1) [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id] +FROM [LevelTwo] AS [l] +ORDER BY [l].[Id]"); + } + + public override async Task SelectMany_subquery_with_custom_projection(bool async) + { + await base.SelectMany_subquery_with_custom_projection(async); + + AssertSql( + @"@__p_0='1' + +SELECT TOP(@__p_0) [l0].[Name] FROM [LevelOne] AS [l] -INNER JOIN [LevelThree] AS [l0] ON 7 = [l0].[Id]"); +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); } - public override async Task Project_shadow_properties(bool async) + public override async Task Include_multiple_collections_on_same_level(bool async) { - await base.Project_shadow_properties(async); + await base.Include_multiple_collections_on_same_level(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Simple_level1_include(bool async) + { + await base.Simple_level1_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Id]"); + } + + public override async Task Simple_level1(bool async) + { + await base.Simple_level1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l]"); + } + + public override async Task Simple_level1_level2_include(bool async) + { + await base.Simple_level1_level2_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Id]"); + } + + public override async Task Simple_level1_level2_GroupBy_Count(bool async) + { + await base.Simple_level1_level2_GroupBy_Count(async); + + AssertSql( + @"SELECT COUNT(*) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Id] +GROUP BY [l1].[Name]"); + } + + public override async Task Simple_level1_level2_GroupBy_Having_Count(bool async) + { + await base.Simple_level1_level2_GroupBy_Having_Count(async); + + AssertSql( + @"SELECT COUNT(*) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Id] +LEFT JOIN [LevelTwo] AS [l2] ON [l].[Id] = [l2].[Id] +GROUP BY [l1].[Name] +HAVING MIN(COALESCE([l2].[Id], 0)) > 0"); + } + + public override async Task Simple_level1_level2_level3_include(bool async) + { + await base.Simple_level1_level2_level3_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Id]"); + } + + public override async Task Project_shadow_properties6(bool async) + { + await base.Project_shadow_properties6(async); + + AssertSql( + @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] +FROM [InheritanceOne] AS [i] +WHERE [i].[Discriminator] = N'InheritanceDerived1'"); + } + + public override async Task Project_shadow_properties3(bool async) + { + await base.Project_shadow_properties3(async); AssertSql( - @"SELECT [l].[Id], [l].[OneToOne_Optional_Self1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToMany_Optional_Self_Inverse1Id] -FROM [LevelOne] AS [l]", - // - @"SELECT [l].[Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id] -FROM [LevelTwo] AS [l]", - // @"SELECT [l].[Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToOne_Optional_Self3Id], [l].[OneToMany_Required_Self_Inverse3Id], [l].[OneToMany_Optional_Self_Inverse3Id] -FROM [LevelThree] AS [l]", - // +FROM [LevelThree] AS [l]"); + } + + public override async Task Project_shadow_properties9(bool async) + { + await base.Project_shadow_properties9(async); + + AssertSql( + @"SELECT [i].[Id], [i].[DifferentTypeReference_InheritanceDerived1Id], [i].[InheritanceDerived1Id], [i].[InheritanceDerived1Id1], [i].[InheritanceDerived2Id], [i].[SameTypeReference_InheritanceDerived1Id], [i].[SameTypeReference_InheritanceDerived2Id] +FROM [InheritanceLeafOne] AS [i]"); + } + + public override async Task Project_shadow_properties4(bool async) + { + await base.Project_shadow_properties4(async); + + AssertSql( @"SELECT [l].[Id], [l].[OneToOne_Optional_PK_Inverse4Id], [l].[OneToMany_Required_Inverse4Id], [l].[OneToMany_Optional_Inverse4Id], [l].[OneToOne_Optional_Self4Id], [l].[OneToMany_Required_Self_Inverse4Id], [l].[OneToMany_Optional_Self_Inverse4Id] -FROM [LevelFour] AS [l]", - // - @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] -FROM [InheritanceOne] AS [i]", - // +FROM [LevelFour] AS [l]"); + } + + public override async Task Project_shadow_properties10(bool async) + { + await base.Project_shadow_properties10(async); + + AssertSql( + @"SELECT [i].[Id], [i].[DifferentTypeReference_InheritanceDerived2Id], [i].[InheritanceDerived2Id] +FROM [InheritanceLeafTwo] AS [i]"); + } + + public override async Task Project_shadow_properties5(bool async) + { + await base.Project_shadow_properties5(async); + + AssertSql( @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] -FROM [InheritanceOne] AS [i] -WHERE [i].[Discriminator] = N'InheritanceDerived1'", - // +FROM [InheritanceOne] AS [i]"); + } + + public override async Task Project_shadow_properties7(bool async) + { + await base.Project_shadow_properties7(async); + + AssertSql( @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] FROM [InheritanceOne] AS [i] -WHERE [i].[Discriminator] = N'InheritanceDerived2'", - // +WHERE [i].[Discriminator] = N'InheritanceDerived2'"); + } + + public override async Task Project_shadow_properties8(bool async) + { + await base.Project_shadow_properties8(async); + + AssertSql( @"SELECT [i].[Id], [i].[InheritanceLeaf2Id] -FROM [InheritanceTwo] AS [i]", - // - @"SELECT [i].[Id], [i].[DifferentTypeReference_InheritanceDerived1Id], [i].[InheritanceDerived1Id], [i].[InheritanceDerived1Id1], [i].[InheritanceDerived2Id], [i].[SameTypeReference_InheritanceDerived1Id], [i].[SameTypeReference_InheritanceDerived2Id] -FROM [InheritanceLeafOne] AS [i]", - // - @"SELECT [i].[Id], [i].[DifferentTypeReference_InheritanceDerived2Id], [i].[InheritanceDerived2Id] -FROM [InheritanceLeafTwo] AS [i]"); +FROM [InheritanceTwo] AS [i]"); + } + + public override async Task Project_shadow_properties1(bool async) + { + await base.Project_shadow_properties1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[OneToOne_Optional_Self1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToMany_Optional_Self_Inverse1Id] +FROM [LevelOne] AS [l]"); + } + + public override async Task Project_shadow_properties2(bool async) + { + await base.Project_shadow_properties2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id] +FROM [LevelTwo] AS [l]"); } private void AssertSql(params string[] expected) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs index 8505db8561e..a7a80bb8fd8 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs @@ -1,13 +1,18 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; +using Xunit.Sdk; namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsSharedTypeQuerySqlServerTest : ComplexNavigationsSharedTypeQueryRelationalTestBase< - ComplexNavigationsSharedTypeQuerySqlServerFixture> + public class ComplexNavigationsSharedTypeQuerySqlServerTest : + ComplexNavigationsSharedTypeQueryRelationalTestBase { public ComplexNavigationsSharedTypeQuerySqlServerTest( ComplexNavigationsSharedTypeQuerySqlServerFixture fixture, @@ -18,6 +23,10 @@ public ComplexNavigationsSharedTypeQuerySqlServerTest( //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + public override async Task Simple_level1_include(bool async) { await base.Simple_level1_include(async); @@ -299,6 +308,8138 @@ FROM [Level1] AS [l1] ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); } + public override async Task Complex_query_with_optional_navigations_and_client_side_evaluation(bool async) + { + await base.Complex_query_with_optional_navigations_and_client_side_evaluation(async); + + AssertSql(); + } + + public override async Task Member_over_null_check_ternary_and_nested_anonymous_type(bool async) + { + await base.Member_over_null_check_ternary_and_nested_anonymous_type(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Name], CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NULL OR [t].[Level1_Required_Id] IS NULL) OR [t].[OneToMany_Required_Inverse2Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [t].[Level2_Name], CASE + WHEN [t0].[Level2_Required_Id] IS NULL OR [t0].[OneToMany_Required_Inverse3Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END, [t0].[Level3_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +WHERE (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NULL OR [t].[Level1_Required_Id] IS NULL) OR [t].[OneToMany_Required_Inverse2Id] IS NULL THEN NULL + ELSE [t0].[Level3_Name] +END <> N'L') OR CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NULL OR [t].[Level1_Required_Id] IS NULL) OR [t].[OneToMany_Required_Inverse2Id] IS NULL THEN NULL + ELSE [t0].[Level3_Name] +END IS NULL"); + } + + public override async Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async) + { + // DefaultIfEmpty on child collection. Issue #19095. + await Assert.ThrowsAsync( + async () => await base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async)); + + AssertSql( + @"SELECT [t6].[l1Name], [t6].[l2Name], [t6].[l3Name] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t3].[l1Name], [t3].[l2Name], [t3].[l3Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + CROSS APPLY ( + SELECT [l].[Name] AS [l1Name], [t0].[Level3_Name] AS [l2Name], [t2].[Level3_Name] AS [l3Name] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON [l5].[Id] = [t1].[Id] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level2_Required_Id], [l9].[Level3_Name], [l9].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[OneToOne_Optional_PK_Inverse4Id] = CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] + END + WHERE ([l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL) AND ((CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [l5].[OneToMany_Optional_Inverse4Id]) OR (CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END IS NULL AND [l5].[OneToMany_Optional_Inverse4Id] IS NULL)) + ) AS [t3] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) +) AS [t6]"); + } + + public override async Task OrderBy_collection_count_ThenBy_reference_navigation(bool async) + { + await base.OrderBy_collection_count_ThenBy_reference_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +ORDER BY ( + SELECT COUNT(*) + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Optional_Inverse2Id], [l6].[OneToMany_Required_Inverse2Id], [l6].[OneToOne_Optional_PK_Inverse2Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE ([l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l5].[OneToMany_Required_Inverse3Id]))), [t0].[Level3_Name]"); + } + + public override async Task Element_selector_with_coalesce_repeated_in_aggregate(bool async) + { + await base.Element_selector_with_coalesce_repeated_in_aggregate(async); + + AssertSql( + @"SELECT COUNT(*) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +GROUP BY [t0].[Level3_Name] +HAVING MIN(COALESCE(CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END, 0) + COALESCE(CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END, 0)) > 0"); + } + + public override async Task Sum_with_selector_cast_using_as(bool async) + { + await base.Sum_with_selector_cast_using_as(async); + + AssertSql( + @"SELECT COALESCE(SUM([l].[Id]), 0) +FROM [Level1] AS [l]"); + } + + public override async Task Sum_with_filter_with_include_selector_cast_using_as(bool async) + { + await base.Sum_with_filter_with_include_selector_cast_using_as(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +WHERE [l].[Id] > ( + SELECT COALESCE(SUM(CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END), 0) + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id]))"); + } + + public override async Task Distinct_take_without_orderby(bool async) + { + await base.Distinct_take_without_orderby(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [t2].[Level3_Name] + FROM ( + SELECT DISTINCT TOP(1) [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = [t1].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ) AS [t2] + ORDER BY CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] + END) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3"); + } + + public override async Task Let_let_contains_from_outer_let(bool async) + { + await base.Let_let_contains_from_outer_let(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t2].[Id0], [t2].[Id1], [t2].[Id00], [t2].[Id], [t2].[Id01], [t2].[Id000], [t3].[Id], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Optional_Id], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Optional_Inverse2Id], [t3].[OneToMany_Required_Inverse2Id], [t3].[OneToOne_Optional_PK_Inverse2Id], [t3].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l0].[Id] AS [Id0], [t].[Id] AS [Id1], [t].[Id0] AS [Id00], [t0].[Id0] AS [Id01], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = [t1].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ((([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l6].[OneToMany_Required_Inverse2Id])) AND ([l6].[Id] = [t0].[Level2_Required_Id])) +) AS [t2] +LEFT JOIN ( + SELECT [l8].[Id], [l8].[OneToOne_Required_PK_Date], [l8].[Level1_Optional_Id], [l8].[Level1_Required_Id], [l8].[Level2_Name], [l8].[OneToMany_Optional_Inverse2Id], [l8].[OneToMany_Required_Inverse2Id], [l8].[OneToOne_Optional_PK_Inverse2Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t3] ON [l].[Id] = [t3].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t2].[Id0], [t2].[Id1], [t2].[Id00], [t2].[Id], [t2].[Id01], [t2].[Id000], [t3].[Id]"); + } + + public override async Task Null_check_different_structure_does_not_remove_null_checks(bool async) + { + await base.Null_check_different_structure_does_not_remove_null_checks(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Level3_Optional_Id], [l5].[Level4_Name] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[Level3_Optional_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NULL OR [t].[Level1_Required_Id] IS NULL) OR [t].[OneToMany_Required_Inverse2Id] IS NULL THEN NULL + WHEN [t0].[Level2_Required_Id] IS NULL OR [t0].[OneToMany_Required_Inverse3Id] IS NULL THEN NULL + ELSE [t2].[Level4_Name] +END = N'L4 01'"); + } + + public override async Task Null_conditional_is_not_applied_explicitly_for_optional_navigation(bool async) + { + await base.Null_conditional_is_not_applied_explicitly_for_optional_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t].[Level2_Name] = N'L2 01')"); + } + + public override async Task Multiple_conditionals_in_projection(bool async) + { + await base.Multiple_conditionals_in_projection(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [t0].[Level3_Name], CASE + WHEN [l5].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN [Level1] AS [l5] ON [t].[Level1_Optional_Id] = [l5].[Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Multiple_joins_groupby_predicate(bool async) + { + await base.Multiple_joins_groupby_predicate(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Name], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NULL OR [t0].[Level1_Required_Id] IS NULL) OR [t0].[OneToMany_Required_Inverse2Id] IS NULL THEN N'Foo' + ELSE N'Bar' +END AS [Foo] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t3].[Level3_Name] AS [Key], COUNT(*) AS [Count] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END = CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] + END + WHERE (([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL) + GROUP BY [t3].[Level3_Name] +) AS [t2] ON [l].[Name] = [t2].[Key] +WHERE [t0].[Level2_Name] IS NOT NULL OR ([t2].[Count] > 0)"); + } + + public override async Task Nested_object_constructed_from_group_key_properties(bool async) + { + await base.Nested_object_constructed_from_group_key_properties(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Name], [l].[Date], CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id], [t0].[Level2_Name] AS [Name], [t].[OneToOne_Required_PK_Date] AS [Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([l].[Name]) AS int)), 0) AS [Aggregate] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level1_Required_Id], [l2].[Level2_Name] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Required_Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +GROUP BY [l].[Id], [l].[Date], [l].[Name], CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t0].[Level2_Name]"); + } + + public override async Task Contains_over_optional_navigation_with_null_parameter(bool async) + { + await base.Contains_over_optional_navigation_with_null_parameter(async); + + AssertSql( + @"SELECT CASE + WHEN EXISTS ( + SELECT 1 + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] + WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END"); + } + + public override async Task Member_over_null_check_ternary_and_nested_dto_type(bool async) + { + await base.Member_over_null_check_ternary_and_nested_dto_type(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Name], CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NULL OR [t].[Level1_Required_Id] IS NULL) OR [t].[OneToMany_Required_Inverse2Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +ORDER BY [t].[Level2_Name], [l].[Id]"); + } + + public override async Task Select_with_joined_where_clause_cast_using_as(bool async) + { + await base.Select_with_joined_where_clause_cast_using_as(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END"); + } + + public override async Task Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key(bool async) + { + await base.Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key(async); + + AssertSql( + @"SELECT [t0].[Key] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END % 3 AS [Key], COALESCE(SUM(CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END), 0) AS [Sum] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l0].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + GROUP BY CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END % 3 +) AS [t0] ON ([l].[Id] = [t0].[Key]) AND (CAST(1 AS bit) = CASE + WHEN [t0].[Sum] > 10 THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END)"); + } + + public override async Task Contains_over_optional_navigation_with_null_entity_reference(bool async) + { + await base.Contains_over_optional_navigation_with_null_entity_reference(async); + + AssertSql( + @"SELECT [l].[Name], [t].[Level2_Name] AS [OptionalName], CASE + WHEN EXISTS ( + SELECT 1 + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l4].[Id] = [t1].[Level1_Optional_Id] + WHERE (CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) OR (CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END IS NULL AND CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END IS NULL)) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Contains] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[OneToOne_Optional_PK_Inverse2Id]"); + } + + public override async Task GroupBy_aggregate_where_required_relationship_2(bool async) + { + await base.GroupBy_aggregate_where_required_relationship_2(async); + + AssertSql( + @"SELECT [l2].[Id] AS [Key], MAX(CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) AS [Max] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToMany_Required_Inverse2Id] = [l2].[Id] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +GROUP BY [l2].[Id] +HAVING (MAX(CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) < 2) OR (MAX(CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) > 2)"); + } + + public override async Task Including_reference_navigation_and_projecting_collection_navigation_2(bool async) + { + await base.Including_reference_navigation_and_projecting_collection_navigation_2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Required_Inverse2Id] +LEFT JOIN ( + SELECT [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] + FROM ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l4].[OneToMany_Required_Inverse2Id] ORDER BY CASE + WHEN ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l4].[Id] + END DESC) AS [row] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] + WHERE [t2].[row] <= 1 +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id]"); + } + + public override async Task Union_over_entities_with_different_nullability(bool async) + { + await base.Union_over_entities_with_different_nullability(async); + + AssertSql( + @"SELECT [t1].[Id] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + UNION ALL + SELECT [l4].[Id], [l4].[Date], [l4].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l3].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + LEFT JOIN [Level1] AS [l4] ON [t2].[Level1_Optional_Id] = [l4].[Id] + WHERE (([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND [l4].[Id] IS NULL +) AS [t1]"); + } + + public override async Task Distinct_skip_without_orderby(bool async) + { + await base.Distinct_skip_without_orderby(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [t3].[Level3_Name] + FROM ( + SELECT [t2].[Id], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id] + FROM ( + SELECT DISTINCT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = [t1].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ) AS [t2] + ORDER BY (SELECT 1) + OFFSET 1 ROWS + ) AS [t3] + ORDER BY CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] + END) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3"); + } + + public override async Task GroupBy_aggregate_where_required_relationship(bool async) + { + await base.GroupBy_aggregate_where_required_relationship(async); + + AssertSql( + @"SELECT [l2].[Id] AS [Key], MAX(CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) AS [Max] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToMany_Required_Inverse2Id] = [l2].[Id] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +GROUP BY [l2].[Id] +HAVING (MAX(CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) <> 2) OR MAX(CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) IS NULL"); + } + + public override async Task Contains_over_optional_navigation_with_null_column(bool async) + { + await base.Contains_over_optional_navigation_with_null_column(async); + + AssertSql( + @"SELECT [l].[Name], [t].[Level2_Name] AS [OptionalName], CASE + WHEN EXISTS ( + SELECT 1 + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Level1_Optional_Id] + WHERE ([t0].[Level2_Name] = [t].[Level2_Name]) OR ([t0].[Level2_Name] IS NULL AND [t].[Level2_Name] IS NULL)) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Contains] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Collection_FirstOrDefault_property_accesses_in_projection(bool async) + { + await base.Collection_FirstOrDefault_property_accesses_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], ( + SELECT TOP(1) [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ((([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id])) AND ([l0].[Level2_Name] = N'L2 02')) AS [Pushdown] +FROM [Level1] AS [l] +WHERE [l].[Id] < 3"); + } + + public override async Task SelectMany_with_outside_reference_to_joined_table_correctly_translated_to_apply(bool async) + { + await base.SelectMany_with_outside_reference_to_joined_table_correctly_translated_to_apply(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Required_Id] +INNER JOIN ( + SELECT [t3].[Id] AS [Id1], [t3].[Level2_Required_Id], [t3].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END = CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] + END + WHERE (([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL) +) AS [t2] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END = [t2].[Level2_Required_Id] +INNER JOIN ( + SELECT [t8].[Level3_Required_Id], [t8].[Level4_Name] + FROM [Level1] AS [l9] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Required_Id], [l10].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l9].[Id] = CASE + WHEN ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t6].[Id] + END + LEFT JOIN ( + SELECT [l12].[Id], [l12].[Level2_Required_Id], [l12].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l12] + INNER JOIN ( + SELECT [l13].[Id] + FROM [Level1] AS [l13] + INNER JOIN [Level1] AS [l14] ON [l13].[Id] = [l14].[Id] + WHERE ([l13].[OneToOne_Required_PK_Date] IS NOT NULL AND [l13].[Level1_Required_Id] IS NOT NULL) AND [l13].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t9] ON [l12].[Id] = [t9].[Id] + WHERE [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t7] ON CASE + WHEN ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t6].[Id] + END = CASE + WHEN [t7].[Level2_Required_Id] IS NOT NULL AND [t7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t7].[Id] + END + LEFT JOIN ( + SELECT [l15].[Id], [l15].[Level3_Required_Id], [l15].[Level4_Name], [l15].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l15] + INNER JOIN ( + SELECT [l16].[Id] + FROM [Level1] AS [l16] + INNER JOIN ( + SELECT [l17].[Id] + FROM [Level1] AS [l17] + INNER JOIN [Level1] AS [l18] ON [l17].[Id] = [l18].[Id] + WHERE ([l17].[OneToOne_Required_PK_Date] IS NOT NULL AND [l17].[Level1_Required_Id] IS NOT NULL) AND [l17].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t11] ON [l16].[Id] = [t11].[Id] + WHERE [l16].[Level2_Required_Id] IS NOT NULL AND [l16].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t10] ON [l15].[Id] = [t10].[Id] + WHERE [l15].[Level3_Required_Id] IS NOT NULL AND [l15].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t8] ON CASE + WHEN [t7].[Level2_Required_Id] IS NOT NULL AND [t7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t7].[Id] + END = CASE + WHEN [t8].[Level3_Required_Id] IS NOT NULL AND [t8].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t8].[Id] + END + WHERE ((([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t7].[Level2_Required_Id] IS NOT NULL AND [t7].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ([t8].[Level3_Required_Id] IS NOT NULL AND [t8].[OneToMany_Required_Inverse4Id] IS NOT NULL) +) AS [t5] ON CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id1] +END = [t5].[Level3_Required_Id] +LEFT JOIN [Level1] AS [l19] ON (CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END >= [l19].[Id]) AND (([t5].[Level4_Name] = [l19].[Name]) OR ([t5].[Level4_Name] IS NULL AND [l19].[Name] IS NULL))"); + } + + public override async Task Contains_over_optional_navigation_with_null_constant(bool async) + { + await base.Contains_over_optional_navigation_with_null_constant(async); + + AssertSql( + @"SELECT CASE + WHEN EXISTS ( + SELECT 1 + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] + WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END"); + } + + public override async Task Join_navigation_self_ref(bool async) + { + await base.Join_navigation_self_ref(async); + + AssertSql(); + } + + public override async Task Join_condition_optimizations_applied_correctly_when_anonymous_type_with_multiple_properties(bool async) + { + await base.Join_condition_optimizations_applied_correctly_when_anonymous_type_with_multiple_properties(async); + + AssertSql(); + } + + public override async Task Join_condition_optimizations_applied_correctly_when_anonymous_type_with_single_property(bool async) + { + await base.Join_condition_optimizations_applied_correctly_when_anonymous_type_with_single_property(async); + + AssertSql(); + } + + public override async Task Multiple_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_joined_together(bool async) + { + await base.Multiple_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_joined_together(async); + + AssertSql(); + } + + public override async Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany( + bool async) + { + await base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany(async); + + AssertSql(); + } + + public override async Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2( + bool async) + { + await base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2(async); + + AssertSql(); + } + + public override async Task SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany(bool async) + { + await base.SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany(async); + + AssertSql(); + } + + public override async Task Include8(bool async) + { + await base.Include8(async); + + AssertSql(); + } + + public override async Task Include9(bool async) + { + await base.Include9(async); + + AssertSql(); + } + + public override async Task Join_with_navigations_in_the_result_selector2(bool async) + { + await base.Join_with_navigations_in_the_result_selector2(async); + + AssertSql(); + } + + public override async Task Member_pushdown_chain_3_levels_deep(bool async) + { + await base.Member_pushdown_chain_3_levels_deep(async); + + AssertSql(); + } + + public override async Task Member_pushdown_chain_3_levels_deep_entity(bool async) + { + await base.Member_pushdown_chain_3_levels_deep_entity(async); + + AssertSql(); + } + + public override async Task Member_pushdown_with_collection_navigation_in_the_middle(bool async) + { + await base.Member_pushdown_with_collection_navigation_in_the_middle(async); + + AssertSql(); + } + + public override async Task Complex_query_with_let_collection_SelectMany(bool async) + { + await base.Complex_query_with_let_collection_SelectMany(async); + + AssertSql(); + } + + public override async Task Select_projecting_queryable_followed_by_SelectMany(bool async) + { + await base.Select_projecting_queryable_followed_by_SelectMany(async); + + AssertSql(); + } + + public override async Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) + { + // Expression cannot be used for return type. Issue #23302. + await Assert.ThrowsAsync( + () => base.Join_with_result_selector_returning_queryable_throws_validation_error(async)); + + AssertSql(); + } + + public override async Task Select_projecting_queryable_followed_by_Join(bool async) + { + await base.Select_projecting_queryable_followed_by_Join(async); + + AssertSql(); + } + + public override async Task Select_projecting_queryable_in_anonymous_projection_followed_by_Join(bool async) + { + await base.Select_projecting_queryable_in_anonymous_projection_followed_by_Join(async); + + AssertSql(); + } + + public override async Task SelectMany_with_navigation_filter_and_explicit_DefaultIfEmpty(bool async) + { + await base.SelectMany_with_navigation_filter_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l0].[Id] > 5) +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task SelectMany_with_nested_navigation_and_explicit_DefaultIfEmpty(bool async) + { + await base.SelectMany_with_nested_navigation_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +WHERE [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL"); + } + + public override async Task SelectMany_with_nested_navigation_filter_and_explicit_DefaultIfEmpty(bool async) + { + await base.SelectMany_with_nested_navigation_filter_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND ([l2].[Id] > 5) +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +WHERE [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL"); + } + + public override async Task Prune_does_not_throw_null_ref(bool async) + { + await base.Prune_does_not_throw_null_ref(async); + + AssertSql( + @"SELECT [t1].[Id], [t1].[Date], [t1].[Name] +FROM ( + SELECT NULL AS [empty] +) AS [e] +LEFT JOIN ( + SELECT [t].[Level1_Required_Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END < 5) +) AS [t0] ON 1 = 1 +CROSS APPLY ( + SELECT [l2].[Id], [l2].[Date], [l2].[Name] + FROM [Level1] AS [l2] + WHERE [l2].[Id] <> COALESCE([t0].[Level1_Required_Id], 0) +) AS [t1]"); + } + + public override async Task Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct( + bool async) + { + await base.Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t5].[Id1] AS [Foo], [t5].[Id2] AS [Bar], [t5].[Id3] AS [Baz] +FROM ( + SELECT DISTINCT TOP(@__p_0) [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] + END AS [Id2], CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id1] + END AS [Id3], [l].[Name] AS [Name1], [t0].[Level2_Name] AS [Name2] + FROM [Level1] AS [l] + INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + INNER JOIN ( + SELECT [t3].[Id] AS [Id1], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END = CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] + END + WHERE (([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ) AS [t2] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] + END = [t2].[Level2_Optional_Id] +) AS [t5]"); + } + + public override async Task Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(bool async) + { + await base.Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], ( + SELECT TOP(1) [l0].[Level3_Name] + FROM [Level1] AS [l0] + INNER JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = [t].[Id] + WHERE ([l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (EXISTS ( + SELECT 1 + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ((([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l3].[OneToMany_Optional_Inverse2Id])) AND ([l3].[Level2_Name] = N'L2 02')) AND ((( + SELECT TOP(1) CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ((([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l5].[OneToMany_Optional_Inverse2Id])) AND ([l5].[Level2_Name] = N'L2 02')) = [l0].[OneToMany_Optional_Inverse3Id]) OR (( + SELECT TOP(1) CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ((([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l5].[OneToMany_Optional_Inverse2Id])) AND ([l5].[Level2_Name] = N'L2 02')) IS NULL AND [l0].[OneToMany_Optional_Inverse3Id] IS NULL))) + ORDER BY CASE + WHEN [l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l0].[Id] + END) AS [Pushdown] +FROM [Level1] AS [l] +WHERE [l].[Id] < 2"); + } + + public override async Task Collection_FirstOrDefault_entity_collection_accesses_in_projection(bool async) + { + await base.Collection_FirstOrDefault_entity_collection_accesses_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id0], [t1].[Id00], [t0].[c] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l0].[Level2_Name] = N'L2 02') + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[OneToMany_Optional_Inverse3Id] +WHERE [l].[Id] < 2 +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0], [t1].[Id], [t1].[Id0]"); + } + + public override async Task Collection_FirstOrDefault_entity_reference_accesses_in_projection(bool async) + { + await base.Collection_FirstOrDefault_entity_reference_accesses_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t2].[Id], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id], [t0].[Id], [t0].[Id0], [t0].[Id00]) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t].[Id] AS [Id0], [t].[Id0] AS [Id00] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[Level2_Optional_Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l0].[Level2_Name] = N'L2 02') + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t2] ON [l].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +WHERE [l].[Id] < 3"); + } + + public override async Task SelectMany_without_collection_selector_returning_queryable(bool async) + { + await base.SelectMany_without_collection_selector_returning_queryable(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END < 10) +) AS [t0]"); + } + + public override async Task Null_reference_protection_complex_materialization(bool async) + { + await base.Null_reference_protection_complex_materialization(async); + + AssertSql( + @"SELECT [t2].[Id00], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [t3].[Id0] AS [Id00], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Optional_Id], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Optional_Inverse2Id], [t3].[OneToMany_Required_Inverse2Id], [t3].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [t4].[Id] AS [Id0], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l6] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Optional_Inverse2Id], [l7].[OneToMany_Required_Inverse2Id], [l7].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] + END + WHERE ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Level1_Optional_Id] +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id00] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany4( + bool async) + { + await base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany4(async); + + AssertSql( + @"SELECT [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id0], [t5].[OneToOne_Required_PK_Date], [t5].[Level1_Optional_Id], [t5].[Level1_Required_Id], [t5].[Level2_Name], [t5].[OneToMany_Optional_Inverse2Id], [t5].[OneToMany_Required_Inverse2Id], [t5].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Required_Inverse4Id] +LEFT JOIN ( + SELECT [t6].[Id] AS [Id0], [t6].[OneToOne_Required_PK_Date], [t6].[Level1_Optional_Id], [t6].[Level1_Required_Id], [t6].[Level2_Name], [t6].[OneToMany_Optional_Inverse2Id], [t6].[OneToMany_Required_Inverse2Id], [t6].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l9] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Optional_Id], [l10].[Level1_Required_Id], [l10].[Level2_Name], [l10].[OneToMany_Optional_Inverse2Id], [l10].[OneToMany_Required_Inverse2Id], [l10].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l9].[Id] = CASE + WHEN ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t6].[Id] + END + WHERE ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t5] ON CASE + WHEN [t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t2].[Id] +END = CASE + WHEN ([t5].[OneToOne_Required_PK_Date] IS NOT NULL AND [t5].[Level1_Required_Id] IS NOT NULL) AND [t5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t5].[Id0] +END"); + } + + public override async Task Select_join_with_key_selector_being_a_subquery(bool async) + { + await base.Select_join_with_key_selector_being_a_subquery(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = COALESCE(( + SELECT TOP(1) CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + WHERE ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END), 0)"); + } + + public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_with_orderby_on_inner_sequence_projecting_inner( + bool async) + { + await base.GroupJoin_on_a_subquery_containing_another_GroupJoin_with_orderby_on_inner_sequence_projecting_inner(async); + + AssertSql( + @"@__p_0='2' + +SELECT [l3].[Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [t0].[Level1_Optional_Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [t].[Level1_Optional_Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [t1] +LEFT JOIN [Level1] AS [l3] ON [t1].[Level1_Optional_Id] = [l3].[Id] +ORDER BY [t1].[Id]"); + } + + public override async Task Null_reference_protection_complex(bool async) + { + await base.Null_reference_protection_complex(async); + + AssertSql( + @"SELECT [t2].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [t3].[Id0] AS [Id00], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [t4].[Id] AS [Id0], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] + END + WHERE ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Level1_Optional_Id] +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id00] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Contains_with_subquery_optional_navigation_and_constant_item(bool async) + { + await base.Contains_with_subquery_optional_navigation_and_constant_item(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE EXISTS ( + SELECT 1 + FROM ( + SELECT DISTINCT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND ((CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL))) + ) AS [t0] + WHERE CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = 1)"); + } + + public override async Task Null_reference_protection_complex_client_eval(bool async) + { + await base.Null_reference_protection_complex_client_eval(async); + + AssertSql( + @"SELECT [t2].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [t3].[Id0] AS [Id00], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [t4].[Id] AS [Id0], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] + END + WHERE ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Level1_Optional_Id] +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id00] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Multiple_SelectMany_with_navigation_and_explicit_DefaultIfEmpty(bool async) + { + await base.Multiple_SelectMany_with_navigation_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND ([l2].[Id] > 5) +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +WHERE [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL"); + } + + public override async Task Contains_with_subquery_optional_navigation_scalar_distinct_and_constant_item(bool async) + { + await base.Contains_with_subquery_optional_navigation_scalar_distinct_and_constant_item(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE EXISTS ( + SELECT DISTINCT 1 + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + WHERE (([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND ((CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)))) AND (CAST(LEN([l2].[Level3_Name]) AS int) = 1))"); + } + + public override async Task GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened2(bool async) + { + await base.GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened2(async); + + AssertSql( + @"SELECT CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l3] ON [l1].[Id] = [l3].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + INNER JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task SelectMany_with_nested_required_navigation_filter_and_explicit_DefaultIfEmpty(bool async) + { + await base.SelectMany_with_nested_required_navigation_filter_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND ([l2].[Id] > 5) +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Required_Inverse3Id] +WHERE [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL"); + } + + public override async Task Required_navigation_on_a_subquery_with_complex_projection_and_First(bool async) + { + await base.Required_navigation_on_a_subquery_with_complex_projection_and_First(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [l4].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + INNER JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] + LEFT JOIN [Level1] AS [l4] ON [t0].[Level1_Required_Id] = [l4].[Id] + WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 7)"); + } + + public override async Task SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany3( + bool async) + { + await base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany3(async); + + AssertSql( + @"SELECT [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id], [t5].[Id0], [t5].[OneToOne_Required_PK_Date], [t5].[Level1_Optional_Id], [t5].[Level1_Required_Id], [t5].[Level2_Name], [t5].[OneToMany_Optional_Inverse2Id], [t5].[OneToMany_Required_Inverse2Id], [t5].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[OneToMany_Required_Inverse4Id] +INNER JOIN ( + SELECT [t6].[Id] AS [Id0], [t6].[OneToOne_Required_PK_Date], [t6].[Level1_Optional_Id], [t6].[Level1_Required_Id], [t6].[Level2_Name], [t6].[OneToMany_Optional_Inverse2Id], [t6].[OneToMany_Required_Inverse2Id], [t6].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l9] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Optional_Id], [l10].[Level1_Required_Id], [l10].[Level2_Name], [l10].[OneToMany_Optional_Inverse2Id], [l10].[OneToMany_Required_Inverse2Id], [l10].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l9].[Id] = CASE + WHEN ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t6].[Id] + END + WHERE ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t5] ON CASE + WHEN [t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t2].[Id] +END = CASE + WHEN ([t5].[OneToOne_Required_PK_Date] IS NOT NULL AND [t5].[Level1_Required_Id] IS NOT NULL) AND [t5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t5].[Id0] +END"); + } + + public override async Task Required_navigation_on_a_subquery_with_First_in_predicate(bool async) + { + await base.Required_navigation_on_a_subquery_with_First_in_predicate(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 7)) AND (( + SELECT TOP(1) [l3].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] + WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) = N'L1 02')"); + } + + public override async Task Manually_created_left_join_propagates_nullability_to_navigations(bool async) + { + await base.Manually_created_left_join_propagates_nullability_to_navigations(async); + + AssertSql( + @"SELECT [l3].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level1_Required_Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] +WHERE ([l3].[Name] <> N'L3 02') OR [l3].[Name] IS NULL"); + } + + public override async Task + SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_followed_by_Select_required_navigation_using_different_navs( + bool async) + { + await base + .SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_followed_by_Select_required_navigation_using_different_navs( + async); + + AssertSql( + @"SELECT [l7].[Id], [l7].[Date], [l7].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END = [l7].[Id]"); + } + + public override async Task Optional_navigation_propagates_nullability_to_manually_created_left_join1(bool async) + { + await base.Optional_navigation_propagates_nullability_to_manually_created_left_join1(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t1].[Id] AS [Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Required_Id], [t1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + WHERE ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Level1_Required_Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END"); + } + + public override async Task GroupJoin_on_left_side_being_a_subquery(bool async) + { + await base.GroupJoin_on_left_side_being_a_subquery(async); + + AssertSql( + @"@__p_0='2' + +SELECT TOP(@__p_0) [l].[Id], [t].[Level2_Name] AS [Brand] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +ORDER BY [t].[Level2_Name], [l].[Id]"); + } + + public override async Task + SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_followed_by_Select_required_navigation_using_same_navs( + bool async) + { + await base + .SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_followed_by_Select_required_navigation_using_same_navs( + async); + + AssertSql( + @"SELECT [l19].[Id], [l19].[Date], [l19].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Required_Id], [l5].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = CASE + WHEN [t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level2_Required_Id], [l9].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l9].[Id] = [t6].[Id] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t5] ON [t2].[Level3_Required_Id] = CASE + WHEN [t5].[Level2_Required_Id] IS NOT NULL AND [t5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t5].[Id] +END +LEFT JOIN ( + SELECT [l12].[Id], [l12].[OneToOne_Required_PK_Date], [l12].[Level1_Required_Id], [l12].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l12] + INNER JOIN [Level1] AS [l13] ON [l12].[Id] = [l13].[Id] + WHERE ([l12].[OneToOne_Required_PK_Date] IS NOT NULL AND [l12].[Level1_Required_Id] IS NOT NULL) AND [l12].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t7] ON [t5].[Level2_Required_Id] = CASE + WHEN ([t7].[OneToOne_Required_PK_Date] IS NOT NULL AND [t7].[Level1_Required_Id] IS NOT NULL) AND [t7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t7].[Id] +END +LEFT JOIN ( + SELECT [l14].[Level2_Required_Id], [l14].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l14] + INNER JOIN ( + SELECT [l15].[Id] + FROM [Level1] AS [l15] + INNER JOIN [Level1] AS [l16] ON [l15].[Id] = [l16].[Id] + WHERE ([l15].[OneToOne_Required_PK_Date] IS NOT NULL AND [l15].[Level1_Required_Id] IS NOT NULL) AND [l15].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t9] ON [l14].[Id] = [t9].[Id] + WHERE [l14].[Level2_Required_Id] IS NOT NULL AND [l14].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t8] ON CASE + WHEN ([t7].[OneToOne_Required_PK_Date] IS NOT NULL AND [t7].[Level1_Required_Id] IS NOT NULL) AND [t7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t7].[Id] +END = [t8].[OneToMany_Required_Inverse3Id] +LEFT JOIN ( + SELECT [l17].[Id], [l17].[OneToOne_Required_PK_Date], [l17].[Level1_Required_Id], [l17].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l17] + INNER JOIN [Level1] AS [l18] ON [l17].[Id] = [l18].[Id] + WHERE ([l17].[OneToOne_Required_PK_Date] IS NOT NULL AND [l17].[Level1_Required_Id] IS NOT NULL) AND [l17].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t10] ON [t8].[Level2_Required_Id] = CASE + WHEN ([t10].[OneToOne_Required_PK_Date] IS NOT NULL AND [t10].[Level1_Required_Id] IS NOT NULL) AND [t10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t10].[Id] +END +LEFT JOIN [Level1] AS [l19] ON CASE + WHEN ([t10].[OneToOne_Required_PK_Date] IS NOT NULL AND [t10].[Level1_Required_Id] IS NOT NULL) AND [t10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t10].[Id] +END = [l19].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ([t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL)"); + } + + public override async Task Required_navigation_on_a_subquery_with_First_in_projection(bool async) + { + await base.Required_navigation_on_a_subquery_with_First_in_projection(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [l3].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] + WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 7)"); + } + + public override async Task GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened(bool async) + { + await base.GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened(async); + + AssertSql( + @"SELECT CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l3] ON [l1].[Id] = [l3].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + INNER JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened3(bool async) + { + await base.GroupJoin_with_complex_subquery_with_joins_does_not_get_flattened3(async); + + AssertSql( + @"SELECT CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l3] ON [l1].[Id] = [l3].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Required_Id]"); + } + + public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_inner(bool async) + { + await base.GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_inner(async); + + AssertSql( + @"@__p_0='2' + +SELECT [l3].[Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [t0].[Level1_Optional_Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [t].[Level1_Optional_Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [t1] +LEFT JOIN [Level1] AS [l3] ON [t1].[Level1_Optional_Id] = [l3].[Id] +ORDER BY [t1].[Id]"); + } + + public override async Task SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(bool async) + { + await base.SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Required_Inverse2Id] ORDER BY CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END) AS [row] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l0].[Id] > 5) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Required_Inverse2Id] +WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Select_join_subquery_containing_filter_and_distinct(bool async) + { + await base.Select_join_subquery_containing_filter_and_distinct(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT DISTINCT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END > 2) +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task Optional_navigation_propagates_nullability_to_manually_created_left_join2(bool async) + { + await base.Optional_navigation_propagates_nullability_to_manually_created_left_join2(async); + + AssertSql( + @"SELECT [t0].[Level3_Name] AS [Name1], [t2].[Level2_Name] AS [Name2] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [t3].[Id] AS [Id0], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Level1_Optional_Id] +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id0] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer(bool async) + { + await base.GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer(async); + + AssertSql( + @"@__p_0='2' + +SELECT [t2].[Level2_Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [t1] +LEFT JOIN ( + SELECT [t3].[Level1_Optional_Id], [t3].[Level2_Name] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l3].[Id] = CASE + WHEN ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t3].[Id] + END + WHERE ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = [t2].[Level1_Optional_Id] +ORDER BY [t1].[Id]"); + } + + public override async Task Where_multiple_nav_prop_optional_required(bool async) + { + await base.Where_multiple_nav_prop_optional_required(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +WHERE ([t0].[Level3_Name] <> N'L3 05') OR [t0].[Level3_Name] IS NULL"); + } + + public override async Task Join_navigation_non_key_join(bool async) + { + await base.Join_navigation_non_key_join(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id2], [t].[Level2_Name] AS [Name2], [t0].[Id] AS [Id1], [t0].[Name] AS [Name1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [l2].[Name], [t1].[Level2_Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Level1_Optional_Id] +) AS [t0] ON [t].[Level2_Name] = [t0].[Level2_Name] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Select_nav_prop_reference_optional3(bool async) + { + await base.Select_nav_prop_reference_optional3(async); + + AssertSql( + @"SELECT [l2].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Optional_Id] = [l2].[Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Include11(bool async) + { + await base.Include11(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Level3_Name], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t5].[Id], [t5].[Level2_Optional_Id], [t5].[Level2_Required_Id], [t5].[Level3_Name], [t5].[OneToMany_Optional_Inverse3Id], [t5].[OneToMany_Required_Inverse3Id], [t5].[OneToOne_Optional_PK_Inverse3Id], [t7].[Id], [t7].[Level3_Optional_Id], [t7].[Level3_Required_Id], [t7].[Level4_Name], [t7].[OneToMany_Optional_Inverse4Id], [t7].[OneToMany_Required_Inverse4Id], [t7].[OneToOne_Optional_PK_Inverse4Id], [t10].[Id], [t10].[Level3_Optional_Id], [t10].[Level3_Required_Id], [t10].[Level4_Name], [t10].[OneToMany_Optional_Inverse4Id], [t10].[OneToMany_Required_Inverse4Id], [t10].[OneToOne_Optional_PK_Inverse4Id], [t13].[Id], [t13].[Level2_Optional_Id], [t13].[Level2_Required_Id], [t13].[Level3_Name], [t13].[OneToMany_Optional_Inverse3Id], [t13].[OneToMany_Required_Inverse3Id], [t13].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t2].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN ( + SELECT [l8].[Id], [l8].[OneToOne_Required_PK_Date], [l8].[Level1_Optional_Id], [l8].[Level1_Required_Id], [l8].[Level2_Name], [l8].[OneToMany_Optional_Inverse2Id], [l8].[OneToMany_Required_Inverse2Id], [l8].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t4] ON [l].[Id] = [t4].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l10].[Id], [l10].[Level2_Optional_Id], [l10].[Level2_Required_Id], [l10].[Level3_Name], [l10].[OneToMany_Optional_Inverse3Id], [l10].[OneToMany_Required_Inverse3Id], [l10].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l10].[Id] = [t6].[Id] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t5] ON CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] +END = [t5].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l13].[Id], [l13].[Level3_Optional_Id], [l13].[Level3_Required_Id], [l13].[Level4_Name], [l13].[OneToMany_Optional_Inverse4Id], [l13].[OneToMany_Required_Inverse4Id], [l13].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l13] + INNER JOIN ( + SELECT [l14].[Id] + FROM [Level1] AS [l14] + INNER JOIN ( + SELECT [l15].[Id] + FROM [Level1] AS [l15] + INNER JOIN [Level1] AS [l16] ON [l15].[Id] = [l16].[Id] + WHERE ([l15].[OneToOne_Required_PK_Date] IS NOT NULL AND [l15].[Level1_Required_Id] IS NOT NULL) AND [l15].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t9] ON [l14].[Id] = [t9].[Id] + WHERE [l14].[Level2_Required_Id] IS NOT NULL AND [l14].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t8] ON [l13].[Id] = [t8].[Id] + WHERE [l13].[Level3_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t7] ON CASE + WHEN [t5].[Level2_Required_Id] IS NOT NULL AND [t5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t5].[Id] +END = [t7].[Level3_Optional_Id] +LEFT JOIN ( + SELECT [l17].[Id], [l17].[Level3_Optional_Id], [l17].[Level3_Required_Id], [l17].[Level4_Name], [l17].[OneToMany_Optional_Inverse4Id], [l17].[OneToMany_Required_Inverse4Id], [l17].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l17] + INNER JOIN ( + SELECT [l18].[Id] + FROM [Level1] AS [l18] + INNER JOIN ( + SELECT [l19].[Id] + FROM [Level1] AS [l19] + INNER JOIN [Level1] AS [l20] ON [l19].[Id] = [l20].[Id] + WHERE ([l19].[OneToOne_Required_PK_Date] IS NOT NULL AND [l19].[Level1_Required_Id] IS NOT NULL) AND [l19].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t12] ON [l18].[Id] = [t12].[Id] + WHERE [l18].[Level2_Required_Id] IS NOT NULL AND [l18].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t11] ON [l17].[Id] = [t11].[Id] + WHERE [l17].[Level3_Required_Id] IS NOT NULL AND [l17].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t10] ON CASE + WHEN [t5].[Level2_Required_Id] IS NOT NULL AND [t5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t5].[Id] +END = [t10].[OneToOne_Optional_PK_Inverse4Id] +LEFT JOIN ( + SELECT [l21].[Id], [l21].[Level2_Optional_Id], [l21].[Level2_Required_Id], [l21].[Level3_Name], [l21].[OneToMany_Optional_Inverse3Id], [l21].[OneToMany_Required_Inverse3Id], [l21].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l21] + INNER JOIN ( + SELECT [l22].[Id] + FROM [Level1] AS [l22] + INNER JOIN [Level1] AS [l23] ON [l22].[Id] = [l23].[Id] + WHERE ([l22].[OneToOne_Required_PK_Date] IS NOT NULL AND [l22].[Level1_Required_Id] IS NOT NULL) AND [l22].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t14] ON [l21].[Id] = [t14].[Id] + WHERE [l21].[Level2_Required_Id] IS NOT NULL AND [l21].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t13] ON CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] +END = [t13].[OneToOne_Optional_PK_Inverse3Id]"); + } + + public override async Task Include18_3_3(bool async) + { + await base.Include18_3_3(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id] +FROM ( + SELECT DISTINCT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[Level2_Optional_Id]"); + } + + public override async Task + String_include_multiple_derived_collection_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( + bool async) + { + await base + .String_include_multiple_derived_collection_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( + async); + + AssertSql( + @"SELECT [i].[Id], [i].[Discriminator], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1], [i].[Name], [i0].[Id], [i0].[DifferentTypeCollection_InheritanceDerived1Id], [i0].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeCollection_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [t].[Id], [t].[DifferentTypeReference_InheritanceDerived2Id], [t].[InheritanceDerived2Id], [t].[Name], [t].[Id0], [t].[InheritanceLeaf2Id], [t].[Name0] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[DifferentTypeCollection_InheritanceDerived1Id] +LEFT JOIN ( + SELECT [i1].[Id], [i1].[DifferentTypeReference_InheritanceDerived2Id], [i1].[InheritanceDerived2Id], [i1].[Name], [i2].[Id] AS [Id0], [i2].[InheritanceLeaf2Id], [i2].[Name] AS [Name0] + FROM [InheritanceLeafTwo] AS [i1] + LEFT JOIN [InheritanceTwo] AS [i2] ON [i1].[Id] = [i2].[InheritanceLeaf2Id] +) AS [t] ON [i].[Id] = [t].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[Id], [t].[Id]"); + } + + public override async Task Join_navigation_nested(bool async) + { + await base.Join_navigation_nested(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END AS [Id3], [t2].[Id] AS [Id1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +INNER JOIN ( + SELECT [l5].[Id], [t4].[Id] AS [Id1], [t4].[Level2_Required_Id], [t4].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Level1_Required_Id] + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Optional_Id], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + INNER JOIN ( + SELECT [l9].[Id] + FROM [Level1] AS [l9] + INNER JOIN [Level1] AS [l10] ON [l9].[Id] = [l10].[Id] + WHERE ([l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL) AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l8].[Id] = [t5].[Id] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t3].[Id] + END = [t4].[Level2_Optional_Id] +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id1] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Projection_select_correct_table_from_subquery_when_materialization_is_not_required(bool async) + { + await base.Projection_select_correct_table_from_subquery_when_materialization_is_not_required(async); + + AssertSql( + @"@__p_0='3' + +SELECT TOP(@__p_0) [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Name] = N'L1 03') +ORDER BY CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END"); + } + + public override async Task Projection_select_correct_table_with_anonymous_projection_in_subquery(bool async) + { + await base.Projection_select_correct_table_with_anonymous_projection_in_subquery(async); + + AssertSql( + @"@__p_0='3' + +SELECT TOP(@__p_0) [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +INNER JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +INNER JOIN ( + SELECT [t1].[Level2_Required_Id], [t1].[Level3_Name] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l3].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] + END + WHERE (([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL) +) AS [t2] ON [l2].[Id] = [t2].[Level2_Required_Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Name] = N'L1 03')) AND ([t2].[Level3_Name] = N'L3 08') +ORDER BY [l2].[Id]"); + } + + public override async Task Include14(bool async) + { + await base.Include14(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l4] + INNER JOIN ( + SELECT [l5].[Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l4].[Id] = [t2].[Id] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t1].[Level2_Optional_Id]"); + } + + public override async Task Key_equality_using_property_method_nested2(bool async) + { + await base.Key_equality_using_property_method_nested2(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] = 7)"); + } + + public override async Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access_subquery(bool async) + { + await base.Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access_subquery(async); + + AssertSql( + @"@__p_0='10' + +SELECT [l7].[Name] +FROM ( + SELECT TOP(@__p_0) [t2].[Level1_Required_Id] AS [Level1_Required_Id0], CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END AS [c] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ORDER BY CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END +) AS [t3] +LEFT JOIN [Level1] AS [l7] ON [t3].[Level1_Required_Id0] = [l7].[Id] +ORDER BY [t3].[c]"); + } + + public override async Task Where_complex_predicate_with_with_nav_prop_and_OrElse1(bool async) + { + await base.Where_complex_predicate_with_with_nav_prop_and_OrElse1(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] +LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[Level1_Optional_Id] +LEFT JOIN [Level1] AS [l5] ON [t0].[Level1_Required_Id] = [l5].[Id] +WHERE ([t1].[Level2_Name] = N'L2 01') OR (([l5].[Name] <> N'Bar') OR [l5].[Name] IS NULL)"); + } + + public override async Task OrderBy_nav_prop_reference_optional(bool async) + { + await base.OrderBy_nav_prop_reference_optional(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +ORDER BY [t].[Level2_Name], [l].[Id]"); + } + + public override async Task Include18(bool async) + { + await base.Include18(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Id] +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t].[Id] = [t1].[Level1_Optional_Id] +ORDER BY [t].[Id]"); + } + + public override async Task String_include_multiple_derived_navigation_with_same_name_and_different_type(bool async) + { + await base.String_include_multiple_derived_navigation_with_same_name_and_different_type(async); + + AssertSql( + @"SELECT [i].[Id], [i].[Discriminator], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1], [i].[Name], [i0].[Id], [i0].[DifferentTypeCollection_InheritanceDerived1Id], [i0].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeCollection_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeReference_InheritanceDerived2Id], [i1].[InheritanceDerived2Id], [i1].[Name] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[DifferentTypeReference_InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafTwo] AS [i1] ON [i].[Id] = [i1].[DifferentTypeReference_InheritanceDerived2Id]"); + } + + public override async Task Include3(bool async) + { + await base.Include3(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[OneToOne_Optional_PK_Inverse2Id]"); + } + + public override async Task Join_navigation_key_access_optional(bool async) + { + await base.Join_navigation_key_access_optional(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [l2].[Id] AS [Id1] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l3] ON [l1].[Id] = [l3].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Optional_Id] = [l2].[Id] + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Id1]"); + } + + public override async Task Optional_navigation_inside_method_call_translated_to_join(bool async) + { + await base.Optional_navigation_inside_method_call_translated_to_join(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE [t].[Level2_Name] IS NOT NULL AND ([t].[Level2_Name] LIKE N'L%')"); + } + + public override async Task Multi_level_navigation_with_same_navigation_compared_to_null(bool async) + { + await base.Multi_level_navigation_with_same_navigation_compared_to_null(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[OneToMany_Optional_Inverse3Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Required_Id] = [l7].[Id] +WHERE (((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND (([l7].[Name] <> N'L1 07') OR [l7].[Name] IS NULL)) AND [l7].[Id] IS NOT NULL"); + } + + public override async Task Multi_level_navigation_compared_to_null(bool async) + { + await base.Multi_level_navigation_compared_to_null(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[OneToMany_Optional_Inverse3Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Required_Id] = [l7].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND [l7].[Id] IS NOT NULL"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_compared_to_null1(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_compared_to_null1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +WHERE [t0].[Level2_Required_Id] IS NULL OR [t0].[OneToMany_Required_Inverse3Id] IS NULL"); + } + + public override async Task Where_complex_predicate_with_with_nav_prop_and_OrElse3(bool async) + { + await base.Where_complex_predicate_with_with_nav_prop_and_OrElse3(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l4].[Level2_Optional_Id], [l4].[Level3_Name] + FROM [Level1] AS [l4] + INNER JOIN ( + SELECT [l5].[Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l4].[Id] = [t2].[Id] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END = [t1].[Level2_Optional_Id] +WHERE (([t].[Level2_Name] <> N'L2 05') OR [t].[Level2_Name] IS NULL) OR ([t1].[Level3_Name] = N'L3 05')"); + } + + public override async Task Include2(bool async) + { + await base.Include2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Join_navigation_in_inner_selector(bool async) + { + await base.Join_navigation_in_inner_selector(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id2], [t0].[Id] AS [Id1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [t1].[Id] AS [Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Required_Id], [t1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Level1_Optional_Id] +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Select_nav_prop_reference_optional1(bool async) + { + await base.Select_nav_prop_reference_optional1(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task SelectMany_navigation_comparison3(bool async) + { + await base.SelectMany_navigation_comparison3(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[Level1_Optional_Id] +WHERE (CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] +END = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END) OR (CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] +END IS NULL AND CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END IS NULL)"); + } + + public override async Task Select_multiple_nav_prop_reference_required2(bool async) + { + await base.Select_multiple_nav_prop_reference_required2(async); + + AssertSql( + @"SELECT [l7].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Required_Id] = [l7].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Include12(bool async) + { + await base.Include12(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id]"); + } + + public override async Task Join_navigation_in_outer_selector_translated_to_extra_join(bool async) + { + await base.Join_navigation_in_outer_selector_translated_to_extra_join(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +INNER JOIN ( + SELECT [t1].[Id] AS [Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Required_Id], [t1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + WHERE ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_member_compared_to_value(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_member_compared_to_value(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +WHERE ([t0].[Level3_Name] <> N'L3 05') OR [t0].[Level3_Name] IS NULL"); + } + + public override async Task Result_operator_nav_prop_reference_optional_Sum(bool async) + { + await base.Result_operator_nav_prop_reference_optional_Sum(async); + + AssertSql( + @"SELECT COALESCE(SUM([t].[Level1_Required_Id]), 0) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Key_equality_using_property_method_nested(bool async) + { + await base.Key_equality_using_property_method_nested(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 7"); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_projection4(bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_unrelated_projection4(async); + + AssertSql( + @"@__p_0='20' + +SELECT TOP(@__p_0) [t1].[Id] +FROM ( + SELECT DISTINCT [l].[Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + WHERE ([t0].[Level2_Name] <> N'Foo') OR [t0].[Level2_Name] IS NULL +) AS [t1] +ORDER BY [t1].[Id]"); + } + + public override async Task SelectMany_with_string_based_Include1(bool async) + { + await base.SelectMany_with_string_based_Include1(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id]"); + } + + public override async Task SelectMany_nested_navigation_property_required(bool async) + { + await base.SelectMany_nested_navigation_property_required(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id]"); + } + + public override async Task Key_equality_using_property_method_required(bool async) + { + await base.Key_equality_using_property_method_required(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END > 7"); + } + + public override async Task Optional_navigation_inside_method_call_translated_to_join_keeps_original_nullability(bool async) + { + await base.Optional_navigation_inside_method_call_translated_to_join_keeps_original_nullability(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE DATEADD(day, CAST(10.0E0 AS int), [t].[OneToOne_Required_PK_Date]) > '2000-02-01T00:00:00.0000000'"); + } + + public override async Task Include4(bool async) + { + await base.Include4(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id]"); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_projection3(bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_unrelated_projection3(async); + + AssertSql( + @"SELECT DISTINCT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +WHERE ([t0].[Level2_Name] <> N'Foo') OR [t0].[Level2_Name] IS NULL"); + } + + public override async Task Include18_1_1(bool async) + { + await base.Include18_1_1(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [t].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] + ORDER BY [t].[Level2_Name] +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = [t1].[Level1_Optional_Id] +ORDER BY [t0].[Level2_Name]"); + } + + public override async Task Optional_navigation_projected_into_DTO(bool async) + { + await base.Optional_navigation_projected_into_DTO(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Name], CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END, [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Join_navigation_nested2(bool async) + { + await base.Join_navigation_nested2(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END AS [Id3], [t2].[Id] AS [Id1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +INNER JOIN ( + SELECT [l5].[Id], [t4].[Id] AS [Id1], [t4].[Level2_Required_Id], [t4].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Level1_Required_Id] + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Optional_Id], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + INNER JOIN ( + SELECT [l9].[Id] + FROM [Level1] AS [l9] + INNER JOIN [Level1] AS [l10] ON [l9].[Id] = [l10].[Id] + WHERE ([l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL) AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l8].[Id] = [t5].[Id] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t3].[Id] + END = [t4].[Level2_Optional_Id] +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id1] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Key_equality_using_property_method_and_member_expression1(bool async) + { + await base.Key_equality_using_property_method_and_member_expression1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 7"); + } + + public override async Task Navigation_key_access_optional_comparison(bool async) + { + await base.Navigation_key_access_optional_comparison(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToOne_Optional_PK_Inverse2Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] > 5)"); + } + + public override async Task SelectMany_navigation_property(bool async) + { + await base.SelectMany_navigation_property(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id]"); + } + + public override async Task Join_with_orderby_on_inner_sequence_navigation_non_key_join(bool async) + { + await base.Join_with_orderby_on_inner_sequence_navigation_non_key_join(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id2], [t].[Level2_Name] AS [Name2], [t0].[Id] AS [Id1], [t0].[Name] AS [Name1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [l2].[Name], [t1].[Level2_Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Level1_Optional_Id] +) AS [t0] ON [t].[Level2_Name] = [t0].[Level2_Name] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Correlated_subquery_doesnt_project_unnecessary_columns_in_top_level_join(bool async) + { + await base.Correlated_subquery_doesnt_project_unnecessary_columns_in_top_level_join(async); + + AssertSql( + @"SELECT [l].[Name] AS [Name1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [l2].[Id] AS [Id1] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l3] ON [l1].[Id] = [l3].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Optional_Id] = [l2].[Id] + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Id1] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id] AS [Id0] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l4].[Id] = CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id] + END + WHERE (([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t1].[Level1_Required_Id] = [l].[Id]))"); + } + + public override async Task SelectMany_navigation_property_and_projection(bool async) + { + await base.SelectMany_navigation_property_and_projection(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id]"); + } + + public override async Task Order_by_key_of_navigation_similar_to_projected_gets_optimized_into_FK_access(bool async) + { + await base.Order_by_key_of_navigation_similar_to_projected_gets_optimized_into_FK_access(async); + + AssertSql( + @"SELECT [l7].[Id], [l7].[Date], [l7].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Required_Id] = [l7].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) +ORDER BY CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END"); + } + + public override async Task Navigations_compared_to_each_other2(bool async) + { + await base.Navigations_compared_to_each_other2(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToMany_Required_Inverse2Id] = [l2].[Id] +LEFT JOIN [Level1] AS [l3] ON [t].[OneToOne_Optional_PK_Inverse2Id] = [l3].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l2].[Id] = [l3].[Id]) OR ([l2].[Id] IS NULL AND [l3].[Id] IS NULL))"); + } + + public override async Task SelectMany_with_navigation_and_explicit_DefaultIfEmpty(bool async) + { + await base.SelectMany_with_navigation_and_explicit_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_multiple_result_operator_distinct_count_materializes_main_clause( + bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_multiple_result_operator_distinct_count_materializes_main_clause(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT DISTINCT [l0].[Id], [l0].[Date], [l0].[Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l1].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l0].[Id] = [t0].[Level1_Optional_Id] + ) AS [t1]) > 4"); + } + + public override async Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access2(bool async) + { + await base.Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access2(async); + + AssertSql( + @"SELECT [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) +ORDER BY CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END"); + } + + public override async Task SelectMany_with_string_based_Include2(bool async) + { + await base.SelectMany_with_string_based_Include2(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[Level3_Required_Id]"); + } + + public override async Task Method_call_on_optional_navigation_translates_to_null_conditional_properly_for_arguments(bool async) + { + await base.Method_call_on_optional_navigation_translates_to_null_conditional_properly_for_arguments(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE ([t].[Level2_Name] = N'') OR ([t].[Level2_Name] IS NOT NULL AND (LEFT([t].[Level2_Name], LEN([t].[Level2_Name])) = [t].[Level2_Name]))"); + } + + public override async Task SelectMany_subquery_with_custom_projection(bool async) + { + await base.SelectMany_subquery_with_custom_projection(async); + + AssertSql( + @"@__p_0='1' + +SELECT TOP(@__p_0) [t].[Name] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Level2_Name] AS [Name], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Join_with_navigations_in_the_result_selector1(bool async) + { + await base.Join_with_navigations_in_the_result_selector1(async); + + AssertSql( + @"SELECT [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[Level1_Optional_Id]"); + } + + public override async Task + String_include_multiple_derived_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( + bool async) + { + await base + .String_include_multiple_derived_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( + async); + + AssertSql( + @"SELECT [i].[Id], [i].[Discriminator], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1], [i].[Name], [i0].[Id], [i0].[DifferentTypeCollection_InheritanceDerived1Id], [i0].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeCollection_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeReference_InheritanceDerived2Id], [i1].[InheritanceDerived2Id], [i1].[Name], [i2].[Id], [i2].[InheritanceLeaf2Id], [i2].[Name] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[DifferentTypeReference_InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafTwo] AS [i1] ON [i].[Id] = [i1].[DifferentTypeReference_InheritanceDerived2Id] +LEFT JOIN [InheritanceTwo] AS [i2] ON [i1].[Id] = [i2].[InheritanceLeaf2Id] +ORDER BY [i].[Id], [i0].[Id], [i1].[Id]"); + } + + public override async Task Key_equality_navigation_converted_to_FK(bool async) + { + await base.Key_equality_navigation_converted_to_FK(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] = 1)"); + } + + public override async Task Include10(bool async) + { + await base.Include10(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t3].[Id], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id], [t5].[Level3_Optional_Id], [t5].[Level3_Required_Id], [t5].[Level4_Name], [t5].[OneToMany_Optional_Inverse4Id], [t5].[OneToMany_Required_Inverse4Id], [t5].[OneToOne_Optional_PK_Inverse4Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l].[Id] = [t2].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Level3_Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l7].[Id] = [t4].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t3] ON CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END = [t3].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l10].[Id], [l10].[Level3_Optional_Id], [l10].[Level3_Required_Id], [l10].[Level4_Name], [l10].[OneToMany_Optional_Inverse4Id], [l10].[OneToMany_Required_Inverse4Id], [l10].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id] + FROM [Level1] AS [l11] + INNER JOIN ( + SELECT [l12].[Id] + FROM [Level1] AS [l12] + INNER JOIN [Level1] AS [l13] ON [l12].[Id] = [l13].[Id] + WHERE ([l12].[OneToOne_Required_PK_Date] IS NOT NULL AND [l12].[Level1_Required_Id] IS NOT NULL) AND [l12].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t7] ON [l11].[Id] = [t7].[Id] + WHERE [l11].[Level2_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t6] ON [l10].[Id] = [t6].[Id] + WHERE [l10].[Level3_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t5] ON CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] +END = [t5].[OneToOne_Optional_PK_Inverse4Id]"); + } + + public override async Task Where_navigation_property_to_collection_of_original_entity_type(bool async) + { + await base.Where_navigation_property_to_collection_of_original_entity_type(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToMany_Required_Inverse2Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (( + SELECT COUNT(*) + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE (([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] IS NOT NULL AND ([l2].[Id] = [l3].[OneToMany_Optional_Inverse2Id]))) > 0)"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_compared_to_null2(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_compared_to_null2(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Optional_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Optional_Id] = [l7].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND [l7].[Id] IS NULL"); + } + + public override async Task SelectMany_navigation_property_and_filter_after(bool async) + { + await base.SelectMany_navigation_property_and_filter_after(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END <> 6) OR CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END IS NULL"); + } + + public override async Task Correlated_nested_subquery_doesnt_project_unnecessary_columns_in_top_level(bool async) + { + await base.Correlated_nested_subquery_doesnt_project_unnecessary_columns_in_top_level(async); + + AssertSql( + @"SELECT DISTINCT [l].[Name] +FROM [Level1] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l3].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Optional_Inverse3Id], [l6].[OneToMany_Required_Inverse3Id], [l6].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Optional_Inverse2Id], [l7].[OneToMany_Required_Inverse2Id], [l7].[OneToOne_Optional_PK_Inverse2Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l6].[Id] = [t2].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] + END + WHERE (([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL)))"); + } + + public override async Task OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty(bool async) + { + await base.OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +ORDER BY [t0].[Level2_Name], [l].[Id]"); + } + + public override async Task Where_complex_predicate_with_with_nav_prop_and_OrElse2(bool async) + { + await base.Where_complex_predicate_with_with_nav_prop_and_OrElse2(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +WHERE ([t0].[Level3_Name] = N'L3 05') OR (([t].[Level2_Name] <> N'L2 05') OR [t].[Level2_Name] IS NULL)"); + } + + public override async Task Optional_navigation_inside_nested_method_call_translated_to_join(bool async) + { + await base.Optional_navigation_inside_nested_method_call_translated_to_join(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE [t].[Level2_Name] IS NOT NULL AND (UPPER([t].[Level2_Name]) LIKE N'L%')"); + } + + public override async Task Multiple_SelectMany_calls(bool async) + { + await base.Multiple_SelectMany_calls(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id]"); + } + + public override async Task Navigation_inside_method_call_translated_to_join(bool async) + { + await base.Navigation_inside_method_call_translated_to_join(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE [t].[Level2_Name] IS NOT NULL AND ([t].[Level2_Name] LIKE N'L%')"); + } + + public override async Task Include5(bool async) + { + await base.Include5(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id]"); + } + + public override async Task String_include_multiple_derived_collection_navigation_with_same_name_and_same_type(bool async) + { + await base.String_include_multiple_derived_collection_navigation_with_same_name_and_same_type(async); + + AssertSql( + @"SELECT [i].[Id], [i].[Discriminator], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1], [i].[Name], [i0].[Id], [i0].[DifferentTypeCollection_InheritanceDerived1Id], [i0].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeCollection_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeCollection_InheritanceDerived1Id], [i1].[DifferentTypeReference_InheritanceDerived1Id], [i1].[InheritanceDerived2Id], [i1].[Name], [i1].[SameTypeCollection_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived2Id] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[SameTypeCollection_InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafOne] AS [i1] ON [i].[Id] = [i1].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[Id]"); + } + + public override async Task Navigations_compared_to_each_other4(bool async) + { + await base.Navigations_compared_to_each_other4(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Optional_Inverse3Id], [l6].[OneToMany_Required_Inverse3Id], [l6].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Optional_Inverse2Id], [l7].[OneToMany_Required_Inverse2Id], [l7].[OneToOne_Optional_PK_Inverse2Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = [t2].[Id] + WHERE ([l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL) AND (CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END IS NOT NULL AND ((CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [l5].[OneToMany_Optional_Inverse4Id]) OR (CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END IS NULL AND [l5].[OneToMany_Optional_Inverse4Id] IS NULL))))"); + } + + public override async Task Null_check_removal_applied_recursively(bool async) + { + await base.Null_check_removal_applied_recursively(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Level3_Optional_Id], [l5].[Level4_Name] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[Level3_Optional_Id] +WHERE [t2].[Level4_Name] = N'L4 01'"); + } + + public override async Task SelectMany_where_with_subquery(bool async) + { + await base.SelectMany_where_with_subquery(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Required_Inverse2Id] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l2].[OneToMany_Required_Inverse3Id])))"); + } + + public override async Task Result_operator_nav_prop_reference_optional_Max(bool async) + { + await base.Result_operator_nav_prop_reference_optional_Max(async); + + AssertSql( + @"SELECT MAX([t].[Level1_Required_Id]) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Complex_navigations_with_predicate_projected_into_anonymous_type(bool async) + { + await base.Complex_navigations_with_predicate_projected_into_anonymous_type(async); + + AssertSql( + @"SELECT [l].[Name], CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] +END AS [Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t2].[Level2_Optional_Id] +WHERE ((CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] +END) OR (CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END IS NULL AND CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] +END IS NULL)) AND ((CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] +END <> 7) OR CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] +END IS NULL)"); + } + + public override async Task GroupJoin_without_DefaultIfEmpty(bool async) + { + await base.GroupJoin_without_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Level1_Optional_Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task Key_equality_two_conditions_on_same_navigation(bool async) + { + await base.Key_equality_two_conditions_on_same_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 1) OR (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 2)"); + } + + public override async Task Select_multiple_nav_prop_reference_required(bool async) + { + await base.Select_multiple_nav_prop_reference_required(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id]"); + } + + public override async Task Project_collection_navigation_count(bool async) + { + await base.Project_collection_navigation_count(async); + + AssertSql( + @"SELECT [l].[Id], ( + SELECT COUNT(*) + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND ((CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)))) AS [Count] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Include18_2(bool async) + { + await base.Include18_2(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] + WHERE ([t].[Level2_Name] <> N'Foo') OR [t].[Level2_Name] IS NULL +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = [t1].[Level1_Optional_Id]"); + } + + public override async Task Include13(bool async) + { + await base.Include13(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Include_with_optional_navigation(bool async) + { + await base.Include_with_optional_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE ([t].[Level2_Name] <> N'L2 05') OR [t].[Level2_Name] IS NULL"); + } + + public override async Task GroupJoin_on_right_side_being_a_subquery(bool async) + { + await base.GroupJoin_on_right_side_being_a_subquery(async); + + AssertSql( + @"@__p_0='2' + +SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id], [t0].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT TOP(@__p_0) [l2].[Id], [l2].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Level1_Optional_Id] + ORDER BY [t1].[Level2_Name] +) AS [t0] ON [t].[Level1_Optional_Id] = [t0].[Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Multiple_SelectMany_with_string_based_Include(bool async) + { + await base.Multiple_SelectMany_with_string_based_Include(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id], [t2].[Level3_Optional_Id], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Optional_Inverse4Id], [t2].[OneToMany_Required_Inverse4Id], [t2].[OneToOne_Optional_PK_Inverse4Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[Level3_Required_Id]"); + } + + public override async Task Where_navigation_property_to_collection2(bool async) + { + await base.Where_navigation_property_to_collection2(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND (( + SELECT COUNT(*) + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id], [l8].[OneToOne_Required_PK_Date], [l8].[Level1_Optional_Id], [l8].[Level1_Required_Id], [l8].[Level2_Name], [l8].[OneToMany_Optional_Inverse2Id], [l8].[OneToMany_Required_Inverse2Id], [l8].[OneToOne_Optional_PK_Inverse2Id], [l9].[Id] AS [Id0] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l7].[Id] = [t3].[Id] + WHERE ([l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END IS NOT NULL AND ((CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END = [l7].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END IS NULL AND [l7].[OneToMany_Optional_Inverse3Id] IS NULL)))) > 0)"); + } + + public override async Task GroupJoin_in_subquery_with_client_projection(bool async) + { + await base.GroupJoin_in_subquery_with_client_projection(async); + + AssertSql( + @"SELECT [l].[Name] +FROM [Level1] AS [l] +WHERE (( + SELECT COUNT(*) + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l1].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l0].[Id] = [t0].[Level1_Optional_Id]) > 7) AND ([l].[Id] < 3)"); + } + + public override async Task Query_source_materialization_bug_4547(bool async) + { + await base.Query_source_materialization_bug_4547(async); + + AssertSql( + @"SELECT [l5].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +INNER JOIN [Level1] AS [l5] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = ( + SELECT TOP(1) CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id1] + END + FROM [Level1] AS [l6] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Optional_Inverse2Id], [l7].[OneToMany_Required_Inverse2Id], [l7].[OneToOne_Optional_PK_Inverse2Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l6].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Date], [l9].[Name], [t4].[Id] AS [Id0], [t4].[OneToOne_Required_PK_Date], [t4].[Level1_Optional_Id], [t4].[Level1_Required_Id], [t4].[Level2_Name], [t4].[OneToMany_Optional_Inverse2Id], [t4].[OneToMany_Required_Inverse2Id], [t4].[OneToOne_Optional_PK_Inverse2Id], [t5].[Id] AS [Id1], [t5].[Level2_Optional_Id], [t5].[Level2_Required_Id], [t5].[Level3_Name], [t5].[OneToMany_Optional_Inverse3Id], [t5].[OneToMany_Required_Inverse3Id], [t5].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id0] AS [Id00], [t5].[Id0] AS [Id01], [t5].[Id00] AS [Id000] + FROM [Level1] AS [l9] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Optional_Id], [l10].[Level1_Required_Id], [l10].[Level2_Name], [l10].[OneToMany_Optional_Inverse2Id], [l10].[OneToMany_Required_Inverse2Id], [l10].[OneToOne_Optional_PK_Inverse2Id], [l11].[Id] AS [Id0] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l9].[Id] = CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] + END + LEFT JOIN ( + SELECT [l12].[Id], [l12].[Level2_Optional_Id], [l12].[Level2_Required_Id], [l12].[Level3_Name], [l12].[OneToMany_Optional_Inverse3Id], [l12].[OneToMany_Required_Inverse3Id], [l12].[OneToOne_Optional_PK_Inverse3Id], [t6].[Id] AS [Id0], [t6].[Id0] AS [Id00] + FROM [Level1] AS [l12] + INNER JOIN ( + SELECT [l13].[Id], [l13].[OneToOne_Required_PK_Date], [l13].[Level1_Optional_Id], [l13].[Level1_Required_Id], [l13].[Level2_Name], [l13].[OneToMany_Optional_Inverse2Id], [l13].[OneToMany_Required_Inverse2Id], [l13].[OneToOne_Optional_PK_Inverse2Id], [l14].[Id] AS [Id0] + FROM [Level1] AS [l13] + INNER JOIN [Level1] AS [l14] ON [l13].[Id] = [l14].[Id] + WHERE ([l13].[OneToOne_Required_PK_Date] IS NOT NULL AND [l13].[Level1_Required_Id] IS NOT NULL) AND [l13].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l12].[Id] = [t6].[Id] + WHERE [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t5] ON CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] + END = CASE + WHEN [t5].[Level2_Required_Id] IS NOT NULL AND [t5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t5].[Id] + END + WHERE (([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t5].[Level2_Required_Id] IS NOT NULL AND [t5].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ) AS [t3] ON CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END = [t3].[Level2_Optional_Id] + WHERE ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id1] + END) +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Join_navigation_deeply_nested_required(bool async) + { + await base.Join_navigation_deeply_nested_required(async); + + AssertSql( + @"SELECT CASE + WHEN [t8].[Level3_Required_Id] IS NOT NULL AND [t8].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t8].[Id2] +END AS [Id4], [t8].[Level4_Name] AS [Name4], [l].[Id] AS [Id1], [l].[Name] AS [Name1] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t2].[Id] AS [Id2], [t2].[Level3_Required_Id], [t2].[Level4_Name], [t2].[OneToMany_Required_Inverse4Id], [l14].[Name] AS [Name0] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Required_Id], [l3].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = [t1].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level3_Required_Id], [l6].[Level4_Name], [l6].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN ( + SELECT [l8].[Id] + FROM [Level1] AS [l8] + INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] + WHERE ([l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL) AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l7].[Id] = [t4].[Id] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level3_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = CASE + WHEN [t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t2].[Id] + END + LEFT JOIN ( + SELECT [l10].[Id], [l10].[Level2_Required_Id], [l10].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l10] + INNER JOIN ( + SELECT [l11].[Id] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l10].[Id] = [t6].[Id] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t5] ON [t2].[Level3_Required_Id] = CASE + WHEN [t5].[Level2_Required_Id] IS NOT NULL AND [t5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t5].[Id] + END + LEFT JOIN ( + SELECT [l13].[Id], [l13].[OneToOne_Required_PK_Date], [l13].[Level1_Required_Id], [l13].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l13] + INNER JOIN [Level1] AS [l15] ON [l13].[Id] = [l15].[Id] + WHERE ([l13].[OneToOne_Required_PK_Date] IS NOT NULL AND [l13].[Level1_Required_Id] IS NOT NULL) AND [l13].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t7] ON [t5].[Level2_Required_Id] = CASE + WHEN ([t7].[OneToOne_Required_PK_Date] IS NOT NULL AND [t7].[Level1_Required_Id] IS NOT NULL) AND [t7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t7].[Id] + END + LEFT JOIN [Level1] AS [l14] ON CASE + WHEN ([t7].[OneToOne_Required_PK_Date] IS NOT NULL AND [t7].[Level1_Required_Id] IS NOT NULL) AND [t7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t7].[Id] + END = [l14].[Id] + WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ([t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL) +) AS [t8] ON [l].[Name] = [t8].[Name0]"); + } + + public override async Task Where_predicate_on_optional_reference_navigation(bool async) + { + await base.Where_predicate_on_optional_reference_navigation(async); + + AssertSql( + @"@__p_0='3' + +SELECT TOP(@__p_0) [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE [t].[Level2_Name] = N'L2 03' +ORDER BY [l].[Id]"); + } + + public override async Task Navigations_compared_to_each_other3(bool async) + { + await base.Navigations_compared_to_each_other3(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND ((CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL))))"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_compared_to_null5(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_compared_to_null5(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l5].[Level3_Required_Id], [l5].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = [t2].[Level3_Required_Id] +WHERE [t2].[Level3_Required_Id] IS NULL OR [t2].[OneToMany_Required_Inverse4Id] IS NULL"); + } + + public override async Task Where_on_multilevel_reference_in_subquery_with_outer_projection(bool async) + { + await base.Where_on_multilevel_reference_in_subquery_with_outer_projection(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t0].[Level3_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[OneToMany_Required_Inverse3Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Required_Id] = [l7].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ([l7].[Name] = N'L1 03') +ORDER BY [t0].[Level2_Required_Id] +OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY"); + } + + public override async Task Projection_select_correct_table_in_subquery_when_materialization_is_not_required_in_multiple_joins( + bool async) + { + await base.Projection_select_correct_table_in_subquery_when_materialization_is_not_required_in_multiple_joins(async); + + AssertSql( + @"@__p_0='3' + +SELECT TOP(@__p_0) [l2].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +INNER JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +INNER JOIN ( + SELECT [t1].[Level2_Required_Id], [t1].[Level3_Name] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l3].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l6].[Id] = [t3].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] + END + WHERE (([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL) +) AS [t2] ON [l2].[Id] = [t2].[Level2_Required_Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Name] = N'L1 03')) AND ([t2].[Level3_Name] = N'L3 08') +ORDER BY [l2].[Id]"); + } + + public override async Task Include6(bool async) + { + await base.Include6(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToOne_Optional_PK_Inverse3Id]"); + } + + public override async Task Include7(bool async) + { + await base.Include7(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToOne_Optional_PK_Inverse2Id]"); + } + + public override async Task Member_doesnt_get_pushed_down_into_subquery_with_result_operator(bool async) + { + await base.Member_doesnt_get_pushed_down_into_subquery_with_result_operator(async); + + AssertSql( + @"SELECT ( + SELECT [t2].[Level3_Name] + FROM ( + SELECT DISTINCT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = [t1].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ) AS [t2] + ORDER BY CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id] + END + OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3"); + } + + public override async Task Correlated_nested_two_levels_up_subquery_doesnt_project_unnecessary_columns_in_top_level(bool async) + { + await base.Correlated_nested_two_levels_up_subquery_doesnt_project_unnecessary_columns_in_top_level(async); + + AssertSql( + @"SELECT DISTINCT [l].[Name] +FROM [Level1] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l3].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Optional_Inverse3Id], [l6].[OneToMany_Required_Inverse3Id], [l6].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Optional_Inverse2Id], [l7].[OneToMany_Required_Inverse2Id], [l7].[OneToOne_Optional_PK_Inverse2Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l6].[Id] = [t2].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END = CASE + WHEN [t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t1].[Id] + END + WHERE (([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t1].[Level2_Required_Id] IS NOT NULL AND [t1].[OneToMany_Required_Inverse3Id] IS NOT NULL)))"); + } + + public override async Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access3(bool async) + { + await base.Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access3(async); + + AssertSql( + @"SELECT [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) +ORDER BY CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END"); + } + + public override async Task Select_nav_prop_reference_optional2(bool async) + { + await base.Select_nav_prop_reference_optional2(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Accessing_optional_property_inside_result_operator_subquery(bool async) + { + await base.Accessing_optional_property_inside_result_operator_subquery(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE [t].[Level2_Name] NOT IN (N'Name1', N'Name2') OR [t].[Level2_Name] IS NULL"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_compared_to_null4(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_compared_to_null4(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Optional_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Optional_Id] = [l7].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND [l7].[Id] IS NOT NULL"); + } + + public override async Task Multi_include_with_groupby_in_subquery(bool async) + { + await base.Multi_include_with_groupby_in_subquery(async); + + AssertSql( + @"SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t].[Name], [t1].[Id00], [t3].[Id], [t3].[Level2_Optional_Id], [t3].[Level2_Required_Id], [t3].[Level3_Name], [t3].[OneToMany_Optional_Inverse3Id], [t3].[OneToMany_Required_Inverse3Id], [t3].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id0], [t3].[Id00] +FROM ( + SELECT [l].[Name] + FROM [Level1] AS [l] + GROUP BY [l].[Name] +) AS [t] +LEFT JOIN ( + SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id00] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] AS [Id00], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l0].[Id] = [t2].[Level1_Optional_Id] + ) AS [t0] + WHERE [t0].[row] <= 1 +) AS [t1] ON [t].[Name] = [t1].[Name] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id] AS [Id0], [t4].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l3].[Id] = [t4].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t3] ON CASE + WHEN ([t1].[OneToOne_Required_PK_Date] IS NOT NULL AND [t1].[Level1_Required_Id] IS NOT NULL) AND [t1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t1].[Id0] +END = [t3].[OneToMany_Optional_Inverse3Id] +ORDER BY [t].[Name], [t1].[Id], [t1].[Id0], [t1].[Id00], [t3].[Id], [t3].[Id0]"); + } + + public override async Task Join_navigation_deeply_nested_non_key_join(bool async) + { + await base.Join_navigation_deeply_nested_non_key_join(async); + + AssertSql( + @"SELECT CASE + WHEN [t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t2].[Id] +END AS [Id4], [t2].[Level4_Name] AS [Name4], [t5].[Id] AS [Id1], [t5].[Name] AS [Name1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id] + FROM [Level1] AS [l6] + INNER JOIN ( + SELECT [l7].[Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [l6].[Id] = [t4].[Id] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = CASE + WHEN [t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t2].[Id] +END +INNER JOIN ( + SELECT [l9].[Id], [l9].[Name], [t8].[Level4_Name] + FROM [Level1] AS [l9] + LEFT JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Required_Id], [l10].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l9].[Id] = [t6].[Level1_Required_Id] + LEFT JOIN ( + SELECT [l12].[Id], [l12].[Level2_Optional_Id], [l12].[Level2_Required_Id], [l12].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l12] + INNER JOIN ( + SELECT [l13].[Id] + FROM [Level1] AS [l13] + INNER JOIN [Level1] AS [l14] ON [l13].[Id] = [l14].[Id] + WHERE ([l13].[OneToOne_Required_PK_Date] IS NOT NULL AND [l13].[Level1_Required_Id] IS NOT NULL) AND [l13].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t9] ON [l12].[Id] = [t9].[Id] + WHERE [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t7] ON CASE + WHEN ([t6].[OneToOne_Required_PK_Date] IS NOT NULL AND [t6].[Level1_Required_Id] IS NOT NULL) AND [t6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t6].[Id] + END = [t7].[Level2_Optional_Id] + LEFT JOIN ( + SELECT [l15].[Id], [l15].[Level3_Required_Id], [l15].[Level4_Name], [l15].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l15] + INNER JOIN ( + SELECT [l16].[Id] + FROM [Level1] AS [l16] + INNER JOIN ( + SELECT [l17].[Id] + FROM [Level1] AS [l17] + INNER JOIN [Level1] AS [l18] ON [l17].[Id] = [l18].[Id] + WHERE ([l17].[OneToOne_Required_PK_Date] IS NOT NULL AND [l17].[Level1_Required_Id] IS NOT NULL) AND [l17].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t11] ON [l16].[Id] = [t11].[Id] + WHERE [l16].[Level2_Required_Id] IS NOT NULL AND [l16].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t10] ON [l15].[Id] = [t10].[Id] + WHERE [l15].[Level3_Required_Id] IS NOT NULL AND [l15].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [t8] ON CASE + WHEN [t7].[Level2_Required_Id] IS NOT NULL AND [t7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t7].[Id] + END = CASE + WHEN [t8].[Level3_Required_Id] IS NOT NULL AND [t8].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [t8].[Id] + END +) AS [t5] ON [t2].[Level4_Name] = [t5].[Level4_Name] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ([t2].[Level3_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse4Id] IS NOT NULL)"); + } + + public override async Task Join_navigation_in_outer_selector_translated_to_extra_join_nested(bool async) + { + await base.Join_navigation_in_outer_selector_translated_to_extra_join_nested(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id1] +END AS [Id3] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +INNER JOIN ( + SELECT [t4].[Id] AS [Id1], [t4].[Level2_Required_Id], [t4].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = CASE + WHEN ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t3].[Id] + END + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + INNER JOIN ( + SELECT [l9].[Id] + FROM [Level1] AS [l9] + INNER JOIN [Level1] AS [l10] ON [l9].[Id] = [l10].[Id] + WHERE ([l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL) AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l8].[Id] = [t5].[Id] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t3].[Id] + END = CASE + WHEN [t4].[Level2_Required_Id] IS NOT NULL AND [t4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t4].[Id] + END + WHERE (([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t4].[Level2_Required_Id] IS NOT NULL AND [t4].[OneToMany_Required_Inverse3Id] IS NOT NULL) +) AS [t2] ON CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END = CASE + WHEN [t2].[Level2_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t2].[Id1] +END"); + } + + public override async Task Where_nav_prop_reference_optional2(bool async) + { + await base.Where_nav_prop_reference_optional2(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE ([t].[Level2_Name] = N'L2 05') OR (([t].[Level2_Name] <> N'L2 42') OR [t].[Level2_Name] IS NULL)"); + } + + public override async Task GroupJoin_client_method_on_outer(bool async) + { + await base.GroupJoin_client_method_on_outer(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task Navigations_compared_to_each_other5(bool async) + { + await base.Navigations_compared_to_each_other5(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Level3_Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00] + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t3] ON [l5].[Id] = [t3].[Id] + WHERE [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t2].[OneToOne_Optional_PK_Inverse3Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l8] + INNER JOIN ( + SELECT [l9].[Id], [l9].[Level2_Optional_Id], [l9].[Level2_Required_Id], [l9].[Level3_Name], [l9].[OneToMany_Optional_Inverse3Id], [l9].[OneToMany_Required_Inverse3Id], [l9].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Optional_Id], [l10].[Level1_Required_Id], [l10].[Level2_Name], [l10].[OneToMany_Optional_Inverse2Id], [l10].[OneToMany_Required_Inverse2Id], [l10].[OneToOne_Optional_PK_Inverse2Id], [l11].[Id] AS [Id0] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON [l8].[Id] = [t4].[Id] + WHERE ([l8].[Level3_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse4Id] IS NOT NULL) AND (CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END IS NOT NULL AND ((CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END = [l8].[OneToMany_Optional_Inverse4Id]) OR (CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END IS NULL AND [l8].[OneToMany_Optional_Inverse4Id] IS NULL))))"); + } + + public override async Task Include_multiple_collections_on_same_level(bool async) + { + await base.Include_multiple_collections_on_same_level(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id0] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id]"); + } + + public override async Task Key_equality_using_property_method_required2(bool async) + { + await base.Key_equality_using_property_method_required2(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] > 7)"); + } + + public override async Task Select_optional_navigation_property_string_concat(bool async) + { + await base.Select_optional_navigation_property_string_concat(async); + + AssertSql( + @"SELECT (COALESCE([l].[Name], N'') + N' ') + COALESCE(CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Level2_Name] + ELSE N'NULL' +END, N'') +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE (([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l0].[Id] > 5) +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id]"); + } + + public override async Task Join_navigation_in_outer_selector_translated_to_extra_join_nested2(bool async) + { + await base.Join_navigation_in_outer_selector_translated_to_extra_join_nested2(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END AS [Id3], [l8].[Id] AS [Id1] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Optional_Id] = [l7].[Id] +INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Include19(bool async) + { + await base.Include19(async); + + AssertSql( + @"SELECT [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id0], [t1].[OneToOne_Required_PK_Date0], [t1].[Level1_Optional_Id0], [t1].[Level1_Required_Id0], [t1].[Level2_Name0], [t1].[OneToMany_Optional_Inverse2Id0], [t1].[OneToMany_Required_Inverse2Id0], [t1].[OneToOne_Optional_PK_Inverse2Id0] +FROM ( + SELECT DISTINCT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id] AS [Id0], [t0].[OneToOne_Required_PK_Date] AS [OneToOne_Required_PK_Date0], [t0].[Level1_Optional_Id] AS [Level1_Optional_Id0], [t0].[Level1_Required_Id] AS [Level1_Required_Id0], [t0].[Level2_Name] AS [Level2_Name0], [t0].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [t0].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [t0].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l].[Id] = [t0].[OneToOne_Optional_PK_Inverse2Id] +) AS [t1]"); + } + + public override async Task SelectMany_navigation_property_and_filter_before(bool async) + { + await base.SelectMany_navigation_property_and_filter_before(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE [l].[Id] = 1"); + } + + public override async Task Subquery_with_Distinct_Skip_FirstOrDefault_without_OrderBy(bool async) + { + await base.Subquery_with_Distinct_Skip_FirstOrDefault_without_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id] AS [Key], ( + SELECT [t2].[Level3_Name] + FROM ( + SELECT DISTINCT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Level3_Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [t1].[Id] AS [Id0], [t1].[Id0] AS [Id00] + FROM [Level1] AS [l3] + INNER JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l3].[Id] = [t1].[Id] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ) AS [t2] + ORDER BY (SELECT 1) + OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY) AS [Subquery] +FROM [Level1] AS [l] +WHERE [l].[Id] < 3"); + } + + public override async Task Include1(bool async) + { + await base.Include1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Comparing_collection_navigation_on_optional_reference_to_null(bool async) + { + await base.Comparing_collection_navigation_on_optional_reference_to_null(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NULL OR [t].[Level1_Required_Id] IS NULL) OR [t].[OneToMany_Required_Inverse2Id] IS NULL"); + } + + public override async Task Where_nav_prop_reference_optional2_via_DefaultIfEmpty(bool async) + { + await base.Where_nav_prop_reference_optional2_via_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t2].[Level1_Optional_Id], [t2].[Level2_Name] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l3].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + WHERE ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[Level1_Optional_Id] +WHERE ([t0].[Level2_Name] = N'L2 05') OR (([t1].[Level2_Name] <> N'L2 42') OR [t1].[Level2_Name] IS NULL)"); + } + + public override async Task Result_operator_nav_prop_reference_optional_Average_with_identity_selector(bool async) + { + await base.Result_operator_nav_prop_reference_optional_Average_with_identity_selector(async); + + AssertSql( + @"SELECT AVG(CAST([t].[Level1_Required_Id] AS float)) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Optional_navigation_inside_property_method_translated_to_join(bool async) + { + await base.Optional_navigation_inside_property_method_translated_to_join(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE [t].[Level2_Name] = N'L2 01'"); + } + + public override async Task + Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability_also_for_arguments(bool async) + { + await base + .Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability_also_for_arguments(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE DATEADD(day, CAST(CAST(CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS float) AS int), DATEADD(day, CAST(15.0E0 AS int), [t].[OneToOne_Required_PK_Date])) > '2002-02-01T00:00:00.0000000'"); + } + + public override async Task Key_equality_using_property_method_and_member_expression3(bool async) + { + await base.Key_equality_using_property_method_and_member_expression3(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] = 7)"); + } + + public override async Task Include_reference_with_groupby_in_subquery(bool async) + { + await base.Include_reference_with_groupby_in_subquery(async); + + AssertSql( + @"SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT [l].[Name] + FROM [Level1] AS [l] + GROUP BY [l].[Name] +) AS [t] +LEFT JOIN ( + SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l0].[Id] = [t2].[Level1_Optional_Id] + ) AS [t0] + WHERE [t0].[row] <= 1 +) AS [t1] ON [t].[Name] = [t1].[Name]"); + } + + public override async Task SelectMany_navigation_comparison2(bool async) + { + await base.SelectMany_navigation_comparison2(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] +END AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] +LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Optional_Id] = [l3].[Id] +WHERE [l].[Id] = [l3].[Id]"); + } + + public override async Task Key_equality_using_property_method_and_member_expression2(bool async) + { + await base.Key_equality_using_property_method_and_member_expression2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 7"); + } + + public override async Task Where_navigation_property_to_collection(bool async) + { + await base.Where_navigation_property_to_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] +WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = [t0].[Id] + WHERE ([l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NOT NULL AND ((CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id]) OR (CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)))) > 0"); + } + + public override async Task Select_multiple_nav_prop_optional_required(bool async) + { + await base.Select_multiple_nav_prop_optional_required(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Required_Id]"); + } + + public override async Task Where_nav_prop_reference_optional1(bool async) + { + await base.Where_nav_prop_reference_optional1(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE [t].[Level2_Name] IN (N'L2 05', N'L2 07')"); + } + + public override async Task SelectMany_navigation_property_with_another_navigation_in_subquery(bool async) + { + await base.SelectMany_navigation_property_with_another_navigation_in_subquery(async); + + AssertSql( + @"SELECT [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l2].[Id] = [t].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t0] ON CASE + WHEN ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l0].[Id] + END = [t0].[Level2_Optional_Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id]"); + } + + public override async Task Join_navigations_in_inner_selector_translated_without_collision(bool async) + { + await base.Join_navigations_in_inner_selector_translated_without_collision(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END AS [Id2], [t0].[Id] AS [Id1], CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id1] +END AS [Id3] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [t1].[Id] AS [Id0], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Required_Id], [t1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Level1_Optional_Id] +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END +INNER JOIN ( + SELECT [t4].[Id] AS [Id1], [t4].[Level2_Required_Id], [t4].[OneToMany_Required_Inverse3Id], [t5].[Id] AS [Id2], [t5].[OneToOne_Required_PK_Date] AS [OneToOne_Required_PK_Date0], [t5].[Level1_Required_Id] AS [Level1_Required_Id0], [t5].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Optional_Id], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + INNER JOIN ( + SELECT [l9].[Id] + FROM [Level1] AS [l9] + INNER JOIN [Level1] AS [l10] ON [l9].[Id] = [l10].[Id] + WHERE ([l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL) AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t6] ON [l8].[Id] = [t6].[Id] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t4] ON CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END = CASE + WHEN [t4].[Level2_Required_Id] IS NOT NULL AND [t4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t4].[Id] + END + LEFT JOIN ( + SELECT [l11].[Id], [l11].[OneToOne_Required_PK_Date], [l11].[Level1_Required_Id], [l11].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l11] + INNER JOIN [Level1] AS [l12] ON [l11].[Id] = [l12].[Id] + WHERE ([l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL) AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [t4].[Level2_Optional_Id] = CASE + WHEN ([t5].[OneToOne_Required_PK_Date] IS NOT NULL AND [t5].[Level1_Required_Id] IS NOT NULL) AND [t5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t5].[Id] + END + WHERE (([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t4].[Level2_Required_Id] IS NOT NULL AND [t4].[OneToMany_Required_Inverse3Id] IS NOT NULL) +) AS [t3] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN ([t3].[OneToOne_Required_PK_Date0] IS NOT NULL AND [t3].[Level1_Required_Id0] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id0] IS NOT NULL THEN [t3].[Id2] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability(bool async) + { + await base.Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE DATEADD(month, CAST(2 AS int), DATEADD(day, CAST(15.0E0 AS int), DATEADD(day, CAST(10.0E0 AS int), [t].[OneToOne_Required_PK_Date]))) > '2002-02-01T00:00:00.0000000'"); + } + + public override async Task Result_operator_nav_prop_reference_optional_Average(bool async) + { + await base.Result_operator_nav_prop_reference_optional_Average(async); + + AssertSql( + @"SELECT AVG(CAST([t].[Level1_Required_Id] AS float)) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task GroupJoin_in_subquery_with_client_projection_nested2(bool async) + { + await base.GroupJoin_in_subquery_with_client_projection_nested2(async); + + AssertSql( + @"SELECT [l].[Name] +FROM [Level1] AS [l] +WHERE (( + SELECT COUNT(*) + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l1].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l0].[Id] = [t0].[Level1_Optional_Id] + WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Date], [l5].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Optional_Inverse2Id], [l6].[OneToMany_Required_Inverse2Id], [l6].[OneToOne_Optional_PK_Inverse2Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + WHERE ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l4].[Id] = [t1].[Level1_Optional_Id]) > 7) > 4) AND ([l].[Id] < 2)"); + } + + public override async Task Complex_navigations_with_predicate_projected_into_anonymous_type2(bool async) + { + await base.Complex_navigations_with_predicate_projected_into_anonymous_type2(async); + + AssertSql( + @"SELECT [t0].[Level3_Name] AS [Name], [l8].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l7] ON [t2].[Level1_Required_Id] = [l7].[Id] +LEFT JOIN [Level1] AS [l8] ON [t2].[Level1_Optional_Id] = [l8].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ((([l7].[Id] = [l8].[Id]) OR ([l7].[Id] IS NULL AND [l8].[Id] IS NULL)) AND (([l8].[Id] <> 7) OR [l8].[Id] IS NULL))"); + } + + public override async Task Select_subquery_with_client_eval_and_navigation1(bool async) + { + await base.Select_subquery_with_client_eval_and_navigation1(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [l3].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] + WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task String_include_multiple_derived_collection_navigation_with_same_name_and_different_type(bool async) + { + await base.String_include_multiple_derived_collection_navigation_with_same_name_and_different_type(async); + + AssertSql( + @"SELECT [i].[Id], [i].[Discriminator], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1], [i].[Name], [i0].[Id], [i0].[DifferentTypeCollection_InheritanceDerived1Id], [i0].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeCollection_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeReference_InheritanceDerived2Id], [i1].[InheritanceDerived2Id], [i1].[Name] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[DifferentTypeCollection_InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafTwo] AS [i1] ON [i].[Id] = [i1].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[Id]"); + } + + public override async Task Include_reference_and_project_into_anonymous_type(bool async) + { + await base.Include_reference_and_project_into_anonymous_type(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_scalar_result_operator(bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_scalar_result_operator(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l1].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l0].[Id] = [t0].[Level1_Optional_Id]) > 4"); + } + + public override async Task Nav_rewrite_doesnt_apply_null_protection_for_function_arguments(bool async) + { + await base.Nav_rewrite_doesnt_apply_null_protection_for_function_arguments(async); + + AssertSql( + @"SELECT [t].[Level1_Required_Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[OneToOne_Optional_PK_Inverse2Id] +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Result_operator_nav_prop_reference_optional_Min(bool async) + { + await base.Result_operator_nav_prop_reference_optional_Min(async); + + AssertSql( + @"SELECT MIN([t].[Level1_Required_Id]) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Entries_for_detached_entities_are_removed(bool async) + { + await base.Entries_for_detached_entities_are_removed(async); + + AssertSql( + @"SELECT TOP(1) [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +ORDER BY CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END"); + } + + public override async Task Navigation_inside_method_call_translated_to_join2(bool async) + { + await base.Navigation_inside_method_call_translated_to_join2(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Level3_Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ([t2].[Level2_Name] IS NOT NULL AND ([t2].[Level2_Name] LIKE N'L%'))"); + } + + public override async Task Select_nav_prop_reference_optional1_via_DefaultIfEmpty(bool async) + { + await base.Select_nav_prop_reference_optional1_via_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [t0].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_compared_to_null3(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_compared_to_null3(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +WHERE [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL"); + } + + public override async Task Navigations_compared_to_each_other1(bool async) + { + await base.Navigations_compared_to_each_other1(async); + + AssertSql( + @"SELECT [t].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToMany_Required_Inverse2Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND (([l2].[Id] = [l2].[Id]) OR [l2].[Id] IS NULL)"); + } + + public override async Task Optional_navigation_in_subquery_with_unrelated_projection(bool async) + { + await base.Optional_navigation_in_subquery_with_unrelated_projection(async); + + AssertSql( + @"@__p_0='15' + +SELECT TOP(@__p_0) [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE ([t].[Level2_Name] <> N'Foo') OR [t].[Level2_Name] IS NULL +ORDER BY [l].[Id]"); + } + + public override async Task Correlated_subquery_doesnt_project_unnecessary_columns_in_top_level(bool async) + { + await base.Correlated_subquery_doesnt_project_unnecessary_columns_in_top_level(async); + + AssertSql( + @"SELECT DISTINCT [l].[Name] +FROM [Level1] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t].[Level1_Required_Id] = [l].[Id]))"); + } + + public override async Task Select_subquery_with_client_eval_and_navigation2(bool async) + { + await base.Select_subquery_with_client_eval_and_navigation2(async); + + AssertSql( + @"SELECT CASE + WHEN (( + SELECT TOP(1) [l3].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] + WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) = N'L1 02') AND ( + SELECT TOP(1) [l3].[Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l5].[Id] AS [Id0] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l2].[Id] = CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END + LEFT JOIN [Level1] AS [l3] ON [t0].[Level1_Required_Id] = [l3].[Id] + WHERE ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ORDER BY CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id] + END) IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL"); + } + + public override async Task Include18_1(bool async) + { + await base.Include18_1(async); + + AssertSql( + @"SELECT [t].[Id], [t].[Date], [t].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task Include18_4(bool async) + { + await base.Include18_4(async); + + AssertSql( + @"SELECT [t].[Id], [t].[Date], [t].[Name], [t0].[Id], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] +) AS [t] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [t].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t].[Id] = [t1].[Level1_Optional_Id]"); + } + + public override async Task Result_operator_nav_prop_reference_optional_Average_without_selector(bool async) + { + await base.Result_operator_nav_prop_reference_optional_Average_without_selector(async); + + AssertSql( + @"SELECT AVG(CAST([t].[Level1_Required_Id] AS float)) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); + } + + public override async Task Order_by_key_of_anonymous_type_projected_navigation_doesnt_get_optimized_into_FK_access_subquery( + bool async) + { + await base.Order_by_key_of_anonymous_type_projected_navigation_doesnt_get_optimized_into_FK_access_subquery(async); + + AssertSql( + @"@__p_0='10' + +SELECT TOP(@__p_0) [t2].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) +ORDER BY CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END"); + } + + public override async Task Where_nav_prop_reference_optional1_via_DefaultIfEmpty(bool async) + { + await base.Where_nav_prop_reference_optional1_via_DefaultIfEmpty(async); + + AssertSql( + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t2].[Level1_Optional_Id], [t2].[Level2_Name] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l3].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + WHERE ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [l].[Id] = [t1].[Level1_Optional_Id] +WHERE ([t0].[Level2_Name] = N'L2 05') OR ([t1].[Level2_Name] = N'L2 07')"); + } + + public override async Task Join_navigation_key_access_required(bool async) + { + await base.Join_navigation_key_access_required(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], [l2].[Id] AS [Id1] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l3] ON [l1].[Id] = [l3].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Id1]"); + } + + public override async Task Include_with_all_method_include_gets_ignored(bool async) + { + await base.Include_with_all_method_include_gets_ignored(async); + + AssertSql( + @"SELECT CASE + WHEN NOT EXISTS ( + SELECT 1 + FROM [Level1] AS [l] + WHERE ([l].[Name] = N'Foo') AND [l].[Name] IS NOT NULL) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END"); + } + + public override async Task Include18_3_2(bool async) + { + await base.Include18_3_2(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [t].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] + ORDER BY [t].[Level2_Name] +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = [t1].[Level1_Optional_Id] +ORDER BY [t0].[Level2_Name]"); + } + + public override async Task Select_nav_prop_reference_optional2_via_DefaultIfEmpty(bool async) + { + await base.Select_nav_prop_reference_optional2_via_DefaultIfEmpty(async); + + AssertSql( + @"SELECT CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id]"); + } + + public override async Task Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access1(bool async) + { + await base.Order_by_key_of_projected_navigation_doesnt_get_optimized_into_FK_access1(async); + + AssertSql( + @"SELECT [t2].[Id], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Optional_Id], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Optional_Inverse2Id], [l5].[OneToMany_Required_Inverse2Id], [l5].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL) +ORDER BY CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END"); + } + + public override async Task Where_complex_predicate_with_with_nav_prop_and_OrElse4(bool async) + { + await base.Where_complex_predicate_with_with_nav_prop_and_OrElse4(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[Level2_Name], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [t0].[Level2_Optional_Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] + WHERE ([l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL) AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t3] ON [t0].[Level2_Required_Id] = CASE + WHEN ([t3].[OneToOne_Required_PK_Date] IS NOT NULL AND [t3].[Level1_Required_Id] IS NOT NULL) AND [t3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t3].[Id] +END +LEFT JOIN [Level1] AS [l9] ON [t3].[Level1_Optional_Id] = [l9].[Id] +WHERE ((([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)) AND ((([t2].[Level2_Name] <> N'L2 05') OR [t2].[Level2_Name] IS NULL) OR ([l9].[Name] = N'L1 05'))"); + } + + public override async Task String_include_multiple_derived_navigation_with_same_name_and_same_type(bool async) + { + await base.String_include_multiple_derived_navigation_with_same_name_and_same_type(async); + + AssertSql( + @"SELECT [i].[Id], [i].[Discriminator], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1], [i].[Name], [i0].[Id], [i0].[DifferentTypeCollection_InheritanceDerived1Id], [i0].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeCollection_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeCollection_InheritanceDerived1Id], [i1].[DifferentTypeReference_InheritanceDerived1Id], [i1].[InheritanceDerived2Id], [i1].[Name], [i1].[SameTypeCollection_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived2Id] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[SameTypeReference_InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafOne] AS [i1] ON [i].[Id] = [i1].[SameTypeReference_InheritanceDerived2Id]"); + } + + public override async Task Select_subquery_with_client_eval_and_multi_level_navigation(bool async) + { + await base.Select_subquery_with_client_eval_and_multi_level_navigation(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [l7].[Name] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Optional_Inverse2Id], [l6].[OneToMany_Required_Inverse2Id], [l6].[OneToOne_Optional_PK_Inverse2Id], [l8].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l8] ON [l6].[Id] = [l8].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level2_Optional_Id], [l9].[Level2_Required_Id], [l9].[Level3_Name], [l9].[OneToMany_Optional_Inverse3Id], [l9].[OneToMany_Required_Inverse3Id], [l9].[OneToOne_Optional_PK_Inverse3Id], [t5].[Id] AS [Id0], [t5].[Id0] AS [Id00] + FROM [Level1] AS [l9] + INNER JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Optional_Id], [l10].[Level1_Required_Id], [l10].[Level2_Name], [l10].[OneToMany_Optional_Inverse2Id], [l10].[OneToMany_Required_Inverse2Id], [l10].[OneToOne_Optional_PK_Inverse2Id], [l11].[Id] AS [Id0] + FROM [Level1] AS [l10] + INNER JOIN [Level1] AS [l11] ON [l10].[Id] = [l11].[Id] + WHERE ([l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL) AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t5] ON [l9].[Id] = [t5].[Id] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [t3] ON CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END = CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] + END + LEFT JOIN ( + SELECT [l12].[Id], [l12].[OneToOne_Required_PK_Date], [l12].[Level1_Optional_Id], [l12].[Level1_Required_Id], [l12].[Level2_Name], [l12].[OneToMany_Optional_Inverse2Id], [l12].[OneToMany_Required_Inverse2Id], [l12].[OneToOne_Optional_PK_Inverse2Id], [l13].[Id] AS [Id0] + FROM [Level1] AS [l12] + INNER JOIN [Level1] AS [l13] ON [l12].[Id] = [l13].[Id] + WHERE ([l12].[OneToOne_Required_PK_Date] IS NOT NULL AND [l12].[Level1_Required_Id] IS NOT NULL) AND [l12].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t4] ON [t3].[Level2_Required_Id] = CASE + WHEN ([t4].[OneToOne_Required_PK_Date] IS NOT NULL AND [t4].[Level1_Required_Id] IS NOT NULL) AND [t4].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t4].[Id] + END + LEFT JOIN [Level1] AS [l7] ON [t4].[Level1_Required_Id] = [l7].[Id] + WHERE (([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL) + ORDER BY CASE + WHEN [t3].[Level2_Required_Id] IS NOT NULL AND [t3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t3].[Id] + END) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL)"); + } + + public override async Task Optional_navigation_take_optional_navigation(bool async) + { + await base.Optional_navigation_take_optional_navigation(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t1].[Level3_Name] +FROM ( + SELECT TOP(@__p_0) [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Required_Id], [t].[OneToMany_Required_Inverse2Id], CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END AS [c] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] + ORDER BY CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l2].[Id] = [t2].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t1] ON CASE + WHEN ([t0].[OneToOne_Required_PK_Date] IS NOT NULL AND [t0].[Level1_Required_Id] IS NOT NULL) AND [t0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t0].[Id0] +END = [t1].[Level2_Optional_Id] +ORDER BY [t0].[c]"); + } + + public override async Task SelectMany_nested_navigation_property_optional_and_projection(bool async) + { + await base.SelectMany_nested_navigation_property_optional_and_projection(async); + + AssertSql( + @"SELECT [t0].[Level3_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[OneToMany_Optional_Inverse3Id]"); + } + + public override async Task Include18_3(bool async) + { + await base.Include18_3(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [t].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] + ORDER BY [t].[Level2_Name] +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = [t1].[Level1_Optional_Id] +ORDER BY [t0].[Level2_Name]"); + } + + public override async Task Navigation_with_same_navigation_compared_to_null(bool async) + { + await base.Navigation_with_same_navigation_compared_to_null(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[OneToMany_Required_Inverse2Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ((([l2].[Name] <> N'L1 07') OR [l2].[Name] IS NULL) AND [l2].[Id] IS NOT NULL)"); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_projection(bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_unrelated_projection(async); + + AssertSql( + @"@__p_0='15' + +SELECT TOP(@__p_0) [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Level1_Optional_Id], [t].[Level2_Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +WHERE ([t0].[Level2_Name] <> N'Foo') OR [t0].[Level2_Name] IS NULL +ORDER BY [l].[Id]"); + } + + public override async Task Navigation_key_access_required_comparison(bool async) + { + await base.Navigation_key_access_required_comparison(async); + + AssertSql( + @"SELECT CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l2].[Id] > 5)"); + } + + public override async Task SelectMany_navigation_comparison1(bool async) + { + await base.SelectMany_navigation_comparison1(async); + + AssertSql( + @"SELECT [l].[Id] AS [Id1], [l0].[Id] AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN [Level1] AS [l0] +WHERE [l].[Id] = [l0].[Id]"); + } + + public override async Task GroupJoin_in_subquery_with_client_result_operator(bool async) + { + await base.GroupJoin_in_subquery_with_client_result_operator(async); + + AssertSql( + @"SELECT [l].[Name] +FROM [Level1] AS [l] +WHERE (( + SELECT COUNT(*) + FROM ( + SELECT DISTINCT [l0].[Id], [l0].[Date], [l0].[Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l1].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l0].[Id] = [t0].[Level1_Optional_Id] + ) AS [t1]) > 7) AND ([l].[Id] < 3)"); + } + + public override async Task Include18_3_1(bool async) + { + await base.Include18_3_1(async); + + AssertSql( + @"@__p_0='10' + +SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t1].[Id], [t1].[OneToOne_Required_PK_Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Level2_Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [t].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l].[Id] = [t].[Level1_Required_Id] + ORDER BY [t].[Level2_Name] +) AS [t0] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = [t1].[Level1_Optional_Id] +ORDER BY [t0].[Level2_Name]"); + } + + public override async Task Key_equality_two_conditions_on_same_navigation2(bool async) + { + await base.Key_equality_two_conditions_on_same_navigation2(async); + + AssertSql( + @"SELECT [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [t].[Level1_Required_Id] = [l2].[Id] +WHERE (([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND [l2].[Id] IN (1, 2)"); + } + + public override async Task Entity_equality_empty(bool async) + { + await base.Entity_equality_empty(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 0"); + } + + public override async Task Member_pushdown_with_multiple_collections(bool async) + { + await base.Member_pushdown_with_multiple_collections(async); + + AssertSql( + @"SELECT ( + SELECT TOP(1) [l0].[Level3_Name] + FROM [Level1] AS [l0] + INNER JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = [t].[Id] + WHERE ([l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL) AND (EXISTS ( + SELECT 1 + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE (([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l3].[OneToMany_Optional_Inverse2Id])) AND ((( + SELECT TOP(1) CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE (([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l5].[OneToMany_Optional_Inverse2Id]) + ORDER BY CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END) = [l0].[OneToMany_Optional_Inverse3Id]) OR (( + SELECT TOP(1) CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END + FROM [Level1] AS [l5] + INNER JOIN [Level1] AS [l6] ON [l5].[Id] = [l6].[Id] + WHERE (([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL) AND ([l].[Id] = [l5].[OneToMany_Optional_Inverse2Id]) + ORDER BY CASE + WHEN ([l5].[OneToOne_Required_PK_Date] IS NOT NULL AND [l5].[Level1_Required_Id] IS NOT NULL) AND [l5].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l5].[Id] + END) IS NULL AND [l0].[OneToMany_Optional_Inverse3Id] IS NULL))) + ORDER BY CASE + WHEN [l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l0].[Id] + END) +FROM [Level1] AS [l]"); + } + + public override async Task Join_flattening_bug_4539(bool async) + { + await base.Join_flattening_bug_4539(async); + + AssertSql( + @"SELECT [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id], [l6].[Date], [l6].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] + WHERE ([l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL) AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +CROSS JOIN ( + SELECT [t2].[Level1_Required_Id] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + INNER JOIN [Level1] AS [l5] ON [l4].[Id] = [l5].[Id] + WHERE ([l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL) AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l3].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + WHERE ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t1] +INNER JOIN [Level1] AS [l6] ON [t1].[Level1_Required_Id] = [l6].[Id]"); + } + + public override async Task Multi_level_include_with_short_circuiting(bool async) + { + await base.Multi_level_include_with_short_circuiting(async); + + AssertSql( + @"SELECT [f].[Name], [f].[LabelDefaultText], [f].[PlaceholderDefaultText], [m].[DefaultText], [m0].[DefaultText], [t].[Text], [t].[ComplexNavigationStringDefaultText], [t].[LanguageName], [t].[Name], [t].[CultureString], [t0].[Text], [t0].[ComplexNavigationStringDefaultText], [t0].[LanguageName], [t0].[Name], [t0].[CultureString] +FROM [Fields] AS [f] +LEFT JOIN [MultilingualStrings] AS [m] ON [f].[LabelDefaultText] = [m].[DefaultText] +LEFT JOIN [MultilingualStrings] AS [m0] ON [f].[PlaceholderDefaultText] = [m0].[DefaultText] +LEFT JOIN ( + SELECT [g].[Text], [g].[ComplexNavigationStringDefaultText], [g].[LanguageName], [l].[Name], [l].[CultureString] + FROM [Globalizations] AS [g] + LEFT JOIN [Languages] AS [l] ON [g].[LanguageName] = [l].[Name] +) AS [t] ON [m].[DefaultText] = [t].[ComplexNavigationStringDefaultText] +LEFT JOIN ( + SELECT [g0].[Text], [g0].[ComplexNavigationStringDefaultText], [g0].[LanguageName], [l0].[Name], [l0].[CultureString] + FROM [Globalizations] AS [g0] + LEFT JOIN [Languages] AS [l0] ON [g0].[LanguageName] = [l0].[Name] +) AS [t0] ON [m0].[DefaultText] = [t0].[ComplexNavigationStringDefaultText] +ORDER BY [f].[Name], [m].[DefaultText], [m0].[DefaultText], [t].[Text], [t].[Name], [t0].[Text]"); + } + + public override async Task Select_multiple_nav_prop_reference_optional(bool async) + { + await base.Select_multiple_nav_prop_reference_optional(async); + + AssertSql( + @"SELECT CASE + WHEN [t0].[Level2_Required_Id] IS NOT NULL AND [t0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [t0].[Id] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id]"); + } + + public override async Task Where_multiple_nav_prop_reference_optional_member_compared_to_null(bool async) + { + await base.Where_multiple_nav_prop_reference_optional_member_compared_to_null(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + INNER JOIN ( + SELECT [l3].[Id] + FROM [Level1] AS [l3] + INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] + WHERE ([l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL) AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l2].[Id] = [t1].[Id] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [t0] ON CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = [t0].[Level2_Optional_Id] +WHERE [t0].[Level3_Name] IS NOT NULL"); + } + + public override async Task GroupJoin_in_subquery_with_client_projection_nested1(bool async) + { + await base.GroupJoin_in_subquery_with_client_projection_nested1(async); + + AssertSql( + @"SELECT [l].[Name] +FROM [Level1] AS [l] +WHERE (( + SELECT COUNT(*) + FROM ( + SELECT TOP(10) [l0].[Id], [l0].[Date], [l0].[Name], [t0].[Id] AS [Id0], [t0].[Date] AS [Date0], [t0].[Name] AS [Name0], [t0].[Id0] AS [Id00], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[Id00] AS [Id000] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[Id0] AS [Id00] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l3].[Id] AS [Id0] + FROM [Level1] AS [l2] + INNER JOIN [Level1] AS [l3] ON [l2].[Id] = [l3].[Id] + WHERE ([l2].[OneToOne_Required_PK_Date] IS NOT NULL AND [l2].[Level1_Required_Id] IS NOT NULL) AND [l2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l1].[Id] = CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] + END + WHERE ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t0] ON [l0].[Id] = [t0].[Level1_Optional_Id] + WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Date], [l5].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[Id0] AS [Id00] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Optional_Inverse2Id], [l6].[OneToMany_Required_Inverse2Id], [l6].[OneToOne_Optional_PK_Inverse2Id], [l7].[Id] AS [Id0] + FROM [Level1] AS [l6] + INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] + WHERE ([l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL) AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t2] ON [l5].[Id] = CASE + WHEN ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + END + WHERE ([t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL) AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t1] ON [l4].[Id] = [t1].[Level1_Optional_Id]) > 7 + ORDER BY [l0].[Id] + ) AS [t3]) > 4) AND ([l].[Id] < 2)"); + } + + public override async Task Key_equality_when_sentinel_ef_property(bool async) + { + await base.Key_equality_when_sentinel_ef_property(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] + WHERE ([l0].[OneToOne_Required_PK_Date] IS NOT NULL AND [l0].[Level1_Required_Id] IS NOT NULL) AND [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] +WHERE CASE + WHEN ([t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL) AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] +END = 0"); + } + + public override async Task Project_shadow_properties1(bool async) + { + await base.Project_shadow_properties1(async); + + AssertSql(); + } + + public override async Task Project_shadow_properties2(bool async) + { + await base.Project_shadow_properties2(async); + + AssertSql(); + } + + public override async Task Project_shadow_properties3(bool async) + { + await base.Project_shadow_properties3(async); + + AssertSql(); + } + + public override async Task Project_shadow_properties4(bool async) + { + await base.Project_shadow_properties4(async); + + AssertSql(); + } + + public override async Task Project_shadow_properties9(bool async) + { + await base.Project_shadow_properties9(async); + + AssertSql(); + } + + public override async Task GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer_with_client_method(bool async) + { + await base.GroupJoin_on_a_subquery_containing_another_GroupJoin_projecting_outer_with_client_method(async); + + AssertSql(); + } + + public override async Task GroupJoin_client_method_in_OrderBy(bool async) + { + await AssertTranslationFailedWithDetails( + () => base.GroupJoin_client_method_in_OrderBy(async), + CoreStrings.QueryUnableToTranslateMethod( + "Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase", + "ClientMethodNullableInt")); + + AssertSql(); + } + + public override async Task GroupJoin_with_subquery_on_inner(bool async) + { + await base.GroupJoin_with_subquery_on_inner(async); + + AssertSql(); + } + + public override async Task GroupJoin_with_subquery_on_inner_and_no_DefaultIfEmpty(bool async) + { + await base.GroupJoin_with_subquery_on_inner_and_no_DefaultIfEmpty(async); + + AssertSql(); + } + + public override async Task Level4_Include(bool async) + { + await base.Level4_Include(async); + + AssertSql(); + } + + public override async Task Include17(bool async) + { + await base.Include17(async); + + AssertSql(); + } + + public override async Task Multiple_required_navigations_with_Include(bool async) + { + await base.Multiple_required_navigations_with_Include(async); + + AssertSql(); + } + + public override async Task Multiple_required_navigation_using_multiple_selects_with_Include(bool async) + { + await base.Multiple_required_navigation_using_multiple_selects_with_Include(async); + + AssertSql(); + } + + public override async Task Multiple_required_navigation_with_string_based_Include(bool async) + { + await base.Multiple_required_navigation_with_string_based_Include(async); + + AssertSql(); + } + + public override async Task Multiple_required_navigation_using_multiple_selects_with_string_based_Include(bool async) + { + await base.Multiple_required_navigation_using_multiple_selects_with_string_based_Include(async); + + AssertSql(); + } + + public override async Task Optional_navigation_with_Include(bool async) + { + await base.Optional_navigation_with_Include(async); + + AssertSql(); + } + + public override async Task Project_shadow_properties8(bool async) + { + await base.Project_shadow_properties8(async); + + AssertSql( + @"SELECT [i].[Id], [i].[InheritanceLeaf2Id] +FROM [InheritanceTwo] AS [i]"); + } + + public override async Task Project_shadow_properties10(bool async) + { + await base.Project_shadow_properties10(async); + + AssertSql( + @"SELECT [i].[Id], [i].[DifferentTypeReference_InheritanceDerived2Id], [i].[InheritanceDerived2Id] +FROM [InheritanceLeafTwo] AS [i]"); + } + + public override async Task Project_shadow_properties7(bool async) + { + await base.Project_shadow_properties7(async); + + AssertSql( + @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] +FROM [InheritanceOne] AS [i] +WHERE [i].[Discriminator] = N'InheritanceDerived2'"); + } + + public override async Task Project_shadow_properties6(bool async) + { + await base.Project_shadow_properties6(async); + + AssertSql( + @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] +FROM [InheritanceOne] AS [i] +WHERE [i].[Discriminator] = N'InheritanceDerived1'"); + } + + public override async Task String_include_multiple_derived_navigations_complex(bool async) + { + await base.String_include_multiple_derived_navigations_complex(async); + + AssertSql( + @"SELECT [i].[Id], [i].[InheritanceLeaf2Id], [i].[Name], [i0].[Id], [i0].[Discriminator], [i0].[InheritanceBase2Id], [i0].[InheritanceBase2Id1], [i0].[Name], [i1].[Id], [i1].[DifferentTypeCollection_InheritanceDerived1Id], [i1].[DifferentTypeReference_InheritanceDerived1Id], [i1].[InheritanceDerived2Id], [i1].[Name], [i1].[SameTypeCollection_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived2Id], [i2].[Id], [i2].[DifferentTypeReference_InheritanceDerived2Id], [i2].[InheritanceDerived2Id], [i2].[Name], [t].[Id], [t].[Discriminator], [t].[InheritanceBase2Id], [t].[InheritanceBase2Id1], [t].[Name], [t].[Id0], [t].[DifferentTypeCollection_InheritanceDerived1Id], [t].[DifferentTypeReference_InheritanceDerived1Id], [t].[InheritanceDerived2Id], [t].[Name0], [t].[SameTypeCollection_InheritanceDerived1Id], [t].[SameTypeReference_InheritanceDerived1Id], [t].[SameTypeReference_InheritanceDerived2Id], [t].[Id1], [t].[DifferentTypeCollection_InheritanceDerived1Id0], [t].[DifferentTypeReference_InheritanceDerived1Id0], [t].[InheritanceDerived2Id0], [t].[Name1], [t].[SameTypeCollection_InheritanceDerived1Id0], [t].[SameTypeReference_InheritanceDerived1Id0], [t].[SameTypeReference_InheritanceDerived2Id0] +FROM [InheritanceTwo] AS [i] +LEFT JOIN [InheritanceOne] AS [i0] ON [i].[Id] = [i0].[InheritanceBase2Id] +LEFT JOIN [InheritanceLeafOne] AS [i1] ON [i0].[Id] = [i1].[DifferentTypeCollection_InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafTwo] AS [i2] ON [i0].[Id] = [i2].[InheritanceDerived2Id] +LEFT JOIN ( + SELECT [i3].[Id], [i3].[Discriminator], [i3].[InheritanceBase2Id], [i3].[InheritanceBase2Id1], [i3].[Name], [i4].[Id] AS [Id0], [i4].[DifferentTypeCollection_InheritanceDerived1Id], [i4].[DifferentTypeReference_InheritanceDerived1Id], [i4].[InheritanceDerived2Id], [i4].[Name] AS [Name0], [i4].[SameTypeCollection_InheritanceDerived1Id], [i4].[SameTypeReference_InheritanceDerived1Id], [i4].[SameTypeReference_InheritanceDerived2Id], [i5].[Id] AS [Id1], [i5].[DifferentTypeCollection_InheritanceDerived1Id] AS [DifferentTypeCollection_InheritanceDerived1Id0], [i5].[DifferentTypeReference_InheritanceDerived1Id] AS [DifferentTypeReference_InheritanceDerived1Id0], [i5].[InheritanceDerived2Id] AS [InheritanceDerived2Id0], [i5].[Name] AS [Name1], [i5].[SameTypeCollection_InheritanceDerived1Id] AS [SameTypeCollection_InheritanceDerived1Id0], [i5].[SameTypeReference_InheritanceDerived1Id] AS [SameTypeReference_InheritanceDerived1Id0], [i5].[SameTypeReference_InheritanceDerived2Id] AS [SameTypeReference_InheritanceDerived2Id0] + FROM [InheritanceOne] AS [i3] + LEFT JOIN [InheritanceLeafOne] AS [i4] ON [i3].[Id] = [i4].[SameTypeReference_InheritanceDerived1Id] + LEFT JOIN [InheritanceLeafOne] AS [i5] ON [i3].[Id] = [i5].[SameTypeReference_InheritanceDerived2Id] +) AS [t] ON [i].[Id] = [t].[InheritanceBase2Id1] +ORDER BY [i].[Id], [i0].[Id], [i1].[Id], [i2].[Id], [t].[Id], [t].[Id0]"); + } + + public override async Task Project_shadow_properties5(bool async) + { + await base.Project_shadow_properties5(async); + + AssertSql( + @"SELECT [i].[Id], [i].[InheritanceBase2Id], [i].[InheritanceBase2Id1] +FROM [InheritanceOne] AS [i]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs index 719fe3cac8e..af4586e4ea2 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindGroupByQuerySqlServerTest.cs @@ -12,7 +12,6 @@ namespace Microsoft.EntityFrameworkCore.Query public class NorthwindGroupByQuerySqlServerTest : NorthwindGroupByQueryRelationalTestBase< NorthwindQuerySqlServerFixture> { - // ReSharper disable once UnusedParameter.Local public NorthwindGroupByQuerySqlServerTest( NorthwindQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper) @@ -25,6 +24,10 @@ public NorthwindGroupByQuerySqlServerTest( protected override bool CanExecuteQueryString => true; + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + public override async Task GroupBy_Property_Select_Average(bool async) { await base.GroupBy_Property_Select_Average(async); @@ -44,8 +47,7 @@ public override async Task GroupBy_Property_Select_Average_with_group_enumerable { await base.GroupBy_Property_Select_Average_with_group_enumerable_projected(async); - AssertSql( - @""); + AssertSql(); } public override async Task GroupBy_Property_Select_Count(bool async) @@ -1982,15 +1984,11 @@ FROM [Customers] AS [c0] ORDER BY [t].[City], [t0].[CustomerID]"); } - public override async Task Select_GroupBy_SelectMany(bool async) { await base.Select_GroupBy_SelectMany(async); - AssertSql( - @"SELECT [o].[OrderID] AS [Order], [o].[CustomerID] AS [Customer] -FROM [Orders] AS [o] -ORDER BY [o].[OrderID]"); + AssertSql(); } public override async Task Count_after_GroupBy_aggregate(bool async) @@ -2338,32 +2336,28 @@ public override async Task GroupBy_with_group_key_being_navigation(bool async) { await base.GroupBy_with_group_key_being_navigation(async); - AssertSql( - @""); + AssertSql(); } public override async Task GroupBy_with_group_key_being_nested_navigation(bool async) { await base.GroupBy_with_group_key_being_nested_navigation(async); - AssertSql( - @""); + AssertSql(); } public override async Task GroupBy_with_group_key_being_navigation_with_entity_key_projection(bool async) { await base.GroupBy_with_group_key_being_navigation_with_entity_key_projection(async); - AssertSql( - @""); + AssertSql(); } public override async Task GroupBy_with_group_key_being_navigation_with_complex_projection(bool async) { await base.GroupBy_with_group_key_being_navigation_with_complex_projection(async); - AssertSql( - @""); + AssertSql(); } public override async Task GroupBy_with_order_by_skip_and_another_order_by(bool async) @@ -2422,7 +2416,7 @@ public override async Task GroupBy_let_orderby_projection_with_coalesce_operatio { await base.GroupBy_let_orderby_projection_with_coalesce_operation(async); - AssertSql(" "); + AssertSql(); } public override async Task GroupBy_Min_Where_optional_relationship(bool async) @@ -2874,6 +2868,76 @@ FROM [Order Details] AS [o1] ORDER BY [t].[ProductID], [t0].[CustomerID]"); } + public override async Task Complex_query_with_groupBy_in_subquery4(bool async) + { + await base.Complex_query_with_groupBy_in_subquery4(async); + + AssertSql(); + } + + public override async Task GroupBy_aggregate_SelectMany(bool async) + { + await base.GroupBy_aggregate_SelectMany(async); + + AssertSql(); + } + + public override async Task GroupBy_as_final_operator(bool async) + { + await base.GroupBy_as_final_operator(async); + + AssertSql(); + } + + public override async Task GroupBy_Where_with_grouping_result(bool async) + { + await base.GroupBy_Where_with_grouping_result(async); + + AssertSql(); + } + + public override async Task GroupBy_OrderBy_with_grouping_result(bool async) + { + await base.GroupBy_OrderBy_with_grouping_result(async); + + AssertSql(); + } + + public override async Task GroupBy_SelectMany(bool async) + { + await base.GroupBy_SelectMany(async); + + AssertSql(); + } + + public override async Task OrderBy_GroupBy_SelectMany(bool async) + { + await base.OrderBy_GroupBy_SelectMany(async); + + AssertSql(); + } + + public override async Task OrderBy_GroupBy_SelectMany_shadow(bool async) + { + await base.OrderBy_GroupBy_SelectMany_shadow(async); + + AssertSql(); + } + + public override async Task GroupBy_with_orderby_take_skip_distinct_followed_by_group_key_projection(bool async) + { + await base.GroupBy_with_orderby_take_skip_distinct_followed_by_group_key_projection(async); + + AssertSql(); + } + + public override async Task GroupBy_Distinct(bool async) + { + await base.GroupBy_Distinct(async); + + AssertSql(); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs index 5a2c21fbe36..76edd9885c2 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsQuerySqlServerTest.cs @@ -7,12 +7,14 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query { [SqlServerCondition(SqlServerCondition.SupportsTemporalTablesCascadeDelete)] - public class TemporalComplexNavigationsCollectionsQuerySqlServerTest : ComplexNavigationsCollectionsQueryRelationalTestBase + public class TemporalComplexNavigationsCollectionsQuerySqlServerTest + : ComplexNavigationsCollectionsQueryRelationalTestBase { public TemporalComplexNavigationsCollectionsQuerySqlServerTest( TemporalComplexNavigationsQuerySqlServerFixture fixture, @@ -38,6 +40,17 @@ protected override Expression RewriteServerQueryExpression(Expression serverQuer return rewriter.Visit(serverQueryExpression); } + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + public override async Task Queryable_in_subquery_works_when_final_projection_is_List(bool async) + { + await base.Queryable_in_subquery_works_when_final_projection_is_List(async); + + AssertSql(); + } + public override async Task Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(bool async) { await base.Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(async); @@ -53,7 +66,8 @@ LEFT JOIN ( ORDER BY [l].[Id], [t].[Id]"); } - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) { await base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async); @@ -69,6 +83,2382 @@ OUTER APPLY ( ORDER BY [l].[Id], [t].[Id]"); } + public override async Task Filtered_include_and_non_filtered_include_on_same_navigation2(bool async) + { + await base.Filtered_include_and_non_filtered_include_on_same_navigation2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_methodcall(bool async) + { + await base.Include_collection_with_multiple_orderbys_methodcall(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY ABS([l].[Level1_Required_Id]), [l].[Name], [l].[Id]"); + } + + public override async Task Include_collection_multiple_with_filter(bool async) + { + await base.Include_collection_multiple_with_filter(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[Id1], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name1], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd1], [t].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Id] AS [Id0], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name] AS [Name0], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd] AS [PeriodEnd0], [l3].[PeriodStart] AS [PeriodStart0], [l4].[Id] AS [Id1], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Name] AS [Name1], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Optional_Self_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToMany_Required_Self_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id], [l4].[OneToOne_Optional_Self4Id], [l4].[PeriodEnd] AS [PeriodEnd1], [l4].[PeriodStart] AS [PeriodStart1] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Id] = [l4].[Level3_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE ( + SELECT COUNT(*) + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] + WHERE ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) AND (([l1].[Name] <> N'Foo') OR [l1].[Name] IS NULL)) > 0 +ORDER BY [l].[Id], [t].[Id], [t].[Id0]"); + } + + public override async Task Filtered_include_after_reference_navigation(bool async) + { + await base.Filtered_include_after_reference_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Name]) AS [row] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE ([l1].[Name] <> N'Foo') OR [l1].[Name] IS NULL + ) AS [t] + WHERE (1 < [t].[row]) AND ([t].[row] <= 4) +) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [t0].[OneToMany_Optional_Inverse3Id], [t0].[Name]"); + } + + public override async Task Skip_Take_on_grouping_element_into_non_entity(bool async) + { + await base.Skip_Take_on_grouping_element_into_non_entity(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Name], [t0].[Id] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Name], [t1].[Id], [t1].[Date] + FROM ( + SELECT [l0].[Name], [l0].[Id], [l0].[Date], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) + { + await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async); + + AssertSql( + @"SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM ( + SELECT TOP(1) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT TOP(40) [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ) AS [t1] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Id] = [l0].[Level2_Optional_Id] +) AS [t0] +ORDER BY [t].[Id], [t0].[Id]"); + } + + public override async Task Include_collection_ThenInclude_reference_followed_by_projection_into_anonmous_type(bool async) + { + await base.Include_collection_ThenInclude_reference_followed_by_projection_into_anonmous_type(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Id] AS [Id0], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name] AS [Name0], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd] AS [PeriodEnd0], [l3].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[OneToOne_Optional_PK_Inverse3Id] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id]"); + } + + public override async Task SelectMany_with_Include_ThenInclude(bool async) + { + await base.SelectMany_with_Include_ThenInclude(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l].[Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Filtered_include_on_ThenInclude(bool async) + { + await base.Filtered_include_on_ThenInclude(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Name]) AS [row] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE ([l1].[Name] <> N'Foo') OR [l1].[Name] IS NULL + ) AS [t] + WHERE (1 < [t].[row]) AND ([t].[row] <= 4) +) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [t0].[OneToMany_Optional_Inverse3Id], [t0].[Name]"); + } + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) + { + await base.Complex_query_with_let_collection_projection_FirstOrDefault(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT [l1].[Name], [l1].[Id] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND ([l2].[Id] = [t0].[Id])) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id]"); + } + + public override async Task Skip_Take_ToList_on_grouping_element(bool async) + { + await base.Skip_Take_ToList_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task SelectMany_with_navigation_and_Distinct_projecting_columns_including_join_key(bool async) + { + await base.SelectMany_with_navigation_and_Distinct_projecting_columns_including_join_key(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN ( + SELECT DISTINCT [l0].[Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id] AS [FK] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] +) AS [t] ON [l].[Id] = [t].[FK] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) + { + await base.Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Id1], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0], [t0].[Level2_Optional_Id0], [t0].[Level2_Required_Id0], [t0].[Name1], [t0].[OneToMany_Optional_Inverse3Id0], [t0].[OneToMany_Optional_Self_Inverse3Id0], [t0].[OneToMany_Required_Inverse3Id0], [t0].[OneToMany_Required_Self_Inverse3Id0], [t0].[OneToOne_Optional_PK_Inverse3Id0], [t0].[OneToOne_Optional_Self3Id0], [t0].[PeriodEnd1], [t0].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [l0].[Id] AS [Id0], [l1].[Id] AS [Id1], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l0].[Level2_Optional_Id] AS [Level2_Optional_Id0], [l0].[Level2_Required_Id] AS [Level2_Required_Id0], [l0].[Name] AS [Name1], [l0].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [l0].[OneToMany_Optional_Self_Inverse3Id] AS [OneToMany_Optional_Self_Inverse3Id0], [l0].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [l0].[OneToMany_Required_Self_Inverse3Id] AS [OneToMany_Required_Self_Inverse3Id0], [l0].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l0].[OneToOne_Optional_Self3Id] AS [OneToOne_Optional_Self3Id0], [l0].[PeriodEnd] AS [PeriodEnd1], [l0].[PeriodStart] AS [PeriodStart1] + FROM ( + SELECT TOP(2) [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + WHERE ([l].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND (([l2].[Name] <> N'Foo') OR [l2].[Name] IS NULL) + ORDER BY [l2].[Id] + ) AS [t] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[Level2_Required_Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +) AS [t0] +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Include_collection_with_conditional_order_by(bool async) + { + await base.Include_collection_with_conditional_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY CASE + WHEN [l].[Name] IS NOT NULL AND ([l].[Name] LIKE N'%03') THEN 1 + ELSE 2 +END, [l].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_member(bool async) + { + await base.Include_collection_with_multiple_orderbys_member(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Level1_Required_Id], [l].[Id]"); + } + + public override async Task Project_collection_and_root_entity(bool async) + { + await base.Project_collection_and_root_entity(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Filtered_include_basic_OrderBy_Skip(bool async) + { + await base.Filtered_include_basic_OrderBy_Skip(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Name]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE 1 < [t].[row] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Name]"); + } + + public override async Task Include_collection_with_groupby_in_subquery_and_filter_after_groupby(bool async) + { + await base.Include_collection_with_groupby_in_subquery_and_filter_after_groupby(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t].[Name], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM ( + SELECT [l].[Name] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Name] + HAVING ([l].[Name] <> N'Foo') OR [l].[Name] IS NULL +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Name] = [t0].[Name] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t0].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Name], [t0].[Id]"); + } + + public override async Task Select_subquery_single_nested_subquery2(bool async) + { + await base.Select_subquery_single_nested_subquery2(async); + + AssertSql( + @"SELECT [l].[Id], [t2].[Id], [t2].[Id0], [t2].[Id1], [t2].[c] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [t0].[Id] AS [Id0], [t1].[Id] AS [Id1], [t0].[c], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse3Id] + FROM ( + SELECT 1 AS [c], [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Id]) AS [row] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + ) AS [t] + WHERE [t].[row] <= 1 + ) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToMany_Optional_Inverse4Id] + FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + ) AS [t1] ON [t0].[Id] = [t1].[OneToMany_Optional_Inverse4Id] +) AS [t2] ON [l].[Id] = [t2].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t2].[Id], [t2].[Id0], [t2].[Id1]"); + } + + public override async Task Filtered_include_OrderBy(bool async) + { + await base.Filtered_include_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Name]"); + } + + public override async Task Multiple_complex_include_select(bool async) + { + await base.Multiple_complex_include_select(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Id] AS [Id0], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name] AS [Name0], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd] AS [PeriodEnd0], [l3].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[Level2_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [t].[Id]"); + } + + public override async Task Filtered_ThenInclude_OrderBy(bool async) + { + await base.Filtered_ThenInclude_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t].[Id] AS [Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name] AS [Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd] AS [PeriodEnd0], [t].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + ) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[Id], [t0].[Name0]"); + } + + public override async Task Filtered_include_Skip_Take_with_another_Skip_Take_on_top_level(bool async) + { + await base.Filtered_include_Skip_Take_with_another_Skip_Take_on_top_level(async); + + AssertSql( + @"@__p_0='10' +@__p_1='5' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Id] DESC + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ORDER BY [l1].[Name] DESC + OFFSET 2 ROWS FETCH NEXT 4 ROWS ONLY + ) AS [t1] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Id] = [l0].[Level2_Optional_Id] +) AS [t0] +ORDER BY [t].[Id] DESC, [t0].[Name] DESC, [t0].[Id]"); + } + + public override async Task Null_check_in_Dto_projection_should_not_be_removed(bool async) + { + await base.Null_check_in_Dto_projection_should_not_be_removed(async); + + AssertSql( + @"SELECT [l].[Id], [t].[c], [t].[Name], [t].[Id], [t].[Id0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT CASE + WHEN [l1].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [c], [l1].[Name], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Include_partially_added_before_Where_and_then_build_upon(bool async) + { + await base.Include_partially_added_before_Where_and_then_build_upon(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l0].[Id], [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Id] AS [Id0], [l3].[Level3_Optional_Id], [l3].[Level3_Required_Id], [l3].[Name] AS [Name0], [l3].[OneToMany_Optional_Inverse4Id], [l3].[OneToMany_Optional_Self_Inverse4Id], [l3].[OneToMany_Required_Inverse4Id], [l3].[OneToMany_Required_Self_Inverse4Id], [l3].[OneToOne_Optional_PK_Inverse4Id], [l3].[OneToOne_Optional_Self4Id], [l3].[PeriodEnd] AS [PeriodEnd0], [l3].[PeriodStart] AS [PeriodStart0] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[Level3_Optional_Id] +) AS [t] ON [l1].[Id] = [t].[OneToMany_Optional_Inverse3Id] +WHERE ([l0].[Id] < 3) OR ([l1].[Id] > 8) +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [t].[Id]"); + } + + public override async Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key(bool async) + { + await base.Complex_multi_include_with_order_by_and_paging_joins_on_correct_key(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd], [l3].[PeriodStart] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Name] + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l0].[Id] = [l2].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l1].[Id] = [l3].[OneToMany_Required_Inverse3Id] +ORDER BY [t].[Name], [t].[Id], [l0].[Id], [l1].[Id], [l2].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_property(bool async) + { + await base.Include_collection_with_multiple_orderbys_property(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Level1_Required_Id], [l].[Name], [l].[Id]"); + } + + public override async Task Multiple_complex_includes(bool async) + { + await base.Multiple_complex_includes(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Id] AS [Id0], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name] AS [Name0], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd] AS [PeriodEnd0], [l3].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[Level2_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [t].[Id]"); + } + + public override async Task Skip_Take_on_grouping_element_with_reference_include(bool async) + { + await base.Skip_Take_on_grouping_element_with_reference_include(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Date0], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Date] AS [Date0], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Date] = [l1].[Date] + ORDER BY [l1].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t1] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Id] = [l0].[Level1_Optional_Id] +) AS [t0] +ORDER BY [t].[Date], [t0].[Name], [t0].[Id]"); + } + + public override async Task Skip_Take_on_grouping_element_with_collection_include(bool async) + { + await base.Skip_Take_on_grouping_element_with_collection_include(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Date0], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Date] AS [Date0], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Date] = [l1].[Date] + ORDER BY [l1].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t1] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +) AS [t0] +ORDER BY [t].[Date], [t0].[Name], [t0].[Id]"); + } + + public override async Task Multiple_include_with_multiple_optional_navigations(bool async) + { + await base.Multiple_include_with_multiple_optional_navigations(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l2].[Id], [l3].[Id], [l4].[Id], [l5].[Id], [l5].[Level2_Optional_Id], [l5].[Level2_Required_Id], [l5].[Name], [l5].[OneToMany_Optional_Inverse3Id], [l5].[OneToMany_Optional_Self_Inverse3Id], [l5].[OneToMany_Required_Inverse3Id], [l5].[OneToMany_Required_Self_Inverse3Id], [l5].[OneToOne_Optional_PK_Inverse3Id], [l5].[OneToOne_Optional_Self3Id], [l5].[PeriodEnd], [l5].[PeriodStart], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Optional_Self_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToMany_Required_Self_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l3].[OneToOne_Optional_Self2Id], [l3].[PeriodEnd], [l3].[PeriodStart], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[Name], [l4].[OneToMany_Optional_Inverse3Id], [l4].[OneToMany_Optional_Self_Inverse3Id], [l4].[OneToMany_Required_Inverse3Id], [l4].[OneToMany_Required_Self_Inverse3Id], [l4].[OneToOne_Optional_PK_Inverse3Id], [l4].[OneToOne_Optional_Self3Id], [l4].[PeriodEnd], [l4].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l0].[Id] = [l2].[Level2_Optional_Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l].[Id] = [l3].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Id] = [l4].[Level2_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l5] ON [l0].[Id] = [l5].[OneToMany_Optional_Inverse3Id] +WHERE ([l1].[Name] <> N'Foo') OR [l1].[Name] IS NULL +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [l2].[Id], [l3].[Id], [l4].[Id]"); + } + + public override async Task Skip_Take_Distinct_on_grouping_element(bool async) + { + await base.Skip_Take_Distinct_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +OUTER APPLY ( + SELECT DISTINCT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE [t].[Date] = [l0].[Date] + ORDER BY [l0].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t1] +) AS [t0] +ORDER BY [t].[Date]"); + } + + public override async Task Include_collection_with_groupby_in_subquery_and_filter_before_groupby(bool async) + { + await base.Include_collection_with_groupby_in_subquery_and_filter_before_groupby(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t].[Name], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM ( + SELECT [l].[Name] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + WHERE [l].[Id] > 3 + GROUP BY [l].[Name] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE [l0].[Id] > 3 + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Name] = [t0].[Name] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t0].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Name], [t0].[Id]"); + } + + public override async Task Include_collection_followed_by_projecting_the_included_collection(bool async) + { + await base.Include_collection_followed_by_projecting_the_included_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Filtered_include_context_accessed_inside_filter_correlated(bool async) + { + await base.Filtered_include_context_accessed_inside_filter_correlated(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ( + SELECT COUNT(*) + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [l1].[Id] <> [l0].[Id]) > 1 + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Required_navigation_with_Include(bool async) + { + await base.Required_navigation_with_Include(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +INNER JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[OneToMany_Required_Inverse2Id] = [l1].[Id]"); + } + + public override async Task Include_collection_followed_by_complex_includes_and_projecting_the_included_collection(bool async) + { + await base.Include_collection_followed_by_complex_includes_and_projecting_the_included_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[Id1], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name1], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd1], [t].[PeriodStart1], [t].[Id2], [t].[Level2_Optional_Id0], [t].[Level2_Required_Id0], [t].[Name2], [t].[OneToMany_Optional_Inverse3Id0], [t].[OneToMany_Optional_Self_Inverse3Id0], [t].[OneToMany_Required_Inverse3Id0], [t].[OneToMany_Required_Self_Inverse3Id0], [t].[OneToOne_Optional_PK_Inverse3Id0], [t].[OneToOne_Optional_Self3Id0], [t].[PeriodEnd2], [t].[PeriodStart2], [t].[Id3], [t].[Level3_Optional_Id0], [t].[Level3_Required_Id0], [t].[Name3], [t].[OneToMany_Optional_Inverse4Id0], [t].[OneToMany_Optional_Self_Inverse4Id0], [t].[OneToMany_Required_Inverse4Id0], [t].[OneToMany_Required_Self_Inverse4Id0], [t].[OneToOne_Optional_PK_Inverse4Id0], [t].[OneToOne_Optional_Self4Id0], [t].[PeriodEnd3], [t].[PeriodStart3] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l2].[Id] AS [Id1], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name1], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd1], [l2].[PeriodStart] AS [PeriodStart1], [l3].[Id] AS [Id2], [l3].[Level2_Optional_Id] AS [Level2_Optional_Id0], [l3].[Level2_Required_Id] AS [Level2_Required_Id0], [l3].[Name] AS [Name2], [l3].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [l3].[OneToMany_Optional_Self_Inverse3Id] AS [OneToMany_Optional_Self_Inverse3Id0], [l3].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [l3].[OneToMany_Required_Self_Inverse3Id] AS [OneToMany_Required_Self_Inverse3Id0], [l3].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l3].[OneToOne_Optional_Self3Id] AS [OneToOne_Optional_Self3Id0], [l3].[PeriodEnd] AS [PeriodEnd2], [l3].[PeriodStart] AS [PeriodStart2], [l4].[Id] AS [Id3], [l4].[Level3_Optional_Id] AS [Level3_Optional_Id0], [l4].[Level3_Required_Id] AS [Level3_Required_Id0], [l4].[Name] AS [Name3], [l4].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [l4].[OneToMany_Optional_Self_Inverse4Id] AS [OneToMany_Optional_Self_Inverse4Id0], [l4].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [l4].[OneToMany_Required_Self_Inverse4Id] AS [OneToMany_Required_Self_Inverse4Id0], [l4].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [l4].[OneToOne_Optional_Self4Id] AS [OneToOne_Optional_Self4Id0], [l4].[PeriodEnd] AS [PeriodEnd3], [l4].[PeriodStart] AS [PeriodStart3] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Optional_Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l0].[Id] = [l3].[Level2_Optional_Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Id] = [l4].[OneToMany_Optional_Inverse4Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2]"); + } + + public override async Task Filtered_include_variable_used_inside_filter(bool async) + { + await base.Filtered_include_variable_used_inside_filter(async); + + AssertSql( + @"@__prm_0='Foo' (Size = 4000) + +SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> @__prm_0) OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Multiple_optional_navigation_with_string_based_Include(bool async) + { + await base.Multiple_optional_navigation_with_string_based_Include(async); + + AssertSql( + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l].[Id], [l0].[Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Include_after_SelectMany(bool async) + { + await base.Include_after_SelectMany(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Required_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Optional_navigation_with_Include_and_order(bool async) + { + await base.Optional_navigation_with_Include_and_order(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l0].[Name], [l].[Id], [l0].[Id]"); + } + + public override async Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async) + { + await base.SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(async); + + AssertSql( + @"SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l].[Id], [l0].[Id], [l1].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2], [t0].[Id], [t0].[Id0], [t0].[Id1], [t0].[Id2], [l11].[Id], [l12].[Id], [l13].[Id], [l14].[Id], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l14].[Name] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Inverse4Id] +INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0], [l5].[Id] AS [Id1], [l6].[Id] AS [Id2] + FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Level3_Required_Id] = [l4].[Id] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l5] ON [l4].[Level2_Optional_Id] = [l5].[Id] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l6] ON [l5].[Id] = [l6].[OneToMany_Required_Self_Inverse2Id] +) AS [t] ON [l2].[Id] = [t].[Id2] +LEFT JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0], [l9].[Id] AS [Id1], [l10].[Id] AS [Id2], [l10].[Level2_Optional_Id] AS [Level2_Optional_Id0] + FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l7] + INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l8] ON [l7].[Level3_Required_Id] = [l8].[Id] + INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l9] ON [l8].[Level2_Required_Id] = [l9].[Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l10] ON [l9].[Id] = [l10].[OneToMany_Required_Inverse3Id] +) AS [t0] ON [t].[Id2] = [t0].[Id2] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l11] ON [l2].[OneToMany_Optional_Inverse4Id] = [l11].[Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l12] ON [t].[Id2] = [l12].[Level2_Optional_Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l13] ON [t0].[Level2_Optional_Id0] = [l13].[Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l14] ON [l13].[Id] = [l14].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l15].[Id], [l15].[Date], [l15].[Level1_Optional_Id], [l15].[Level1_Required_Id], [l15].[Name], [l15].[OneToMany_Optional_Inverse2Id], [l15].[OneToMany_Optional_Self_Inverse2Id], [l15].[OneToMany_Required_Inverse2Id], [l15].[OneToMany_Required_Self_Inverse2Id], [l15].[OneToOne_Optional_PK_Inverse2Id], [l15].[OneToOne_Optional_Self2Id], [l15].[PeriodEnd], [l15].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l15] + WHERE [l15].[Id] <> 42 +) AS [t1] ON [t].[Id2] = [t1].[OneToMany_Optional_Self_Inverse2Id] +WHERE ([l11].[Name] <> N'Foo') OR [l11].[Name] IS NULL +ORDER BY [l12].[Id], [l].[Id], [l0].[Id], [l1].[Id], [l2].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2], [t0].[Id], [t0].[Id0], [t0].[Id1], [t0].[Id2], [l11].[Id], [l13].[Id], [l14].[Id]"); + } + + public override async Task Include_nested_with_optional_navigation(bool async) + { + await base.Include_nested_with_optional_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id] AS [Id0], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name0], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd0], [l2].[PeriodStart] AS [PeriodStart0] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +) AS [t] ON [l0].[Id] = [t].[OneToMany_Required_Inverse3Id] +WHERE ([l0].[Name] <> N'L2 09') OR [l0].[Name] IS NULL +ORDER BY [l].[Id], [l0].[Id], [t].[Id]"); + } + + public override async Task Project_collection_navigation_composed(bool async) + { + await base.Project_collection_navigation_composed(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +WHERE [l].[Id] < 3 +ORDER BY [l].[Id]"); + } + + public override async Task Include_partially_added_before_Where_and_then_build_upon_with_filtered_include(bool async) + { + await base.Include_partially_added_before_Where_and_then_build_upon_with_filtered_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l0].[Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Optional_Self_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToMany_Required_Self_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToOne_Optional_Self3Id], [t1].[PeriodEnd], [t1].[PeriodStart], [t1].[Id0], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Name0], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Optional_Self_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToMany_Required_Self_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t1].[OneToOne_Optional_Self4Id], [t1].[PeriodEnd0], [t1].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [l2].[PeriodEnd], [l2].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Optional_Inverse3Id] ORDER BY [l2].[Id]) AS [row] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l1].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd], [l3].[PeriodStart], [l4].[Id] AS [Id0], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Name] AS [Name0], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Optional_Self_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToMany_Required_Self_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id], [l4].[OneToOne_Optional_Self4Id], [l4].[PeriodEnd] AS [PeriodEnd0], [l4].[PeriodStart] AS [PeriodStart0] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Id] = [l4].[Level3_Optional_Id] +) AS [t1] ON [l1].[Id] = [t1].[OneToMany_Required_Inverse3Id] +WHERE ([l0].[Id] < 3) OR ([l1].[Id] > 8) +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [t0].[OneToMany_Optional_Inverse3Id], [t0].[Id], [t1].[Id]"); + } + + public override async Task Required_navigation_with_Include_ThenInclude(bool async) + { + await base.Required_navigation_with_Include_ThenInclude(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id], [l2].[Date], [l2].[Name], [l2].[OneToMany_Optional_Self_Inverse1Id], [l2].[OneToMany_Required_Self_Inverse1Id], [l2].[OneToOne_Optional_Self1Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Level3_Required_Id] = [l0].[Id] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[OneToMany_Required_Inverse3Id] = [l1].[Id] +LEFT JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[OneToMany_Optional_Inverse2Id] = [l2].[Id]"); + } + + public override async Task Project_collection_navigation_using_ef_property(bool async) + { + await base.Project_collection_navigation_using_ef_property(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Take_Select_collection_Take(bool async) + { + await base.Take_Select_collection_Take(async); + + AssertSql( + @"@__p_0='1' + +SELECT [t].[Id], [t].[Name], [t0].[Id], [t0].[Name], [t0].[Level1Id], [t0].[Level2Id], [t0].[Id0], [t0].[Date], [t0].[Name0], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Name] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Name], [t1].[OneToMany_Required_Inverse2Id] AS [Level1Id], [t1].[Level1_Required_Id] AS [Level2Id], [l0].[Id] AS [Id0], [l0].[Date], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM ( + SELECT TOP(3) [l1].[Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Id] = [l1].[OneToMany_Required_Inverse2Id] + ORDER BY [l1].[Id] + ) AS [t1] + INNER JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Level1_Required_Id] = [l0].[Id] +) AS [t0] +ORDER BY [t].[Id], [t0].[Id]"); + } + + public override async Task Complex_multi_include_with_order_by_and_paging(bool async) + { + await base.Complex_multi_include_with_order_by_and_paging(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Name] + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l0].[Id] = [l2].[OneToMany_Required_Inverse3Id] +ORDER BY [t].[Name], [t].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Include_collection_with_groupby_in_subquery(bool async) + { + await base.Include_collection_with_groupby_in_subquery(async); + + AssertSql( + @"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t].[Name], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM ( + SELECT [l].[Name] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Name] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Name] = [t0].[Name] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t0].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Name], [t0].[Id]"); + } + + public override async Task Filtered_include_ThenInclude_OrderBy(bool async) + { + await base.Filtered_include_ThenInclude_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t].[Id] AS [Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name] AS [Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd] AS [PeriodEnd0], [t].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + ) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[Name], [t0].[Id], [t0].[Name0] DESC"); + } + + public override async Task Project_collection_navigation_nested(bool async) + { + await base.Project_collection_navigation_nested(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Filtered_include_after_different_filtered_include_different_level(bool async) + { + await base.Filtered_include_after_different_filtered_include_different_level(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t2].[Id], [t2].[Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Optional_Self_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToMany_Required_Self_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[OneToOne_Optional_Self2Id], [t2].[PeriodEnd], [t2].[PeriodStart], [t2].[Id0], [t2].[Level2_Optional_Id], [t2].[Level2_Required_Id], [t2].[Name0], [t2].[OneToMany_Optional_Inverse3Id], [t2].[OneToMany_Optional_Self_Inverse3Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[OneToMany_Required_Self_Inverse3Id], [t2].[OneToOne_Optional_PK_Inverse3Id], [t2].[OneToOne_Optional_Self3Id], [t2].[PeriodEnd0], [t2].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name] AS [Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd] AS [PeriodEnd0], [t0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT TOP(3) [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) AND (([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL) + ORDER BY [l0].[Name] + ) AS [t] + LEFT JOIN ( + SELECT [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Optional_Self_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToMany_Required_Self_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToOne_Optional_Self3Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Required_Inverse3Id] ORDER BY [l1].[Name] DESC) AS [row] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE ([l1].[Name] <> N'Bar') OR [l1].[Name] IS NULL + ) AS [t1] + WHERE 1 < [t1].[row] + ) AS [t0] ON [t].[Id] = [t0].[OneToMany_Required_Inverse3Id] +) AS [t2] +ORDER BY [l].[Id], [t2].[Name], [t2].[Id], [t2].[OneToMany_Required_Inverse3Id], [t2].[Name0] DESC"); + } + + public override async Task Null_check_in_anonymous_type_projection_should_not_be_removed(bool async) + { + await base.Null_check_in_anonymous_type_projection_should_not_be_removed(async); + + AssertSql( + @"SELECT [l].[Id], [t].[c], [t].[Name], [t].[Id], [t].[Id0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT CASE + WHEN [l1].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [c], [l1].[Name], [l0].[Id], [l1].[Id] AS [Id0], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + { + // Nested collection with ToList. Issue #23303. + + await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async)); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id], [t0].[c] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT [l1].[Name], [l1].[Id] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND ([l2].[Id] = [t0].[Id])) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id]"); + } + + public override async Task Skip_on_grouping_element(bool async) + { + await base.Skip_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE 1 < [t1].[row] +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task Filtered_include_Take_without_OrderBy(bool async) + { + await base.Filtered_include_Take_without_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Include_after_SelectMany_and_multiple_reference_navigations(bool async) + { + await base.Include_after_SelectMany_and_multiple_reference_navigations(async); + + AssertSql( + @"SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l].[Id], [l0].[Id], [l1].[Id], [l3].[Id], [l3].[Level3_Optional_Id], [l3].[Level3_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse4Id], [l3].[OneToMany_Optional_Self_Inverse4Id], [l3].[OneToMany_Required_Inverse4Id], [l3].[OneToMany_Required_Self_Inverse4Id], [l3].[OneToOne_Optional_PK_Inverse4Id], [l3].[OneToOne_Optional_Self4Id], [l3].[PeriodEnd], [l3].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Required_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[OneToMany_Optional_Self_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [l2].[Id]"); + } + + public override async Task Include_reference_ThenInclude_collection_order_by(bool async) + { + await base.Include_reference_ThenInclude_collection_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Id], [l0].[Id]"); + } + + public override async Task FirstOrDefault_with_predicate_on_correlated_collection_in_projection(bool async) + { + await base.FirstOrDefault_with_predicate_on_correlated_collection_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id], [l0].[Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON ([l].[Id] = [t0].[OneToMany_Optional_Inverse2Id]) AND ([l].[Id] = [t0].[Id])"); + } + + public override async Task SelectMany_with_Include_and_order_by(bool async) + { + await base.SelectMany_with_Include_and_order_by(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l0].[Name], [l].[Id], [l0].[Id]"); + } + + public override async Task SelectMany_navigation_property_with_include_and_followed_by_select_collection_navigation(bool async) + { + await base.SelectMany_navigation_property_with_include_and_followed_by_select_collection_navigation(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Optional_Self_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToMany_Required_Self_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [l2].[OneToOne_Optional_Self3Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Required_Inverse3Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l0].[Id] = [l2].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key2(bool async) + { + await base.Complex_multi_include_with_order_by_and_paging_joins_on_correct_key2(async); + + AssertSql( + @"@__p_0='0' +@__p_1='10' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Name] + OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +) AS [t] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [t].[Name], [t].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Project_navigation_and_collection(bool async) + { + await base.Project_navigation_and_collection(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Multiple_optional_navigation_with_Include(bool async) + { + await base.Multiple_optional_navigation_with_Include(async); + + AssertSql( + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l].[Id], [l0].[Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Project_collection_navigation_nested_with_take(bool async) + { + await base.Project_collection_navigation_nested_with_take(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [t0].[Id], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Optional_Inverse3Id] ORDER BY [l1].[Id]) AS [row] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + ) AS [t] + WHERE [t].[row] <= 50 +) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [t0].[OneToMany_Optional_Inverse3Id], [t0].[Id]"); + } + + public override async Task Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(bool async) + { + await base.Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Name0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Optional_Self_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToMany_Required_Self_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToOne_Optional_Self3Id], [t1].[PeriodEnd0], [t1].[PeriodStart0], [t1].[Id1], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Name1], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Optional_Self_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToMany_Required_Self_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t1].[OneToOne_Optional_Self4Id], [t1].[PeriodEnd1], [t1].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0], [t0].[Id] AS [Id1], [t0].[Level3_Optional_Id], [t0].[Level3_Required_Id], [t0].[Name] AS [Name1], [t0].[OneToMany_Optional_Inverse4Id], [t0].[OneToMany_Optional_Self_Inverse4Id], [t0].[OneToMany_Required_Inverse4Id], [t0].[OneToMany_Required_Self_Inverse4Id], [t0].[OneToOne_Optional_PK_Inverse4Id], [t0].[OneToOne_Optional_Self4Id], [t0].[PeriodEnd] AS [PeriodEnd1], [t0].[PeriodStart] AS [PeriodStart1] + FROM ( + SELECT TOP(1) [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE ([l].[Id] = [l1].[OneToMany_Optional_Inverse2Id]) AND (([l1].[Name] <> N'Foo') OR [l1].[Name] IS NULL) + ORDER BY [l1].[Id] + ) AS [t] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart] + FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + WHERE [l2].[Id] > 1 + ) AS [t0] ON [l0].[Id] = [t0].[OneToMany_Optional_Inverse4Id] +) AS [t1] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0]"); + } + + public override async Task Filtered_include_basic_Where(bool async) + { + await base.Filtered_include_basic_Where(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE [l0].[Id] > 5 +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Projecting_collection_with_FirstOrDefault(bool async) + { + await base.Projecting_collection_with_FirstOrDefault(async); + + AssertSql( + @"SELECT [t].[Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM ( + SELECT TOP(1) [l].[Id] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + WHERE [l].[Id] = 1 +) AS [t] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [t].[Id]"); + } + + public override async Task Filtered_include_complex_three_level_with_middle_having_filter2(bool async) + { + await base.Filtered_include_complex_three_level_with_middle_having_filter2(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Name0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Optional_Self_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToMany_Required_Self_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToOne_Optional_Self3Id], [t1].[PeriodEnd0], [t1].[PeriodStart0], [t1].[Id00], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Name00], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Optional_Self_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToMany_Required_Self_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t1].[OneToOne_Optional_Self4Id], [t1].[PeriodEnd00], [t1].[PeriodStart00], [t1].[Id1], [t1].[Level3_Optional_Id0], [t1].[Level3_Required_Id0], [t1].[Name1], [t1].[OneToMany_Optional_Inverse4Id0], [t1].[OneToMany_Optional_Self_Inverse4Id0], [t1].[OneToMany_Required_Inverse4Id0], [t1].[OneToMany_Required_Self_Inverse4Id0], [t1].[OneToOne_Optional_PK_Inverse4Id0], [t1].[OneToOne_Optional_Self4Id0], [t1].[PeriodEnd1], [t1].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name] AS [Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd] AS [PeriodEnd0], [t0].[PeriodStart] AS [PeriodStart0], [t0].[Id0] AS [Id00], [t0].[Level3_Optional_Id], [t0].[Level3_Required_Id], [t0].[Name0] AS [Name00], [t0].[OneToMany_Optional_Inverse4Id], [t0].[OneToMany_Optional_Self_Inverse4Id], [t0].[OneToMany_Required_Inverse4Id], [t0].[OneToMany_Required_Self_Inverse4Id], [t0].[OneToOne_Optional_PK_Inverse4Id], [t0].[OneToOne_Optional_Self4Id], [t0].[PeriodEnd0] AS [PeriodEnd00], [t0].[PeriodStart0] AS [PeriodStart00], [t0].[Id1], [t0].[Level3_Optional_Id0], [t0].[Level3_Required_Id0], [t0].[Name1], [t0].[OneToMany_Optional_Inverse4Id0], [t0].[OneToMany_Optional_Self_Inverse4Id0], [t0].[OneToMany_Required_Inverse4Id0], [t0].[OneToMany_Required_Self_Inverse4Id0], [t0].[OneToOne_Optional_PK_Inverse4Id0], [t0].[OneToOne_Optional_Self4Id0], [t0].[PeriodEnd1], [t0].[PeriodStart1] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + OUTER APPLY ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level3_Optional_Id], [l1].[Level3_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse4Id], [l1].[OneToMany_Optional_Self_Inverse4Id], [l1].[OneToMany_Required_Inverse4Id], [l1].[OneToMany_Required_Self_Inverse4Id], [l1].[OneToOne_Optional_PK_Inverse4Id], [l1].[OneToOne_Optional_Self4Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l2].[Id] AS [Id1], [l2].[Level3_Optional_Id] AS [Level3_Optional_Id0], [l2].[Level3_Required_Id] AS [Level3_Required_Id0], [l2].[Name] AS [Name1], [l2].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [l2].[OneToMany_Optional_Self_Inverse4Id] AS [OneToMany_Optional_Self_Inverse4Id0], [l2].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [l2].[OneToMany_Required_Self_Inverse4Id] AS [OneToMany_Required_Self_Inverse4Id0], [l2].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [l2].[OneToOne_Optional_Self4Id] AS [OneToOne_Optional_Self4Id0], [l2].[PeriodEnd] AS [PeriodEnd1], [l2].[PeriodStart] AS [PeriodStart1] + FROM ( + SELECT TOP(1) [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd], [l3].[PeriodStart] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + WHERE ([l0].[Id] = [l3].[OneToMany_Optional_Inverse3Id]) AND (([l3].[Name] <> N'Foo') OR [l3].[Name] IS NULL) + ORDER BY [l3].[Id] + ) AS [t] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t].[Id] = [l1].[OneToMany_Optional_Inverse4Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [t].[Id] = [l2].[OneToMany_Required_Inverse4Id] + ) AS [t0] +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id00]"); + } + + public override async Task Include_inside_subquery(bool async) + { + await base.Include_inside_subquery(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] + WHERE [l0].[Id] > 0 +) AS [t] +WHERE [l].[Id] < 3 +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Include_and_ThenInclude_collections_followed_by_projecting_the_first_collection(bool async) + { + await base.Include_and_ThenInclude_collections_followed_by_projecting_the_first_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Filtered_include_Take_with_another_Take_on_top_level(bool async) + { + await base.Filtered_include_Take_with_another_Take_on_top_level(async); + + AssertSql( + @"@__p_0='5' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT TOP(4) [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ORDER BY [l1].[Name] DESC + ) AS [t1] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Id] = [l0].[Level2_Optional_Id] +) AS [t0] +ORDER BY [t].[Id], [t0].[Name] DESC, [t0].[Id]"); + } + + public override async Task Optional_navigation_with_order_by_and_Include(bool async) + { + await base.Optional_navigation_with_order_by_and_Include(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l0].[Name], [l].[Id], [l0].[Id]"); + } + + public override async Task Include_collection_multiple(bool async) + { + await base.Include_collection_multiple(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[Id1], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name1], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd1], [t].[PeriodStart1], [t].[Id2], [t].[Level2_Optional_Id0], [t].[Level2_Required_Id0], [t].[Name2], [t].[OneToMany_Optional_Inverse3Id0], [t].[OneToMany_Optional_Self_Inverse3Id0], [t].[OneToMany_Required_Inverse3Id0], [t].[OneToMany_Required_Self_Inverse3Id0], [t].[OneToOne_Optional_PK_Inverse3Id0], [t].[OneToOne_Optional_Self3Id0], [t].[PeriodEnd2], [t].[PeriodStart2], [t].[Id3], [t].[Level3_Optional_Id0], [t].[Level3_Required_Id0], [t].[Name3], [t].[OneToMany_Optional_Inverse4Id0], [t].[OneToMany_Optional_Self_Inverse4Id0], [t].[OneToMany_Required_Inverse4Id0], [t].[OneToMany_Required_Self_Inverse4Id0], [t].[OneToOne_Optional_PK_Inverse4Id0], [t].[OneToOne_Optional_Self4Id0], [t].[PeriodEnd3], [t].[PeriodStart3] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l2].[Id] AS [Id1], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name1], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd1], [l2].[PeriodStart] AS [PeriodStart1], [l3].[Id] AS [Id2], [l3].[Level2_Optional_Id] AS [Level2_Optional_Id0], [l3].[Level2_Required_Id] AS [Level2_Required_Id0], [l3].[Name] AS [Name2], [l3].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [l3].[OneToMany_Optional_Self_Inverse3Id] AS [OneToMany_Optional_Self_Inverse3Id0], [l3].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [l3].[OneToMany_Required_Self_Inverse3Id] AS [OneToMany_Required_Self_Inverse3Id0], [l3].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l3].[OneToOne_Optional_Self3Id] AS [OneToOne_Optional_Self3Id0], [l3].[PeriodEnd] AS [PeriodEnd2], [l3].[PeriodStart] AS [PeriodStart2], [l4].[Id] AS [Id3], [l4].[Level3_Optional_Id] AS [Level3_Optional_Id0], [l4].[Level3_Required_Id] AS [Level3_Required_Id0], [l4].[Name] AS [Name3], [l4].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [l4].[OneToMany_Optional_Self_Inverse4Id] AS [OneToMany_Optional_Self_Inverse4Id0], [l4].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [l4].[OneToMany_Required_Self_Inverse4Id] AS [OneToMany_Required_Self_Inverse4Id0], [l4].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [l4].[OneToOne_Optional_Self4Id] AS [OneToOne_Optional_Self4Id0], [l4].[PeriodEnd] AS [PeriodEnd3], [l4].[PeriodStart] AS [PeriodStart3] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Optional_Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l0].[Id] = [l3].[Level2_Optional_Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Id] = [l4].[OneToMany_Optional_Inverse4Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2]"); + } + + public override async Task Project_collection_navigation_nested_anonymous(bool async) + { + await base.Project_collection_navigation_nested_anonymous(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Include_after_multiple_SelectMany_and_reference_navigation(bool async) + { + await base.Include_after_multiple_SelectMany_and_reference_navigation(async); + + AssertSql( + @"SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l].[Id], [l0].[Id], [l1].[Id], [l3].[Id], [l3].[Level3_Optional_Id], [l3].[Level3_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse4Id], [l3].[OneToMany_Optional_Self_Inverse4Id], [l3].[OneToMany_Required_Inverse4Id], [l3].[OneToMany_Required_Self_Inverse4Id], [l3].[OneToOne_Optional_PK_Inverse4Id], [l3].[OneToOne_Optional_Self4Id], [l3].[PeriodEnd], [l3].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Required_Inverse2Id] +INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[OneToMany_Required_Self_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [l2].[Id]"); + } + + public override async Task Multiple_complex_includes_self_ref(bool async) + { + await base.Multiple_complex_includes_self_ref(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l1].[PeriodEnd], [l1].[PeriodStart], [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Date0], [t].[Name0], [t].[OneToMany_Optional_Self_Inverse1Id0], [t].[OneToMany_Required_Self_Inverse1Id0], [t].[OneToOne_Optional_Self1Id0], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[OneToOne_Optional_Self1Id] = [l0].[Id] +LEFT JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Self_Inverse1Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Date], [l2].[Name], [l2].[OneToMany_Optional_Self_Inverse1Id], [l2].[OneToMany_Required_Self_Inverse1Id], [l2].[OneToOne_Optional_Self1Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l3].[Id] AS [Id0], [l3].[Date] AS [Date0], [l3].[Name] AS [Name0], [l3].[OneToMany_Optional_Self_Inverse1Id] AS [OneToMany_Optional_Self_Inverse1Id0], [l3].[OneToMany_Required_Self_Inverse1Id] AS [OneToMany_Required_Self_Inverse1Id0], [l3].[OneToOne_Optional_Self1Id] AS [OneToOne_Optional_Self1Id0], [l3].[PeriodEnd] AS [PeriodEnd0], [l3].[PeriodStart] AS [PeriodStart0] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[OneToOne_Optional_Self1Id] = [l3].[Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Self_Inverse1Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [t].[Id]"); + } + + public override async Task Include_collection_then_reference(bool async) + { + await base.Include_collection_then_reference(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Include_collection(bool async) + { + await base.Include_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Multiple_SelectMany_with_Include(bool async) + { + await base.Multiple_SelectMany_with_Include(async); + + AssertSql( + @"SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l].[Id], [l0].[Id], [l3].[Id], [l3].[Level3_Optional_Id], [l3].[Level3_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse4Id], [l3].[OneToMany_Optional_Self_Inverse4Id], [l3].[OneToMany_Required_Inverse4Id], [l3].[OneToMany_Required_Self_Inverse4Id], [l3].[OneToOne_Optional_PK_Inverse4Id], [l3].[OneToOne_Optional_Self4Id], [l3].[PeriodEnd], [l3].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l1].[Id] = [l3].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [l2].[Id]"); + } + + public override async Task Lift_projection_mapping_when_pushing_down_subquery(bool async) + { + await base.Lift_projection_mapping_when_pushing_down_subquery(async); + + AssertSql( + @"@__p_0='25' + +SELECT [t].[Id], [t0].[Id], [l1].[Id], [t0].[c] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[c], [t1].[OneToMany_Required_Inverse2Id] + FROM ( + SELECT [l0].[Id], 1 AS [c], [l0].[OneToMany_Required_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Required_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 1 +) AS [t0] ON [t].[Id] = [t0].[OneToMany_Required_Inverse2Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t].[Id] = [l1].[OneToMany_Required_Inverse2Id] +ORDER BY [t].[Id], [t0].[Id]"); + } + + public override async Task SelectMany_with_Include2(bool async) + { + await base.SelectMany_with_Include2(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id]"); + } + + public override async Task Project_collection_navigation(bool async) + { + await base.Project_collection_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task + Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(bool async) + { + await base + .Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0], [t0].[Id00], [t0].[Date0], [t0].[Level1_Optional_Id0], [t0].[Level1_Required_Id0], [t0].[Name00], [t0].[OneToMany_Optional_Inverse2Id0], [t0].[OneToMany_Optional_Self_Inverse2Id0], [t0].[OneToMany_Required_Inverse2Id0], [t0].[OneToMany_Required_Self_Inverse2Id0], [t0].[OneToOne_Optional_PK_Inverse2Id0], [t0].[OneToOne_Optional_Self2Id0], [t0].[PeriodEnd00], [t0].[PeriodStart00], [t0].[Id1], [t0].[Level2_Optional_Id0], [t0].[Level2_Required_Id0], [t0].[Name1], [t0].[OneToMany_Optional_Inverse3Id0], [t0].[OneToMany_Optional_Self_Inverse3Id0], [t0].[OneToMany_Required_Inverse3Id0], [t0].[OneToMany_Required_Self_Inverse3Id0], [t0].[OneToOne_Optional_PK_Inverse3Id0], [t0].[OneToOne_Optional_Self3Id0], [t0].[PeriodEnd1], [t0].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t].[Id] AS [Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name] AS [Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd] AS [PeriodEnd0], [t].[PeriodStart] AS [PeriodStart0], [t].[Id0] AS [Id00], [t].[Date] AS [Date0], [t].[Level1_Optional_Id] AS [Level1_Optional_Id0], [t].[Level1_Required_Id] AS [Level1_Required_Id0], [t].[Name0] AS [Name00], [t].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [t].[OneToMany_Optional_Self_Inverse2Id] AS [OneToMany_Optional_Self_Inverse2Id0], [t].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [t].[OneToMany_Required_Self_Inverse2Id] AS [OneToMany_Required_Self_Inverse2Id0], [t].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [t].[OneToOne_Optional_Self2Id] AS [OneToOne_Optional_Self2Id0], [t].[PeriodEnd0] AS [PeriodEnd00], [t].[PeriodStart0] AS [PeriodStart00], [t].[Id1], [t].[Level2_Optional_Id0], [t].[Level2_Required_Id0], [t].[Name1], [t].[OneToMany_Optional_Inverse3Id0], [t].[OneToMany_Optional_Self_Inverse3Id0], [t].[OneToMany_Required_Inverse3Id0], [t].[OneToMany_Required_Self_Inverse3Id0], [t].[OneToOne_Optional_PK_Inverse3Id0], [t].[OneToOne_Optional_Self3Id0], [t].[PeriodEnd1], [t].[PeriodStart1] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id] AS [Id0], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name] AS [Name0], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd] AS [PeriodEnd0], [l2].[PeriodStart] AS [PeriodStart0], [l3].[Id] AS [Id1], [l3].[Level2_Optional_Id] AS [Level2_Optional_Id0], [l3].[Level2_Required_Id] AS [Level2_Required_Id0], [l3].[Name] AS [Name1], [l3].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [l3].[OneToMany_Optional_Self_Inverse3Id] AS [OneToMany_Optional_Self_Inverse3Id0], [l3].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [l3].[OneToMany_Required_Self_Inverse3Id] AS [OneToMany_Required_Self_Inverse3Id0], [l3].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l3].[OneToOne_Optional_Self3Id] AS [OneToOne_Optional_Self3Id0], [l3].[PeriodEnd] AS [PeriodEnd1], [l3].[PeriodStart] AS [PeriodStart1] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[OneToMany_Required_Inverse3Id] = [l2].[Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] ON [l2].[Id] = [l3].[OneToMany_Optional_Inverse3Id] + ) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0], [t0].[Id00]"); + } + + public override async Task Complex_query_issue_21665(bool async) + { + await base.Complex_query_issue_21665(async); + + AssertSql( + @"SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Name0], [t].[c], [t].[c0], [t].[c1], [t].[Id0], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[ChildCount], [t0].[Level2Name], [t0].[Level2Count], [t0].[IsLevel2There], [t0].[Id0] +FROM ( + SELECT TOP(1) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Name] AS [Name0], ( + SELECT COUNT(*) + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [l].[Id] = [l1].[OneToMany_Optional_Self_Inverse1Id]) AS [c], ( + SELECT COUNT(*) + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AS [c0], CASE + WHEN EXISTS ( + SELECT 1 + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + WHERE ([l].[Id] = [l3].[OneToMany_Optional_Inverse2Id]) AND ([l3].[Id] = 2)) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [c1], [l0].[Id] AS [Id0] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + WHERE [l].[Id] = 2 + ORDER BY [l].[Name] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart], ( + SELECT COUNT(*) + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l5] + WHERE [t1].[Id] = [l5].[OneToMany_Optional_Self_Inverse1Id]) AS [ChildCount], [l4].[Name] AS [Level2Name], ( + SELECT COUNT(*) + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l6] + WHERE [t1].[Id] = [l6].[OneToMany_Optional_Inverse2Id]) AS [Level2Count], CASE + WHEN EXISTS ( + SELECT 1 + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l7] + WHERE ([t1].[Id] = [l7].[OneToMany_Optional_Inverse2Id]) AND ([l7].[Id] = 2)) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [IsLevel2There], [l4].[Id] AS [Id0] + FROM ( + SELECT [l8].[Id], [l8].[Date], [l8].[Name], [l8].[OneToMany_Optional_Self_Inverse1Id], [l8].[OneToMany_Required_Self_Inverse1Id], [l8].[OneToOne_Optional_Self1Id], [l8].[PeriodEnd], [l8].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l8] + WHERE [t].[Id] = [l8].[OneToMany_Optional_Self_Inverse1Id] + ORDER BY [l8].[Name] + OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY + ) AS [t1] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [t1].[Id] = [l4].[Level1_Optional_Id] +) AS [t0] +ORDER BY [t].[Name], [t].[Id], [t].[Id0], [t0].[Name], [t0].[Id]"); + } + + public override async Task Filtered_include_and_non_filtered_include_on_same_navigation1(bool async) + { + await base.Filtered_include_and_non_filtered_include_on_same_navigation1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task + Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top(bool async) + { + await base.Complex_SelectMany_with_nested_navigations_and_explicit_DefaultIfEmpty_with_other_query_operators_composed_on_top( + async); + + AssertSql( + @"SELECT [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart], [l].[Id], [l0].[Id], [l1].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2], [t0].[Id], [t0].[Id0], [t0].[Id1], [t0].[Id2], [l11].[Id], [l12].[Id], [l13].[Id], [l14].[Id], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l14].[Name] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Inverse4Id] +INNER JOIN ( + SELECT [l3].[Id], [l4].[Id] AS [Id0], [l5].[Id] AS [Id1], [l6].[Id] AS [Id2] + FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l4] ON [l3].[Level3_Required_Id] = [l4].[Id] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l5] ON [l4].[Level2_Optional_Id] = [l5].[Id] + LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l6] ON [l5].[Id] = [l6].[OneToMany_Required_Self_Inverse2Id] +) AS [t] ON [l2].[Id] = [t].[Id2] +LEFT JOIN ( + SELECT [l7].[Id], [l8].[Id] AS [Id0], [l9].[Id] AS [Id1], [l10].[Id] AS [Id2], [l10].[Level2_Optional_Id] AS [Level2_Optional_Id0] + FROM [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l7] + INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l8] ON [l7].[Level3_Required_Id] = [l8].[Id] + INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l9] ON [l8].[Level2_Required_Id] = [l9].[Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l10] ON [l9].[Id] = [l10].[OneToMany_Required_Inverse3Id] +) AS [t0] ON [t].[Id2] = [t0].[Id2] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l11] ON [l2].[OneToMany_Optional_Inverse4Id] = [l11].[Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l12] ON [t].[Id2] = [l12].[Level2_Optional_Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l13] ON [t0].[Level2_Optional_Id0] = [l13].[Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l14] ON [l13].[Id] = [l14].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l15].[Id], [l15].[Date], [l15].[Level1_Optional_Id], [l15].[Level1_Required_Id], [l15].[Name], [l15].[OneToMany_Optional_Inverse2Id], [l15].[OneToMany_Optional_Self_Inverse2Id], [l15].[OneToMany_Required_Inverse2Id], [l15].[OneToMany_Required_Self_Inverse2Id], [l15].[OneToOne_Optional_PK_Inverse2Id], [l15].[OneToOne_Optional_Self2Id], [l15].[PeriodEnd], [l15].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l15] + WHERE [l15].[Id] <> 42 +) AS [t1] ON [t].[Id2] = [t1].[OneToMany_Optional_Self_Inverse2Id] +WHERE ([l11].[Name] <> N'Foo') OR [l11].[Name] IS NULL +ORDER BY [l12].[Id], [l].[Id], [l0].[Id], [l1].[Id], [l2].[Id], [t].[Id], [t].[Id0], [t].[Id1], [t].[Id2], [t0].[Id], [t0].[Id0], [t0].[Id1], [t0].[Id2], [l11].[Id], [l13].[Id], [l14].[Id]"); + } + + public override async Task Filtered_include_basic_OrderBy_Skip_Take(bool async) + { + await base.Filtered_include_basic_OrderBy_Skip_Take(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Name]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE (1 < [t].[row]) AND ([t].[row] <= 4) +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Name]"); + } + + public override async Task Filtered_include_basic_OrderBy_Take(bool async) + { + await base.Filtered_include_basic_OrderBy_Take(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Name]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Name]"); + } + + public override async Task Filtered_include_context_accessed_inside_filter(bool async) + { + await base.Filtered_include_context_accessed_inside_filter(async); + + AssertSql( + @"SELECT COUNT(*) +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l]", + // + @"@__p_0='True' + +SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE @__p_0 = CAST(1 AS bit) + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) + { + await base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async); + + AssertSql( + @"@__p_0='30' + +SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[PeriodEnd], [t].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Id] +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [l0].[Id] AS [Id0], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd] AS [PeriodEnd0], [l0].[PeriodStart] AS [PeriodStart0] + FROM ( + SELECT TOP(40) [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ) AS [t1] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Id] = [l0].[Level2_Optional_Id] +) AS [t0] +ORDER BY [t].[Id], [t0].[Id]"); + } + + public override async Task Include_reference_and_collection_order_by(bool async) + { + await base.Include_reference_and_collection_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Id], [l0].[Id]"); + } + + public override async Task SelectMany_with_order_by_and_Include(bool async) + { + await base.SelectMany_with_order_by_and_Include(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l0].[Name], [l].[Id], [l0].[Id]"); + } + + public override async Task Filtered_include_same_filter_set_on_same_navigation_twice(bool async) + { + await base.Filtered_include_same_filter_set_on_same_navigation_twice(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id] DESC) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 2 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id] DESC"); + } + + public override async Task SelectMany_navigation_property_followed_by_select_collection_navigation(bool async) + { + await base.SelectMany_navigation_property_followed_by_select_collection_navigation(async); + + AssertSql( + @"SELECT [l0].[Id], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Orderby_SelectMany_with_Include1(bool async) + { + await base.Orderby_SelectMany_with_Include1(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Include_reference_collection_order_by_reference_navigation(bool async) + { + await base.Include_reference_collection_order_by_reference_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l0].[Id], [l].[Id]"); + } + + public override async Task Take_on_correlated_collection_in_projection(bool async) + { + await base.Take_on_correlated_collection_in_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE [t].[row] <= 50 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_complex_repeated(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex_repeated(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY -[l].[Level1_Required_Id], [l].[Name], [l].[Id]"); + } + + public override async Task Take_on_grouping_element(bool async) + { + await base.Take_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name] DESC) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE [t1].[row] <= 10 +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name] DESC"); + } + + public override async Task Select_subquery_single_nested_subquery(bool async) + { + await base.Select_subquery_single_nested_subquery(async); + + AssertSql( + @"SELECT [l].[Id], [t0].[Id], [t1].[Id], [t0].[c] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] +) AS [t1] ON [t0].[Id] = [t1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [t0].[Id], [t1].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_complex_repeated_checked(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex_repeated_checked(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY -[l].[Level1_Required_Id], [l].[Name], [l].[Id]"); + } + + public override async Task Filtered_include_Skip_without_OrderBy(bool async) + { + await base.Filtered_include_Skip_without_OrderBy(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t] + WHERE 1 < [t].[row] +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task Include_collection_and_another_navigation_chain_followed_by_projecting_the_first_collection(bool async) + { + await base.Include_collection_and_another_navigation_chain_followed_by_projecting_the_first_collection(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[Id1], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name1], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd1], [t].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l2].[Id] AS [Id1], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name1], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd1], [l2].[PeriodStart] AS [PeriodStart1] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0]"); + } + + public override async Task Filtered_include_after_different_filtered_include_same_level(bool async) + { + await base.Filtered_include_after_different_filtered_include_same_level(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Name]) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 3 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [t2].[Id], [t2].[Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Optional_Self_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToMany_Required_Self_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id], [t2].[OneToOne_Optional_Self2Id], [t2].[PeriodEnd], [t2].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l1].[OneToMany_Required_Inverse2Id] ORDER BY [l1].[Name] DESC) AS [row] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE ([l1].[Name] <> N'Bar') OR [l1].[Name] IS NULL + ) AS [t2] + WHERE 1 < [t2].[row] +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Name], [t0].[Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[Name] DESC"); + } + + public override async Task Skip_Take_on_grouping_element(bool async) + { + await base.Skip_Take_on_grouping_element(async); + + AssertSql( + @"SELECT [t].[Date], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT [l].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + GROUP BY [l].[Date] +) AS [t] +LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[Date] ORDER BY [l0].[Name]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) +) AS [t0] ON [t].[Date] = [t0].[Date] +ORDER BY [t].[Date], [t0].[Date], [t0].[Name]"); + } + + public override async Task Skip_Take_on_grouping_element_inside_collection_projection(bool async) + { + await base.Skip_Take_on_grouping_element_inside_collection_projection(async); + + AssertSql( + @"SELECT [l].[Id], [t2].[Date], [t2].[Id], [t2].[Date0], [t2].[Name], [t2].[OneToMany_Optional_Self_Inverse1Id], [t2].[OneToMany_Required_Self_Inverse1Id], [t2].[OneToOne_Optional_Self1Id], [t2].[PeriodEnd], [t2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [t].[Date], [t0].[Id], [t0].[Date] AS [Date0], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] + FROM ( + SELECT [l0].[Date] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + WHERE ([l0].[Name] = [l].[Name]) OR ([l0].[Name] IS NULL AND [l].[Name] IS NULL) + GROUP BY [l0].[Date] + ) AS [t] + LEFT JOIN ( + SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], [t1].[PeriodEnd], [t1].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [l1].[PeriodEnd], [l1].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l1].[Date] ORDER BY [l1].[Name]) AS [row] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE ([l1].[Name] = [l].[Name]) OR ([l1].[Name] IS NULL AND [l].[Name] IS NULL) + ) AS [t1] + WHERE (1 < [t1].[row]) AND ([t1].[row] <= 6) + ) AS [t0] ON [t].[Date] = [t0].[Date] +) AS [t2] +ORDER BY [l].[Id], [t2].[Date], [t2].[Date0], [t2].[Name]"); + } + + public override async Task Multiple_SelectMany_navigation_property_followed_by_select_collection_navigation(bool async) + { + await base.Multiple_SelectMany_navigation_property_followed_by_select_collection_navigation(async); + + AssertSql( + @"SELECT [l1].[Id], [l].[Id], [l0].[Id], [l2].[Id], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Include_collection_followed_by_include_reference(bool async) + { + await base.Include_collection_followed_by_include_reference(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Filtered_include_is_considered_loaded(bool async) + { + await base.Filtered_include_is_considered_loaded(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t0].[OneToMany_Optional_Inverse2Id], [t0].[Id]"); + } + + public override async Task SelectMany_with_Include1(bool async) + { + await base.SelectMany_with_Include1(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Including_reference_navigation_and_projecting_collection_navigation(bool async) + { + await base.Including_reference_navigation_and_projecting_collection_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l].[Id] = [l2].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Skip_Take_Select_collection_Skip_Take(bool async) + { + await base.Skip_Take_Select_collection_Skip_Take(async); + + AssertSql( + @"@__p_0='1' + +SELECT [t].[Id], [t].[Name], [t0].[Id], [t0].[Name], [t0].[Level1Id], [t0].[Level2Id], [t0].[Id0], [t0].[Date], [t0].[Name0], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[PeriodEnd], [t0].[PeriodStart] +FROM ( + SELECT [l].[Id], [l].[Name] + FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] + ORDER BY [l].[Id] + OFFSET @__p_0 ROWS FETCH NEXT @__p_0 ROWS ONLY +) AS [t] +OUTER APPLY ( + SELECT [t1].[Id], [t1].[Name], [t1].[OneToMany_Required_Inverse2Id] AS [Level1Id], [t1].[Level1_Required_Id] AS [Level2Id], [l0].[Id] AS [Id0], [l0].[Date], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM ( + SELECT [l1].[Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Required_Inverse2Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + WHERE [t].[Id] = [l1].[OneToMany_Required_Inverse2Id] + ORDER BY [l1].[Id] + OFFSET 1 ROWS FETCH NEXT 3 ROWS ONLY + ) AS [t1] + INNER JOIN [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t1].[Level1_Required_Id] = [l0].[Id] +) AS [t0] +ORDER BY [t].[Id], [t0].[Id]"); + } + + public override async Task Optional_navigation_with_Include_ThenInclude(bool async) + { + await base.Optional_navigation_with_Include_ThenInclude(async); + + AssertSql( + @"SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l].[Id], [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd0], [t].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id] AS [Id0], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name0], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd0], [l2].[PeriodStart] AS [PeriodStart0] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Optional_Id] +) AS [t] ON [l0].[Id] = [t].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [t].[Id]"); + } + + public override async Task Include_reference_followed_by_include_collection(bool async) + { + await base.Include_reference_followed_by_include_collection(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Include_collection_ThenInclude_two_references(bool async) + { + await base.Include_collection_ThenInclude_two_references(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[Id1], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name1], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd1], [t].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l2].[Id] AS [Id1], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name1], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd1], [l2].[PeriodStart] AS [PeriodStart1] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0]"); + } + + public override async Task Filtered_include_outer_parameter_used_inside_filter(bool async) + { + await base.Filtered_include_outer_parameter_used_inside_filter(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +) AS [t] +OUTER APPLY ( + SELECT [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart], [t1].[Id] AS [Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Name] AS [Name0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Optional_Self_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToMany_Required_Self_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToOne_Optional_Self3Id], [t1].[PeriodEnd] AS [PeriodEnd0], [t1].[PeriodStart] AS [PeriodStart0] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd], [l3].[PeriodStart] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + WHERE [l3].[Id] <> [l].[Id] + ) AS [t1] ON [l2].[Id] = [t1].[OneToMany_Optional_Inverse3Id] +) AS [t0] +ORDER BY [l].[Id], [t].[Id], [t].[Id0], [t0].[Id]"); + } + + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(bool async) + { + await base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t0].[Id], [t0].[Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Optional_Self_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToMany_Required_Self_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id], [t0].[OneToOne_Optional_Self2Id], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[Id0], [t0].[Id1], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd0], [t0].[PeriodStart0], [t0].[Level2_Optional_Id0], [t0].[Level2_Required_Id0], [t0].[Name1], [t0].[OneToMany_Optional_Inverse3Id0], [t0].[OneToMany_Optional_Self_Inverse3Id0], [t0].[OneToMany_Required_Inverse3Id0], [t0].[OneToMany_Required_Self_Inverse3Id0], [t0].[OneToOne_Optional_PK_Inverse3Id0], [t0].[OneToOne_Optional_Self3Id0], [t0].[PeriodEnd1], [t0].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +OUTER APPLY ( + SELECT [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[PeriodEnd], [t].[PeriodStart], [l0].[Id] AS [Id0], [l1].[Id] AS [Id1], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l0].[Level2_Optional_Id] AS [Level2_Optional_Id0], [l0].[Level2_Required_Id] AS [Level2_Required_Id0], [l0].[Name] AS [Name1], [l0].[OneToMany_Optional_Inverse3Id] AS [OneToMany_Optional_Inverse3Id0], [l0].[OneToMany_Optional_Self_Inverse3Id] AS [OneToMany_Optional_Self_Inverse3Id0], [l0].[OneToMany_Required_Inverse3Id] AS [OneToMany_Required_Inverse3Id0], [l0].[OneToMany_Required_Self_Inverse3Id] AS [OneToMany_Required_Self_Inverse3Id0], [l0].[OneToOne_Optional_PK_Inverse3Id] AS [OneToOne_Optional_PK_Inverse3Id0], [l0].[OneToOne_Optional_Self3Id] AS [OneToOne_Optional_Self3Id0], [l0].[PeriodEnd] AS [PeriodEnd1], [l0].[PeriodStart] AS [PeriodStart1] + FROM ( + SELECT TOP(2) [l2].[Id], [l2].[Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Name], [l2].[OneToMany_Optional_Inverse2Id], [l2].[OneToMany_Optional_Self_Inverse2Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Required_Self_Inverse2Id], [l2].[OneToOne_Optional_PK_Inverse2Id], [l2].[OneToOne_Optional_Self2Id], [l2].[PeriodEnd], [l2].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] + WHERE ([l].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND (([l2].[Name] <> N'Foo') OR [l2].[Name] IS NULL) + ORDER BY [l2].[Id] + ) AS [t] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [t].[Id] = [l0].[Level2_Required_Id] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +) AS [t0] +ORDER BY [l].[Id], [t0].[Id], [t0].[Id0]"); + } + + public override async Task Project_collection_and_include(bool async) + { + await base.Project_collection_and_include(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task SelectMany_with_navigation_and_Distinct(bool async) + { + await base.SelectMany_with_navigation_and_Distinct(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t].[Id], [l1].[Id], [l1].[Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +INNER JOIN ( + SELECT DISTINCT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id]"); + } + + public override async Task Select_nav_prop_collection_one_to_many_required(bool async) + { + await base.Select_nav_prop_collection_one_to_many_required(async); + + AssertSql( + @"SELECT [l].[Id], [l0].[Id] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id]"); + } + + public override async Task Include_ThenInclude_ThenInclude_followed_by_two_nested_selects(bool async) + { + await base.Include_ThenInclude_ThenInclude_followed_by_two_nested_selects(async); + + AssertSql( + @"SELECT [l].[Id], [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart], [t].[Id0], [t].[Level3_Optional_Id], [t].[Level3_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse4Id], [t].[OneToMany_Optional_Self_Inverse4Id], [t].[OneToMany_Required_Inverse4Id], [t].[OneToMany_Required_Self_Inverse4Id], [t].[OneToOne_Optional_PK_Inverse4Id], [t].[OneToOne_Optional_Self4Id], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[Id1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart], [l2].[Id] AS [Id0], [l2].[Level3_Optional_Id], [l2].[Level3_Required_Id], [l2].[Name] AS [Name0], [l2].[OneToMany_Optional_Inverse4Id], [l2].[OneToMany_Optional_Self_Inverse4Id], [l2].[OneToMany_Required_Inverse4Id], [l2].[OneToMany_Required_Self_Inverse4Id], [l2].[OneToOne_Optional_PK_Inverse4Id], [l2].[OneToOne_Optional_Self4Id], [l2].[PeriodEnd] AS [PeriodEnd0], [l2].[PeriodStart] AS [PeriodStart0], [l0].[Id] AS [Id1], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [l1].[Id] = [l2].[Level3_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id1], [t].[Id]"); + } + + public override async Task Include_collection_with_multiple_orderbys_complex(bool async) + { + await base.Include_collection_with_multiple_orderbys_complex(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Optional_Self_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToMany_Required_Self_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[OneToOne_Optional_Self2Id], [l].[PeriodEnd], [l].[PeriodStart], [l0].[Id], [l0].[Level2_Optional_Id], [l0].[Level2_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse3Id], [l0].[OneToMany_Optional_Self_Inverse3Id], [l0].[OneToMany_Required_Inverse3Id], [l0].[OneToMany_Required_Self_Inverse3Id], [l0].[OneToOne_Optional_PK_Inverse3Id], [l0].[OneToOne_Optional_Self3Id], [l0].[PeriodEnd], [l0].[PeriodStart] +FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +ORDER BY ABS([l].[Level1_Required_Id]) + 7, [l].[Name], [l].[Id]"); + } + + public override async Task LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(bool async) + { + await base.LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(async); + + AssertSql( + @"SELECT CASE + WHEN [l0].[Id] IS NULL THEN 0 + ELSE [l0].[Id] +END, [l].[Id], [l0].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id], [l1].[PeriodEnd], [l1].[PeriodStart] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [l0].[Id] = [l1].[OneToMany_Required_Inverse3Id] +WHERE [l].[Name] IN (N'L1 01', N'L1 02') +ORDER BY [l].[Id], [l0].[Id]"); + } + + public override async Task Filtered_include_complex_three_level_with_middle_having_filter1(bool async) + { + await base.Filtered_include_complex_three_level_with_middle_having_filter1(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l].[PeriodEnd], [l].[PeriodStart], [t1].[Id], [t1].[Date], [t1].[Level1_Optional_Id], [t1].[Level1_Required_Id], [t1].[Name], [t1].[OneToMany_Optional_Inverse2Id], [t1].[OneToMany_Optional_Self_Inverse2Id], [t1].[OneToMany_Required_Inverse2Id], [t1].[OneToMany_Required_Self_Inverse2Id], [t1].[OneToOne_Optional_PK_Inverse2Id], [t1].[OneToOne_Optional_Self2Id], [t1].[PeriodEnd], [t1].[PeriodStart], [t1].[Id0], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Name0], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Optional_Self_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToMany_Required_Self_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t1].[OneToOne_Optional_Self3Id], [t1].[PeriodEnd0], [t1].[PeriodStart0], [t1].[Id00], [t1].[Level3_Optional_Id], [t1].[Level3_Required_Id], [t1].[Name00], [t1].[OneToMany_Optional_Inverse4Id], [t1].[OneToMany_Optional_Self_Inverse4Id], [t1].[OneToMany_Required_Inverse4Id], [t1].[OneToMany_Required_Self_Inverse4Id], [t1].[OneToOne_Optional_PK_Inverse4Id], [t1].[OneToOne_Optional_Self4Id], [t1].[PeriodEnd00], [t1].[PeriodStart00], [t1].[Id1], [t1].[Level3_Optional_Id0], [t1].[Level3_Required_Id0], [t1].[Name1], [t1].[OneToMany_Optional_Inverse4Id0], [t1].[OneToMany_Optional_Self_Inverse4Id0], [t1].[OneToMany_Required_Inverse4Id0], [t1].[OneToMany_Required_Self_Inverse4Id0], [t1].[OneToOne_Optional_PK_Inverse4Id0], [t1].[OneToOne_Optional_Self4Id0], [t1].[PeriodEnd1], [t1].[PeriodStart1] +FROM [LevelOne] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l0].[PeriodEnd], [l0].[PeriodStart], [t0].[Id] AS [Id0], [t0].[Level2_Optional_Id], [t0].[Level2_Required_Id], [t0].[Name] AS [Name0], [t0].[OneToMany_Optional_Inverse3Id], [t0].[OneToMany_Optional_Self_Inverse3Id], [t0].[OneToMany_Required_Inverse3Id], [t0].[OneToMany_Required_Self_Inverse3Id], [t0].[OneToOne_Optional_PK_Inverse3Id], [t0].[OneToOne_Optional_Self3Id], [t0].[PeriodEnd] AS [PeriodEnd0], [t0].[PeriodStart] AS [PeriodStart0], [t0].[Id0] AS [Id00], [t0].[Level3_Optional_Id], [t0].[Level3_Required_Id], [t0].[Name0] AS [Name00], [t0].[OneToMany_Optional_Inverse4Id], [t0].[OneToMany_Optional_Self_Inverse4Id], [t0].[OneToMany_Required_Inverse4Id], [t0].[OneToMany_Required_Self_Inverse4Id], [t0].[OneToOne_Optional_PK_Inverse4Id], [t0].[OneToOne_Optional_Self4Id], [t0].[PeriodEnd0] AS [PeriodEnd00], [t0].[PeriodStart0] AS [PeriodStart00], [t0].[Id1], [t0].[Level3_Optional_Id0], [t0].[Level3_Required_Id0], [t0].[Name1], [t0].[OneToMany_Optional_Inverse4Id0], [t0].[OneToMany_Optional_Self_Inverse4Id0], [t0].[OneToMany_Required_Inverse4Id0], [t0].[OneToMany_Required_Self_Inverse4Id0], [t0].[OneToOne_Optional_PK_Inverse4Id0], [t0].[OneToOne_Optional_Self4Id0], [t0].[PeriodEnd1], [t0].[PeriodStart1] + FROM [LevelTwo] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l0] + OUTER APPLY ( + SELECT [t].[Id], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id], [t].[PeriodEnd], [t].[PeriodStart], [l1].[Id] AS [Id0], [l1].[Level3_Optional_Id], [l1].[Level3_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse4Id], [l1].[OneToMany_Optional_Self_Inverse4Id], [l1].[OneToMany_Required_Inverse4Id], [l1].[OneToMany_Required_Self_Inverse4Id], [l1].[OneToOne_Optional_PK_Inverse4Id], [l1].[OneToOne_Optional_Self4Id], [l1].[PeriodEnd] AS [PeriodEnd0], [l1].[PeriodStart] AS [PeriodStart0], [l2].[Id] AS [Id1], [l2].[Level3_Optional_Id] AS [Level3_Optional_Id0], [l2].[Level3_Required_Id] AS [Level3_Required_Id0], [l2].[Name] AS [Name1], [l2].[OneToMany_Optional_Inverse4Id] AS [OneToMany_Optional_Inverse4Id0], [l2].[OneToMany_Optional_Self_Inverse4Id] AS [OneToMany_Optional_Self_Inverse4Id0], [l2].[OneToMany_Required_Inverse4Id] AS [OneToMany_Required_Inverse4Id0], [l2].[OneToMany_Required_Self_Inverse4Id] AS [OneToMany_Required_Self_Inverse4Id0], [l2].[OneToOne_Optional_PK_Inverse4Id] AS [OneToOne_Optional_PK_Inverse4Id0], [l2].[OneToOne_Optional_Self4Id] AS [OneToOne_Optional_Self4Id0], [l2].[PeriodEnd] AS [PeriodEnd1], [l2].[PeriodStart] AS [PeriodStart1] + FROM ( + SELECT TOP(1) [l3].[Id], [l3].[Level2_Optional_Id], [l3].[Level2_Required_Id], [l3].[Name], [l3].[OneToMany_Optional_Inverse3Id], [l3].[OneToMany_Optional_Self_Inverse3Id], [l3].[OneToMany_Required_Inverse3Id], [l3].[OneToMany_Required_Self_Inverse3Id], [l3].[OneToOne_Optional_PK_Inverse3Id], [l3].[OneToOne_Optional_Self3Id], [l3].[PeriodEnd], [l3].[PeriodStart] + FROM [LevelThree] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l3] + WHERE ([l0].[Id] = [l3].[OneToMany_Optional_Inverse3Id]) AND (([l3].[Name] <> N'Foo') OR [l3].[Name] IS NULL) + ORDER BY [l3].[Id] + ) AS [t] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l1] ON [t].[Id] = [l1].[OneToMany_Optional_Inverse4Id] + LEFT JOIN [LevelFour] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [l2] ON [t].[Id] = [l2].[OneToMany_Required_Inverse4Id] + ) AS [t0] +) AS [t1] ON [l].[Id] = [t1].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t1].[Id], [t1].[Id0], [t1].[Id00]"); + } + + public override async Task SelectMany_over_conditional_null_source(bool async) + { + await base.SelectMany_over_conditional_null_source(async); + + AssertSql(); + } + + public override async Task SelectMany_over_conditional_empty_source(bool async) + { + await base.SelectMany_over_conditional_empty_source(async); + + AssertSql(); + } + + public override async Task Include_after_Select(bool async) + { + await base.Include_after_Select(async); + + AssertSql(); + } + + public override async Task Include_after_SelectMany_and_reference_navigation(bool async) + { + await base.Include_after_SelectMany_and_reference_navigation(async); + + AssertSql(); + } + + public override async Task Filtered_include_different_filter_set_on_same_navigation_twice(bool async) + { + await base.Filtered_include_different_filter_set_on_same_navigation_twice(async); + + AssertSql(); + } + + public override async Task Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(bool async) + { + await base.Filtered_include_different_filter_set_on_same_navigation_twice_multi_level(async); + + AssertSql(); + } + + public override async Task Filtered_include_include_parameter_used_inside_filter_throws(bool async) + { + await base.Filtered_include_include_parameter_used_inside_filter_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_with_Distinct_throws(bool async) + { + await base.Filtered_include_with_Distinct_throws(async); + + AssertSql(); + } + + public override async Task Filtered_include_calling_methods_directly_on_parameter_throws(bool async) + { + await base.Filtered_include_calling_methods_directly_on_parameter_throws(async); + + AssertSql(); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqliteTest.cs index d27f1632862..b9fd0465f5a 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsQuerySqliteTest.cs @@ -8,18 +8,26 @@ namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsQuerySqliteTest : ComplexNavigationsCollectionsQueryRelationalTestBase + public class ComplexNavigationsCollectionsQuerySqliteTest + : ComplexNavigationsCollectionsQueryRelationalTestBase { public ComplexNavigationsCollectionsQuerySqliteTest(ComplexNavigationsQuerySqliteFixture fixture) : base(fixture) { } + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async))) + .Message); + public override async Task Include_inside_subquery(bool async) - => Assert.Equal( - SqliteStrings.ApplyNotSupported, - (await Assert.ThrowsAsync( - () => base.Include_inside_subquery(async))).Message); + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Include_inside_subquery(async))).Message); public override async Task Filtered_include_after_different_filtered_include_different_level(bool async) => Assert.Equal( @@ -39,12 +47,15 @@ public override async Task Filtered_include_and_non_filtered_include_followed_by (await Assert.ThrowsAsync( () => base.Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(async))).Message); - public override async Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( - bool async) + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async))).Message); + () => base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + async))).Message); public override async Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) => Assert.Equal( @@ -118,23 +129,30 @@ public override async Task Skip_Take_on_grouping_element_with_reference_include( (await Assert.ThrowsAsync( () => base.Skip_Take_on_grouping_element_with_reference_include(async))).Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))) + .Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))) + .Message); - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))).Message); + () => base + .SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))) + .Message); public override async Task Complex_query_issue_21665(bool async) => Assert.Equal( diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqliteTest.cs index c653c83267e..8ed89ba332a 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqliteTest.cs @@ -9,14 +9,23 @@ namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSharedTypeQuerySqliteTest : ComplexNavigationsCollectionsSharedTypeQueryRelationalTestBase< - ComplexNavigationsSharedTypeQuerySqliteFixture> + public class ComplexNavigationsCollectionsSharedTypeQuerySqliteTest + : ComplexNavigationsCollectionsSharedTypeQueryRelationalTestBase { - public ComplexNavigationsCollectionsSharedTypeQuerySqliteTest(ComplexNavigationsSharedTypeQuerySqliteFixture fixture, ITestOutputHelper testOutputHelper) + public ComplexNavigationsCollectionsSharedTypeQuerySqliteTest( + ComplexNavigationsSharedTypeQuerySqliteFixture fixture, + ITestOutputHelper testOutputHelper) : base(fixture) { } + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async))) + .Message); + public override async Task Filtered_include_after_different_filtered_include_different_level(bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, @@ -35,12 +44,15 @@ public override async Task Filtered_include_complex_three_level_with_middle_havi (await Assert.ThrowsAsync( () => base.Filtered_include_complex_three_level_with_middle_having_filter1(async))).Message); - public override async Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( - bool async) + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async))).Message); + () => base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + async))).Message); public override async Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) => Assert.Equal( @@ -108,22 +120,29 @@ public override async Task Skip_Take_on_grouping_element_with_reference_include( (await Assert.ThrowsAsync( () => base.Skip_Take_on_grouping_element_with_reference_include(async))).Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))) + .Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))) + .Message); - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))).Message); + () => base + .SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))) + .Message); } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqliteTest.cs index 275c2621a3b..15c61500b66 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitQuerySqliteTest.cs @@ -8,18 +8,26 @@ namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSplitQuerySqliteTest : ComplexNavigationsCollectionsSplitQueryRelationalTestBase + public class ComplexNavigationsCollectionsSplitQuerySqliteTest + : ComplexNavigationsCollectionsSplitQueryRelationalTestBase { public ComplexNavigationsCollectionsSplitQuerySqliteTest(ComplexNavigationsQuerySqliteFixture fixture) : base(fixture) { } + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async))) + .Message); + public override async Task Include_inside_subquery(bool async) - => Assert.Equal( - SqliteStrings.ApplyNotSupported, - (await Assert.ThrowsAsync( - () => base.Include_inside_subquery(async))).Message); + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Include_inside_subquery(async))).Message); public override async Task Filtered_include_outer_parameter_used_inside_filter(bool async) => Assert.Equal( @@ -33,12 +41,15 @@ public override async Task Filtered_include_and_non_filtered_include_followed_by (await Assert.ThrowsAsync( () => base.Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(async))).Message); - public override async Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( - bool async) + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async))).Message); + () => base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + async))).Message); public override async Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) => Assert.Equal( @@ -94,23 +105,30 @@ public override async Task Skip_Take_on_grouping_element_with_reference_include( (await Assert.ThrowsAsync( () => base.Skip_Take_on_grouping_element_with_reference_include(async))).Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))) + .Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))) + .Message); - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))).Message); + () => base + .SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))) + .Message); public override async Task Complex_query_issue_21665(bool async) => Assert.Equal( diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest.cs index b8368fed206..a3e92d2c8ef 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest.cs @@ -9,26 +9,38 @@ namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest : ComplexNavigationsCollectionsSplitSharedTypeQueryRelationalTestBase< - ComplexNavigationsSharedTypeQuerySqliteFixture> + public class ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest + : ComplexNavigationsCollectionsSplitSharedTypeQueryRelationalTestBase { - public ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest(ComplexNavigationsSharedTypeQuerySqliteFixture fixture, ITestOutputHelper testOutputHelper) + public ComplexNavigationsCollectionsSplitSharedTypeQuerySqliteTest( + ComplexNavigationsSharedTypeQuerySqliteFixture fixture, + ITestOutputHelper testOutputHelper) : base(fixture) { } + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(async))) + .Message); + public override async Task Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(async))).Message); - public override async Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( - bool async) + public override async Task + Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(async))).Message); + () => base + .Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only( + async))).Message); public override async Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) => Assert.Equal( @@ -84,22 +96,29 @@ public override async Task Skip_Take_on_grouping_element_with_reference_include( (await Assert.ThrowsAsync( () => base.Skip_Take_on_grouping_element_with_reference_include(async))).Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_FirstOrDefault_on_top_level(async))) + .Message); - public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(bool async) + public override async Task Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))).Message); + () => base.Filtered_include_with_Take_without_order_by_followed_by_ThenInclude_and_unordered_Take_on_top_level(async))) + .Message); - public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(bool async) + public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection( + bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( - () => base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))).Message); + () => base + .SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))) + .Message); } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs index 130a0fb0106..d86a1741bce 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Sqlite.Internal; using Xunit; @@ -26,5 +27,24 @@ public override async Task Prune_does_not_throw_null_ref(bool async) SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Prune_does_not_throw_null_ref(async))).Message); + + public override async Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Join_with_result_selector_returning_queryable_throws_validation_error(async))).Message); + + public override async Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async))).Message); + + public override Task GroupJoin_client_method_in_OrderBy(bool async) + => AssertTranslationFailedWithDetails( + () => base.GroupJoin_client_method_in_OrderBy(async), + CoreStrings.QueryUnableToTranslateMethod( + "Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase", + "ClientMethodNullableInt")); } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqliteTest.cs index 56c6b9a0459..8f6f40ac43b 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqliteTest.cs @@ -3,20 +3,42 @@ using System; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Sqlite.Internal; using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query { - public class ComplexNavigationsSharedTypeQuerySqliteTest : ComplexNavigationsSharedTypeQueryRelationalTestBase< - ComplexNavigationsSharedTypeQuerySqliteFixture> + public class ComplexNavigationsSharedTypeQuerySqliteTest : + ComplexNavigationsSharedTypeQueryRelationalTestBase { - public ComplexNavigationsSharedTypeQuerySqliteTest(ComplexNavigationsSharedTypeQuerySqliteFixture fixture, ITestOutputHelper testOutputHelper) + public ComplexNavigationsSharedTypeQuerySqliteTest( + ComplexNavigationsSharedTypeQuerySqliteFixture fixture, + ITestOutputHelper testOutputHelper) : base(fixture) { } + public override Task GroupJoin_client_method_in_OrderBy(bool async) + => AssertTranslationFailedWithDetails( + () => base.GroupJoin_client_method_in_OrderBy(async), + CoreStrings.QueryUnableToTranslateMethod( + "Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase", + "ClientMethodNullableInt")); + + public override async Task Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Nested_SelectMany_correlated_with_join_table_correctly_translated_to_apply(async))).Message); + + public override async Task Join_with_result_selector_returning_queryable_throws_validation_error(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Join_with_result_selector_returning_queryable_throws_validation_error(async))).Message); + public override async Task Let_let_contains_from_outer_let(bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported,