diff --git a/src/EFCore.SqlServer/Infrastructure/Internal/SqlServerOptionsExtension.cs b/src/EFCore.SqlServer/Infrastructure/Internal/SqlServerOptionsExtension.cs index 50e26c4e6a0..ccf3d1961b9 100644 --- a/src/EFCore.SqlServer/Infrastructure/Internal/SqlServerOptionsExtension.cs +++ b/src/EFCore.SqlServer/Infrastructure/Internal/SqlServerOptionsExtension.cs @@ -29,7 +29,7 @@ public class SqlServerOptionsExtension : RelationalOptionsExtension, IDbContextO // SQL Server 2017 (14.x): compatibility level 140, start date 2017-09-29, mainstream end date 2022-10-11, extended end date 2027-10-12 // SQL Server 2016 (13.x): compatibility level 130, start date 2016-06-01, mainstream end date 2021-07-13, extended end date 2026-07-14 // SQL Server 2014 (12.x): compatibility level 120, start date 2014-06-05, mainstream end date 2019-07-09, extended end date 2024-07-09 - public static readonly int DefaultCompatibilityLevel = 160; + public static readonly int DefaultCompatibilityLevel = 150; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs b/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs index 3a4345aa804..c3f74d0bd91 100644 --- a/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs +++ b/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs @@ -106,7 +106,7 @@ public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure( /// /// Sets the SQL Server compatibility level that EF Core will use when interacting with the database. This allows configuring EF - /// Core to work with older (or newer) versions of SQL Server. Defaults to 160 (SQL Server 2022). + /// Core to work with older (or newer) versions of SQL Server. Defaults to 150 (SQL Server 2019). /// /// /// See Using DbContextOptions, and diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServer160Test.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServer160Test.cs new file mode 100644 index 00000000000..ee806b4e0ab --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServer160Test.cs @@ -0,0 +1,4909 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; +using Xunit.Sdk; + +namespace Microsoft.EntityFrameworkCore.Query; + +[SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] +public class ComplexNavigationsQuerySqlServer160Test + : ComplexNavigationsQueryRelationalTestBase +{ + public ComplexNavigationsQuerySqlServer160Test(Fixture160 fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_skip_without_orderby(bool async) + { + await 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); + + AssertSql( + """ +SELECT ( + SELECT TOP(1) [l2].[Name] + FROM ( + SELECT [l1].[Id], [l1].[Name] + FROM ( + SELECT DISTINCT [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 [LevelThree] AS [l0] + ) AS [l1] + ORDER BY (SELECT 1) + OFFSET 1 ROWS + ) AS [l2] + ORDER BY [l2].[Id]) +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_take_without_orderby(bool async) + { + await 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); + + AssertSql( + """ +SELECT ( + SELECT TOP(1) [l1].[Name] + FROM ( + SELECT DISTINCT TOP(1) [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 [LevelThree] AS [l0] + ) AS [l1] + ORDER BY [l1].[Id]) +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + public override async Task Entity_equality_empty(bool async) + { + await base.Entity_equality_empty(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] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Id] = 0 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Id] = 0 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Id] > 7 +"""); + } + + public override async Task Key_equality_using_property_method_required2(bool async) + { + await base.Key_equality_using_property_method_required2(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] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +WHERE [l0].[Id] > 7 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Id] = 7 +"""); + } + + public override async Task Key_equality_using_property_method_nested2(bool async) + { + await base.Key_equality_using_property_method_nested2(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] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +WHERE [l0].[Id] = 7 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Id] = 7 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Id] = 7 +"""); + } + + 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 [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] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +WHERE [l0].[Id] = 7 +"""); + } + + public override async Task Key_equality_navigation_converted_to_FK(bool async) + { + await base.Key_equality_navigation_converted_to_FK(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] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +WHERE [l0].[Id] = 1 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Id] IN (1, 2) +"""); + } + + 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 [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] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +WHERE [l0].[Id] IN (1, 2) +"""); + } + + 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], [s].[Text], [s].[ComplexNavigationStringDefaultText], [s].[LanguageName], [s].[Name], [s].[CultureString], [s0].[Text], [s0].[ComplexNavigationStringDefaultText], [s0].[LanguageName], [s0].[Name], [s0].[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 [s] ON [m].[DefaultText] = [s].[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 [s0] ON [m0].[DefaultText] = [s0].[ComplexNavigationStringDefaultText] +ORDER BY [f].[Name], [m].[DefaultText], [m0].[DefaultText], [s].[Text], [s].[Name], [s0].[Text] +"""); + } + + 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], [s].[Id] AS [Id2] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Optional_Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[Id0] +"""); + } + + 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], [s].[Id] AS [Id2] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[Id0] +"""); + } + + public override async Task Navigation_key_access_optional_comparison(bool async) + { + await base.Navigation_key_access_optional_comparison(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelOne] AS [l0] ON [l].[OneToOne_Optional_PK_Inverse2Id] = [l0].[Id] +WHERE [l0].[Id] > 5 +"""); + } + + public override async Task Navigation_key_access_required_comparison(bool async) + { + await base.Navigation_key_access_required_comparison(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Id] = [l0].[Id] +WHERE [l0].[Id] > 5 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Name] LIKE N'L%' +"""); + } + + 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 [l].[Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Optional_Self_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToMany_Required_Self_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[OneToOne_Optional_Self3Id] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +WHERE [l0].[Name] LIKE N'L%' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] LIKE N'L%' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] = N'L2 01' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE UPPER([l0].[Name]) LIKE N'L%' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] IS NOT NULL AND LEFT([l0].[Name], LEN([l0].[Name])) = [l0].[Name] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE DATEADD(day, CAST(10.0E0 AS int), [l0].[Date]) > '2000-02-01T00:00:00.0000000' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE DATEADD(month, CAST(2 AS int), DATEADD(day, CAST(15.0E0 AS int), DATEADD(day, CAST(10.0E0 AS int), [l0].[Date]))) > '2002-02-01T00:00:00.0000000' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE DATEADD(day, CAST(CAST([l0].[Id] AS float) AS int), DATEADD(day, CAST(15.0E0 AS int), [l0].[Date])) > '2002-02-01T00:00:00.0000000' +"""); + } + + 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], [l1].[Id] AS [Id2] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +INNER JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Id] +"""); + } + + 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], [l2].[Id] AS [Id3] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +INNER JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Id] +"""); + } + + 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 [l].[Id] AS [Id3], [l2].[Id] AS [Id1] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Optional_Id] = [l1].[Id] +INNER JOIN [LevelOne] AS [l2] ON [l1].[Id] = [l2].[Id] +"""); + } + + public override async Task Join_navigation_in_inner_selector(bool async) + { + await base.Join_navigation_in_inner_selector(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id2], [s].[Id] AS [Id1] +FROM [LevelTwo] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Id] = [s].[Id0] +"""); + } + + 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 [l].[Id] AS [Id2], [s].[Id] AS [Id1], [s0].[Id] AS [Id3] +FROM [LevelTwo] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Id] = [s].[Id0] +INNER JOIN ( + SELECT [l2].[Id], [l3].[Id] AS [Id0] + FROM [LevelThree] AS [l2] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Level2_Optional_Id] = [l3].[Id] +) AS [s0] ON [l].[Id] = [s0].[Id0] +"""); + } + + public override async Task Join_navigation_non_key_join(bool async) + { + await base.Join_navigation_non_key_join(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id2], [l].[Name] AS [Name2], [s].[Id] AS [Id1], [s].[Name] AS [Name1] +FROM [LevelTwo] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Name], [l1].[Name] AS [Name0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Name] = [s].[Name0] +"""); + } + + 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 [l].[Id] AS [Id2], [l].[Name] AS [Name2], [s].[Id] AS [Id1], [s].[Name] AS [Name1] +FROM [LevelTwo] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Name], [l1].[Name] AS [Name0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Name] = [s].[Name0] +"""); + } + + public override async Task Join_navigation_self_ref(bool async) + { + await base.Join_navigation_self_ref(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id1], [s].[Id] AS [Id2] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelOne] AS [l1] ON [l0].[OneToMany_Optional_Self_Inverse1Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[Id0] +"""); + } + + public override async Task Join_navigation_nested(bool async) + { + await base.Join_navigation_nested(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id3], [s].[Id] AS [Id1] +FROM [LevelThree] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l2].[Id] AS [Id1] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Required_Id] + LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Level2_Optional_Id] +) AS [s] ON [l].[Id] = [s].[Id1] +"""); + } + + public override async Task Join_navigation_nested2(bool async) + { + await base.Join_navigation_nested2(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id3], [s].[Id] AS [Id1] +FROM [LevelThree] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l2].[Id] AS [Id1] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Required_Id] + LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Level2_Optional_Id] +) AS [s] ON [l].[Id] = [s].[Id1] +"""); + } + + 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 [l].[Id] AS [Id4], [l].[Name] AS [Name4], [s].[Id] AS [Id1], [s].[Name] AS [Name1] +FROM [LevelFour] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Name], [l3].[Name] AS [Name2] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Required_Id] + LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Level2_Optional_Id] + LEFT JOIN [LevelFour] AS [l3] ON [l2].[Id] = [l3].[Id] +) AS [s] ON [l].[Name] = [s].[Name2] +"""); + } + + public override async Task Join_navigation_deeply_nested_required(bool async) + { + await base.Join_navigation_deeply_nested_required(async); + + AssertSql( + """ +SELECT [s].[Id] AS [Id4], [s].[Name] AS [Name4], [l].[Id] AS [Id1], [l].[Name] AS [Name1] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Name], [l3].[Name] AS [Name2] + FROM [LevelFour] AS [l0] + INNER JOIN [LevelThree] AS [l1] ON [l0].[Level3_Required_Id] = [l1].[Id] + INNER JOIN [LevelTwo] AS [l2] ON [l1].[Level2_Required_Id] = [l2].[Id] + INNER JOIN [LevelOne] AS [l3] ON [l2].[Id] = [l3].[Id] +) AS [s] ON [l].[Name] = [s].[Name2] +"""); + } + + 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], [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].[Level1_Optional_Id] +"""); + } + + public override async Task Select_nav_prop_reference_optional1(bool async) + { + await base.Select_nav_prop_reference_optional1(async); + + AssertSql( + """ +SELECT [l0].[Name] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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 [l0].[Name] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + public override async Task Select_nav_prop_reference_optional2(bool async) + { + await base.Select_nav_prop_reference_optional2(async); + + AssertSql( + """ +SELECT [l0].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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 [l0].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + public override async Task Select_nav_prop_reference_optional3(bool async) + { + await base.Select_nav_prop_reference_optional3(async); + + AssertSql( + """ +SELECT [l0].[Name] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelOne] AS [l0] ON [l].[Level1_Optional_Id] = [l0].[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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] IN (N'L2 05', N'L2 07') +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l0].[Name] = N'L2 05' OR [l1].[Name] = N'L2 07' +"""); + } + + public override async Task Where_nav_prop_reference_optional2(bool async) + { + await base.Where_nav_prop_reference_optional2(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] = N'L2 05' OR [l0].[Name] <> N'L2 42' OR [l0].[Name] 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l0].[Name] = N'L2 05' OR [l1].[Name] <> N'L2 42' OR [l1].[Name] IS NULL +"""); + } + + public override async Task Select_multiple_nav_prop_reference_optional(bool async) + { + await base.Select_multiple_nav_prop_reference_optional(async); + + AssertSql( + """ +SELECT [l1].[Id] +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].[Level2_Optional_Id] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Optional_Id] +WHERE [l1].[Name] <> N'L3 05' OR [l1].[Name] IS NULL +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Optional_Id] +WHERE [l1].[Name] 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Optional_Id] +WHERE [l1].[Id] IS NULL +"""); + } + + 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 [l].[Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Optional_Self_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToMany_Required_Self_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[OneToOne_Optional_Self3Id] +FROM [LevelThree] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Level2_Optional_Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Optional_Id] = [l1].[Id] +WHERE [l1].[Id] IS NULL +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Optional_Id] +WHERE [l1].[Id] IS NOT 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 [l].[Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Optional_Self_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToMany_Required_Self_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[OneToOne_Optional_Self3Id] +FROM [LevelThree] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Level2_Optional_Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Optional_Id] = [l1].[Id] +WHERE [l1].[Id] IS NOT 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Required_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +WHERE [l2].[Id] IS NULL +"""); + } + + public override async Task Select_multiple_nav_prop_reference_required(bool async) + { + await base.Select_multiple_nav_prop_reference_required(async); + + AssertSql( + """ +SELECT [l1].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +"""); + } + + public override async Task Select_multiple_nav_prop_reference_required2(bool async) + { + await base.Select_multiple_nav_prop_reference_required2(async); + + AssertSql( + """ +SELECT [l1].[Id] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +"""); + } + + public override async Task Select_multiple_nav_prop_optional_required(bool async) + { + await base.Select_multiple_nav_prop_optional_required(async); + + AssertSql( + """ +SELECT [l1].[Id] +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].[Level2_Required_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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Required_Id] +WHERE [l1].[Name] <> N'L3 05' OR [l1].[Name] IS NULL +"""); + } + + 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 [LevelOne] AS [l] +CROSS JOIN [LevelOne] AS [l0] +WHERE [l].[Id] = [l0].[Id] +"""); + } + + public override async Task SelectMany_navigation_comparison2(bool async) + { + await base.SelectMany_navigation_comparison2(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id1], [l0].[Id] AS [Id2] +FROM [LevelOne] AS [l] +CROSS JOIN [LevelTwo] AS [l0] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Optional_Id] = [l1].[Id] +WHERE [l].[Id] = [l1].[Id] +"""); + } + + public override async Task SelectMany_navigation_comparison3(bool async) + { + await base.SelectMany_navigation_comparison3(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id1], [l0].[Id] AS [Id2] +FROM [LevelOne] AS [l] +CROSS JOIN [LevelTwo] AS [l0] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[Id] = [l0].[Id] +"""); + } + + 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], [l0].[Id] AS [Id2] +FROM [LevelOne] AS [l] +CROSS JOIN [LevelTwo] AS [l0] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +INNER JOIN [LevelOne] AS [l2] ON [l0].[Level1_Required_Id] = [l2].[Id] +WHERE [l1].[Name] = N'L2 01' OR [l2].[Name] <> N'Bar' OR [l2].[Name] IS NULL +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +WHERE [l1].[Name] = N'L3 05' OR [l0].[Name] <> N'L2 05' OR [l0].[Name] 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Level2_Optional_Id] +WHERE [l0].[Name] <> N'L2 05' OR [l0].[Name] IS NULL OR [l2].[Name] = N'L3 05' +"""); + } + + 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 [l].[Id] +FROM [LevelThree] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Level2_Optional_Id] = [l0].[Id] +INNER JOIN [LevelTwo] AS [l1] ON [l].[Level2_Required_Id] = [l1].[Id] +LEFT JOIN [LevelOne] AS [l2] ON [l1].[Level1_Optional_Id] = [l2].[Id] +WHERE [l0].[Name] <> N'L2 05' OR [l0].[Name] IS NULL OR [l2].[Name] = N'L1 05' +"""); + } + + 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], [l2].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +LEFT JOIN [LevelThree] AS [l2] ON [l0].[Id] = [l2].[Level2_Optional_Id] +WHERE ([l1].[Id] = [l2].[Id] OR ([l1].[Id] IS NULL AND [l2].[Id] IS NULL)) AND ([l2].[Id] <> 7 OR [l2].[Id] IS NULL) +"""); + } + + 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 [l].[Name], [l2].[Id] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +LEFT JOIN [LevelOne] AS [l2] ON [l0].[Level1_Optional_Id] = [l2].[Id] +WHERE ([l1].[Id] <> [l2].[Id] OR [l2].[Id] IS NULL) AND ([l2].[Id] <> 7 OR [l2].[Id] IS NULL) +"""); + } + + 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 [l0].[Id] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, [l0].[Id], [l0].[Name] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + public override async Task OrderBy_nav_prop_reference_optional(bool async) + { + await base.OrderBy_nav_prop_reference_optional(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +ORDER BY [l0].[Name], [l].[Id] +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +ORDER BY [l0].[Name], [l].[Id] +"""); + } + + 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([l0].[Level1_Required_Id]), 0) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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([l0].[Level1_Required_Id]) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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([l0].[Level1_Required_Id]) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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([l0].[Level1_Required_Id] AS float)) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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([l0].[Level1_Required_Id] AS float)) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[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([l0].[Level1_Required_Id] AS float)) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + public override async Task Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(bool async) + { + await base.Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(async); + + AssertSql( + """ +SELECT COALESCE(SUM(CASE + WHEN [l0].[Id] IS NULL THEN 0 + ELSE [l0].[Level1_Required_Id] +END), 0) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[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], [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].[Level1_Optional_Id] +WHERE [l0].[Name] <> N'L2 05' OR [l0].[Name] IS NULL +"""); + } + + public override async Task Join_flattening_bug_4539(bool async) + { + await base.Join_flattening_bug_4539(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], [l2].[Id], [l2].[Date], [l2].[Name], [l2].[OneToMany_Optional_Self_Inverse1Id], [l2].[OneToMany_Required_Self_Inverse1Id], [l2].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +CROSS JOIN [LevelTwo] AS [l1] +INNER JOIN [LevelOne] AS [l2] ON [l1].[Level1_Required_Id] = [l2].[Id] +"""); + } + + public override async Task Query_source_materialization_bug_4547(bool async) + { + await base.Query_source_materialization_bug_4547(async); + + AssertSql( + """ +SELECT [l0].[Id] +FROM [LevelThree] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Id] = ( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l1] + LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Level2_Optional_Id] + WHERE [l2].[Id] IS NOT NULL + ORDER BY [l2].[Id]) +"""); + } + + public override async Task SelectMany_navigation_property(bool async) + { + await base.SelectMany_navigation_property(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] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +"""); + } + + public override async Task SelectMany_navigation_property_and_projection(bool async) + { + await base.SelectMany_navigation_property_and_projection(async); + + AssertSql( + """ +SELECT [l0].[Name] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +"""); + } + + public override async Task SelectMany_navigation_property_and_filter_before(bool async) + { + await base.SelectMany_navigation_property_and_filter_before(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] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +WHERE [l].[Id] = 1 +"""); + } + + public override async Task SelectMany_navigation_property_and_filter_after(bool async) + { + await base.SelectMany_navigation_property_and_filter_after(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] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +WHERE [l0].[Id] <> 6 +"""); + } + + public override async Task SelectMany_nested_navigation_property_required(bool async) + { + await base.SelectMany_nested_navigation_property_required(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] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +"""); + } + + 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 [l1].[Name] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +"""); + } + + public override async Task Multiple_SelectMany_calls(bool async) + { + await base.Multiple_SelectMany_calls(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] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +"""); + } + + 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 [s].[Id], [s].[Level2_Optional_Id], [s].[Level2_Required_Id], [s].[Name], [s].[OneToMany_Optional_Inverse3Id], [s].[OneToMany_Optional_Self_Inverse3Id], [s].[OneToMany_Required_Inverse3Id], [s].[OneToMany_Required_Self_Inverse3Id], [s].[OneToOne_Optional_PK_Inverse3Id], [s].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +INNER 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], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +) AS [s] ON [l].[Id] = [s].[OneToMany_Optional_Inverse2Id] +"""); + } + + [ConditionalFact] + public void Multiple_complex_includes_from_sql() + { + using var context = CreateContext(); + var query = context.LevelOne.FromSqlRaw("SELECT * FROM [LevelOne]") + .Include(e => e.OneToOne_Optional_FK1) + .ThenInclude(e => e.OneToMany_Optional2) + .Include(e => e.OneToMany_Optional1) + .ThenInclude(e => e.OneToOne_Optional_FK2); + + var results = query.ToList(); + + Assert.Equal(13, results.Count); + + AssertSql( + """ +SELECT [m].[Id], [m].[Date], [m].[Name], [m].[OneToMany_Optional_Self_Inverse1Id], [m].[OneToMany_Required_Self_Inverse1Id], [m].[OneToOne_Optional_Self1Id], [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], [s].[Id], [s].[Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Optional_Self_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToMany_Required_Self_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[OneToOne_Optional_Self2Id], [s].[Id0], [s].[Level2_Optional_Id], [s].[Level2_Required_Id], [s].[Name0], [s].[OneToMany_Optional_Inverse3Id], [s].[OneToMany_Optional_Self_Inverse3Id], [s].[OneToMany_Required_Inverse3Id], [s].[OneToMany_Required_Self_Inverse3Id], [s].[OneToOne_Optional_PK_Inverse3Id], [s].[OneToOne_Optional_Self3Id] +FROM ( + SELECT * FROM [LevelOne] +) AS [m] +LEFT JOIN [LevelTwo] AS [l] ON [m].[Id] = [l].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + 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], [l2].[Id] AS [Id0], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Name] AS [Name0], [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] + FROM [LevelTwo] AS [l1] + LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[Level2_Optional_Id] +) AS [s] ON [m].[Id] = [s].[OneToMany_Optional_Inverse2Id] +ORDER BY [m].[Id], [l].[Id], [l0].[Id], [s].[Id] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE ( + SELECT COUNT(*) + FROM [LevelThree] AS [l1] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id]) > 0 +"""); + } + + public override async Task Where_navigation_property_to_collection2(bool async) + { + await base.Where_navigation_property_to_collection2(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Optional_Self_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToMany_Required_Self_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[OneToOne_Optional_Self3Id] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +WHERE ( + SELECT COUNT(*) + FROM [LevelThree] AS [l1] + WHERE [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id]) > 0 +"""); + } + + 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 [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] +INNER JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Required_Inverse2Id] = [l0].[Id] +WHERE ( + SELECT COUNT(*) + FROM [LevelTwo] AS [l1] + WHERE [l0].[Id] = [l1].[OneToMany_Optional_Inverse2Id]) > 0 +"""); + } + + 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 [LevelOne] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l0] + WHERE [l0].[Level1_Required_Id] = [l].[Id]) +"""); + } + + 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], [s].[Id] AS [Id2] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Optional_Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[Id0] +WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l2] + WHERE [l2].[Level1_Required_Id] = [l].[Id]) +"""); + } + + 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 [LevelOne] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l0] + WHERE EXISTS ( + SELECT 1 + FROM [LevelThree] AS [l1])) +"""); + } + + 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 [LevelOne] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l0] + WHERE EXISTS ( + SELECT 1 + FROM [LevelThree] AS [l1])) +"""); + } + + public override async Task SelectMany_where_with_subquery(bool async) + { + await base.SelectMany_where_with_subquery(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] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Required_Inverse2Id] +WHERE EXISTS ( + SELECT 1 + FROM [LevelThree] AS [l1] + WHERE [l0].[Id] = [l1].[OneToMany_Required_Inverse3Id]) +"""); + } + + 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 [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 [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +ORDER BY [l0].[Id] +"""); + } + + 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 [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 [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +ORDER BY [l0].[Id] +"""); + } + + 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 [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 [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +ORDER BY [l0].[Id] +"""); + } + + 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 [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +ORDER BY [l0].[Id] +"""); + } + + 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 [l1].[Name] +FROM ( + SELECT TOP(@__p_0) [l0].[Id] AS [Id0], [l0].[Level1_Required_Id] + FROM [LevelThree] AS [l] + INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] + ORDER BY [l0].[Id] +) AS [s] +INNER JOIN [LevelOne] AS [l1] ON [s].[Level1_Required_Id] = [l1].[Id] +ORDER BY [s].[Id0] +"""); + } + + 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) [l0].[Name] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Level2_Required_Id] = [l0].[Id] +ORDER BY [l0].[Id] +"""); + } + + public override async Task Optional_navigation_take_optional_navigation(bool async) + { + await base.Optional_navigation_take_optional_navigation(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [l1].[Name] +FROM ( + SELECT TOP(@__p_0) [l0].[Id] AS [Id0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + ORDER BY [l0].[Id] +) AS [s] +LEFT JOIN [LevelThree] AS [l1] ON [s].[Id0] = [l1].[Level2_Optional_Id] +ORDER BY [s].[Id0] +"""); + } + + 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) [l].[Name] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +WHERE [l0].[Name] = N'L1 03' +ORDER BY [l].[Id] +"""); + } + + 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) [l].[Name] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +ORDER BY [l0].[Id] +"""); + } + + 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) [l0].[Name] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[Level1_Required_Id] = [l0].[Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +ORDER BY [l0].[Id] +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +WHERE [l0].[Name] = N'L2 03' +ORDER BY [l].[Id] +"""); + } + + public override async Task SelectMany_with_string_based_Include1(bool async) + { + await base.SelectMany_with_string_based_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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +"""); + } + + public override async Task SelectMany_with_string_based_Include2(bool async) + { + await base.SelectMany_with_string_based_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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +"""); + } + + public override async Task Multiple_SelectMany_with_string_based_Include(bool async) + { + await base.Multiple_SelectMany_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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +"""); + } + + 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 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +WHERE [l0].[Id] IS NOT NULL +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] > 5 +) AS [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +WHERE [l1].[Id] 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +WHERE [l1].[Id] 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id] + FROM [LevelThree] AS [l1] + WHERE [l1].[Id] > 5 +) AS [l2] ON [l0].[Id] = [l2].[OneToMany_Optional_Inverse3Id] +WHERE [l2].[Id] IS NOT NULL +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToMany_Required_Inverse3Id] + FROM [LevelThree] AS [l1] + WHERE [l1].[Id] > 5 +) AS [l2] ON [l0].[Id] = [l2].[OneToMany_Required_Inverse3Id] +WHERE [l2].[Id] IS NOT NULL +"""); + } + + 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( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [s].[Id2], [s].[Date0], [s].[Level1_Optional_Id0], [s].[Level1_Required_Id0], [s].[Name2], [s].[OneToMany_Optional_Inverse2Id0], [s].[OneToMany_Optional_Self_Inverse2Id0], [s].[OneToMany_Required_Inverse2Id0], [s].[OneToMany_Required_Self_Inverse2Id0], [s].[OneToOne_Optional_PK_Inverse2Id0], [s].[OneToOne_Optional_Self2Id0] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l3].[Id] AS [Id2], [l3].[Date] AS [Date0], [l3].[Level1_Optional_Id] AS [Level1_Optional_Id0], [l3].[Level1_Required_Id] AS [Level1_Required_Id0], [l3].[Name] AS [Name2], [l3].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [l3].[OneToMany_Optional_Self_Inverse2Id] AS [OneToMany_Optional_Self_Inverse2Id0], [l3].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [l3].[OneToMany_Required_Self_Inverse2Id] AS [OneToMany_Required_Self_Inverse2Id0], [l3].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [l3].[OneToOne_Optional_Self2Id] AS [OneToOne_Optional_Self2Id0] + FROM [LevelFour] AS [l0] + INNER JOIN [LevelThree] AS [l1] ON [l0].[Level3_Required_Id] = [l1].[Id] + LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Level2_Optional_Id] = [l2].[Id] + INNER JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[OneToMany_Required_Self_Inverse2Id] +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id0] +"""); + } + + 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( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [s].[Id2], [s].[Date0], [s].[Level1_Optional_Id0], [s].[Level1_Required_Id0], [s].[Name2], [s].[OneToMany_Optional_Inverse2Id0], [s].[OneToMany_Optional_Self_Inverse2Id0], [s].[OneToMany_Required_Inverse2Id0], [s].[OneToMany_Required_Self_Inverse2Id0], [s].[OneToOne_Optional_PK_Inverse2Id0], [s].[OneToOne_Optional_Self2Id0] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l3].[Id] AS [Id2], [l3].[Date] AS [Date0], [l3].[Level1_Optional_Id] AS [Level1_Optional_Id0], [l3].[Level1_Required_Id] AS [Level1_Required_Id0], [l3].[Name] AS [Name2], [l3].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [l3].[OneToMany_Optional_Self_Inverse2Id] AS [OneToMany_Optional_Self_Inverse2Id0], [l3].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [l3].[OneToMany_Required_Self_Inverse2Id] AS [OneToMany_Required_Self_Inverse2Id0], [l3].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [l3].[OneToOne_Optional_Self2Id] AS [OneToOne_Optional_Self2Id0] + FROM [LevelFour] AS [l0] + INNER JOIN [LevelThree] AS [l1] ON [l0].[Level3_Required_Id] = [l1].[Id] + LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Level2_Optional_Id] = [l2].[Id] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[OneToMany_Required_Self_Inverse2Id] +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id0] +"""); + } + + 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( + """ +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], [l3].[Id], [l3].[Date], [l3].[Name], [l3].[OneToMany_Optional_Self_Inverse1Id], [l3].[OneToMany_Required_Self_Inverse1Id], [l3].[OneToOne_Optional_Self1Id] +FROM [LevelFour] AS [l] +INNER JOIN [LevelThree] AS [l0] ON [l].[Level3_Required_Id] = [l0].[Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Level2_Optional_Id] = [l1].[Id] +LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Self_Inverse2Id] +INNER JOIN [LevelOne] AS [l3] ON [l2].[Level1_Optional_Id] = [l3].[Id] +"""); + } + + 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 [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], [l3].[Id], [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] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Inverse4Id] +INNER JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Id] +"""); + } + + 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 [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], [l3].[Id], [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] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Inverse4Id] +LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Id] +"""); + } + + 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( + """ +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], [s].[Id2], [s].[Date0], [s].[Level1_Optional_Id0], [s].[Level1_Required_Id0], [s].[Name2], [s].[OneToMany_Optional_Inverse2Id0], [s].[OneToMany_Optional_Self_Inverse2Id0], [s].[OneToMany_Required_Inverse2Id0], [s].[OneToMany_Required_Self_Inverse2Id0], [s].[OneToOne_Optional_PK_Inverse2Id0], [s].[OneToOne_Optional_Self2Id0] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Inverse4Id] +INNER JOIN ( + SELECT [l6].[Id] AS [Id2], [l6].[Date] AS [Date0], [l6].[Level1_Optional_Id] AS [Level1_Optional_Id0], [l6].[Level1_Required_Id] AS [Level1_Required_Id0], [l6].[Name] AS [Name2], [l6].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [l6].[OneToMany_Optional_Self_Inverse2Id] AS [OneToMany_Optional_Self_Inverse2Id0], [l6].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [l6].[OneToMany_Required_Self_Inverse2Id] AS [OneToMany_Required_Self_Inverse2Id0], [l6].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [l6].[OneToOne_Optional_Self2Id] AS [OneToOne_Optional_Self2Id0] + FROM [LevelFour] AS [l3] + INNER JOIN [LevelThree] AS [l4] ON [l3].[Level3_Required_Id] = [l4].[Id] + LEFT JOIN [LevelTwo] AS [l5] ON [l4].[Level2_Optional_Id] = [l5].[Id] + LEFT JOIN [LevelTwo] AS [l6] ON [l5].[Id] = [l6].[OneToMany_Required_Self_Inverse2Id] +) AS [s] ON [l2].[Id] = [s].[Id2] +"""); + } + + 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 [l4].[Id], [l4].[Date], [l4].[Name], [l4].[OneToMany_Optional_Self_Inverse1Id], [l4].[OneToMany_Required_Self_Inverse1Id], [l4].[OneToOne_Optional_Self1Id] +FROM [LevelFour] AS [l] +INNER JOIN [LevelThree] AS [l0] ON [l].[Level3_Required_Id] = [l0].[Id] +INNER JOIN [LevelTwo] AS [l1] ON [l0].[Level2_Required_Id] = [l1].[Id] +LEFT JOIN [LevelThree] AS [l2] ON [l1].[Id] = [l2].[OneToMany_Required_Inverse3Id] +LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Level2_Required_Id] = [l3].[Id] +LEFT JOIN [LevelOne] AS [l4] ON [l3].[Id] = [l4].[Id] +"""); + } + + 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 [l3].[Id], [l3].[Date], [l3].[Name], [l3].[OneToMany_Optional_Self_Inverse1Id], [l3].[OneToMany_Required_Self_Inverse1Id], [l3].[OneToOne_Optional_Self1Id] +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].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Level2_Required_Id] = [l2].[Id] +LEFT JOIN [LevelOne] AS [l3] ON [l2].[Id] = [l3].[Id] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToMany_Optional_Inverse3Id] + FROM [LevelThree] AS [l1] + WHERE [l1].[Id] > 5 +) AS [l2] ON [l0].[Id] = [l2].[OneToMany_Optional_Inverse3Id] +WHERE [l2].[Id] IS NOT NULL +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToMany_Required_Inverse2Id] + FROM ( + SELECT [l0].[Id], [l0].[OneToMany_Required_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Required_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] > 5 + ) AS [l1] + WHERE [l1].[row] <= 3 +) AS [l2] ON [l].[Id] = [l2].[OneToMany_Required_Inverse2Id] +WHERE [l2].[Id] 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [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] +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] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] > 2 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + 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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = COALESCE(( + SELECT TOP(1) [l1].[Id] + FROM [LevelTwo] AS [l1] + ORDER BY [l1].[Id]), 0) +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE 6 IN ( + SELECT [l2].[Id] + FROM ( + SELECT DISTINCT [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 [LevelThree] AS [l1] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] + ) AS [l2] +) +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE 5 IN ( + SELECT DISTINCT CAST(LEN([l1].[Name]) AS int) + FROM [LevelThree] AS [l1] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +) +"""); + } + + 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) [l1].[Name] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] + ORDER BY [l0].[Id]) +FROM [LevelTwo] AS [l] +WHERE [l].[Id] = 7 +"""); + } + + 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) [l2].[Name] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] + INNER JOIN [LevelOne] AS [l2] ON [l0].[Level1_Required_Id] = [l2].[Id] + ORDER BY [l0].[Id]) +FROM [LevelTwo] AS [l] +WHERE [l].[Id] = 7 +"""); + } + + 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 [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] +WHERE [l].[Id] = 7 AND (( + SELECT TOP(1) [l1].[Name] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] + ORDER BY [l0].[Id]) = N'L1 10' OR ( + SELECT TOP(1) [l3].[Name] + FROM [LevelTwo] AS [l2] + INNER JOIN [LevelOne] AS [l3] ON [l2].[Level1_Required_Id] = [l3].[Id] + ORDER BY [l2].[Id]) = N'L1 01') +"""); + } + + 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 [l1].[Name] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +WHERE [l1].[Name] <> N'L3 02' OR [l1].[Name] IS NULL +"""); + } + + 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 [l0].[Id] AS [Id1], [l1].[Id] AS [Id2] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[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 [l].[Name] AS [Name1], [s].[Name0] AS [Name2] +FROM [LevelThree] AS [l] +LEFT JOIN ( + SELECT [l1].[Id] AS [Id0], [l1].[Name] AS [Name0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Level2_Required_Id] = [s].[Id0] +"""); + } + + public override async Task Null_reference_protection_complex(bool async) + { + await base.Null_reference_protection_complex(async); + + AssertSql( + """ +SELECT [s].[Name0] +FROM [LevelThree] AS [l] +LEFT JOIN ( + SELECT [l1].[Id] AS [Id0], [l1].[Name] AS [Name0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Level2_Required_Id] = [s].[Id0] +"""); + } + + public override async Task Null_reference_protection_complex_materialization(bool async) + { + await base.Null_reference_protection_complex_materialization(async); + + AssertSql( + """ +SELECT [s].[Id0], [s].[Date0], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Name0], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Optional_Self_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToMany_Required_Self_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[OneToOne_Optional_Self2Id] +FROM [LevelThree] AS [l] +LEFT JOIN ( + SELECT [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] +) AS [s] ON [l].[Level2_Required_Id] = [s].[Id0] +"""); + } + + public override async Task Null_reference_protection_complex_client_eval(bool async) + { + await base.Null_reference_protection_complex_client_eval(async); + + AssertSql( + """ +SELECT [s].[Name0] +FROM [LevelThree] AS [l] +LEFT JOIN ( + SELECT [l1].[Id] AS [Id0], [l1].[Name] AS [Name0] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] +) AS [s] ON [l].[Level2_Required_Id] = [s].[Id0] +"""); + } + + 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 [s].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +"""); + } + + 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 [s].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[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 [s].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Level1_Required_Id] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +) AS [s] ON [l].[Id] = [s].[Level1_Required_Id] +"""); + } + + 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 [l1].[Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [s].[Id] +"""); + } + + 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_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 [l1].[Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l0].[Level1_Optional_Id] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s] +LEFT JOIN [LevelOne] AS [l1] ON [s].[Level1_Optional_Id] = [l1].[Id] +ORDER BY [s].[Id] +"""); + } + + 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 [l1].[Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l0].[Level1_Optional_Id] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s] +LEFT JOIN [LevelOne] AS [l1] ON [s].[Level1_Optional_Id] = [l1].[Id] +ORDER BY [s].[Id] +"""); + } + + 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], [l0].[Name] AS [Brand] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +ORDER BY [l0].[Name], [l].[Id] +"""); + } + + 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 [l].[Id], [s].[Name] +FROM [LevelTwo] AS [l] +LEFT JOIN ( + SELECT TOP(@__p_0) [l0].[Id], [l0].[Name] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + ORDER BY [l1].[Name] +) AS [s] ON [l].[Level1_Optional_Id] = [s].[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 [LevelOne] AS [l] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT DISTINCT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + ) AS [s]) > 7 AND [l].[Id] < 3 +"""); + } + + 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 [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) + { + await base.GroupJoin_in_subquery_with_client_projection_nested1(async); + + AssertSql( + """ +SELECT [l].[Name] +FROM [LevelOne] AS [l] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT TOP(10) 1 AS empty + 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 [s]) > 4 AND [l].[Id] < 2 +"""); + } + + 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 [LevelOne] AS [l] +WHERE ( + SELECT COUNT(*) + 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) + { + await base.GroupJoin_client_method_on_outer(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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_without_DefaultIfEmpty(bool async) + { + await base.GroupJoin_without_DefaultIfEmpty(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + public override async Task GroupJoin_with_subquery_on_inner(bool async) + { + await base.GroupJoin_with_subquery_on_inner(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l1].[Level1_Optional_Id] + FROM ( + SELECT [l0].[Level1_Optional_Id], ROW_NUMBER() OVER(PARTITION BY [l0].[Level1_Optional_Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] > 0 + ) AS [l1] + WHERE [l1].[row] <= 10 +) AS [l2] ON [l].[Id] = [l2].[Level1_Optional_Id] +"""); + } + + 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 [l].[Id] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l1].[Level1_Optional_Id] + FROM ( + SELECT [l0].[Level1_Optional_Id], ROW_NUMBER() OVER(PARTITION BY [l0].[Level1_Optional_Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] > 0 + ) AS [l1] + WHERE [l1].[row] <= 10 +) AS [l2] ON [l].[Id] = [l2].[Level1_Optional_Id] +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +ORDER BY [l].[Id] +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +ORDER BY [l].[Id] +"""); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_projection2(bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_unrelated_projection2(async); + + AssertSql( + """ +SELECT [s].[Id] +FROM ( + SELECT DISTINCT [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 [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [s] +"""); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +"""); + } + + 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) [s].[Id] +FROM ( + SELECT DISTINCT [l].[Id] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [s] +ORDER BY [s].[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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +WHERE ( + SELECT COUNT(*) + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id]) > 4 +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT DISTINCT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + ) AS [s]) > 4 +"""); + } + + 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 [l].[Name] +FROM [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[OneToMany_Required_Inverse3Id] = [l0].[Id] +INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +WHERE [l1].[Name] IN (N'L1 10', N'L1 01') +ORDER BY [l].[Level2_Required_Id] +OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY +"""); + } + + 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( + """ +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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[OneToMany_Optional_Self_Inverse1Id] = [l0].[Level1_Optional_Id] OR ([l].[OneToMany_Optional_Self_Inverse1Id] IS NULL AND [l0].[Level1_Optional_Id] IS NULL) +"""); + } + + 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( + """ +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] +INNER JOIN [LevelTwo] AS [l0] ON ([l].[OneToMany_Optional_Self_Inverse1Id] = [l0].[Level1_Optional_Id] OR ([l].[OneToMany_Optional_Self_Inverse1Id] IS NULL AND [l0].[Level1_Optional_Id] IS NULL)) AND ([l].[OneToOne_Optional_Self1Id] = [l0].[OneToMany_Optional_Self_Inverse2Id] OR ([l].[OneToOne_Optional_Self1Id] IS NULL AND [l0].[OneToMany_Optional_Self_Inverse2Id] IS NULL)) +"""); + } + + public override async Task Nested_group_join_with_take(bool async) + { + await base.Nested_group_join_with_take(async); + + AssertSql( + """ +@__p_0='2' + +SELECT [l1].[Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [l0].[Id] AS [Id0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id0] = [l1].[Level1_Optional_Id] +ORDER BY [s].[Id] +"""); + } + + 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 [l].[Id] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Required_Inverse2Id] = [l0].[Id] +WHERE [l0].[Name] <> N'L1 07' OR [l0].[Name] IS NULL +"""); + } + + public override async Task Multi_level_navigation_compared_to_null(bool async) + { + await base.Multi_level_navigation_compared_to_null(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelThree] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[OneToMany_Optional_Inverse3Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +WHERE [l1].[Id] IS NOT NULL +"""); + } + + 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 [l].[Id] +FROM [LevelThree] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[OneToMany_Optional_Inverse3Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] +WHERE ([l1].[Name] <> N'L1 07' OR [l1].[Name] IS NULL) AND [l1].[Id] IS NOT NULL +"""); + } + + public override async Task Navigations_compared_to_each_other1(bool async) + { + await base.Navigations_compared_to_each_other1(async); + + AssertSql( + """ +SELECT [l].[Name] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Required_Inverse2Id] = [l0].[Id] +"""); + } + + public override async Task Navigations_compared_to_each_other2(bool async) + { + await base.Navigations_compared_to_each_other2(async); + + AssertSql( + """ +SELECT [l].[Name] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Required_Inverse2Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l].[OneToOne_Optional_PK_Inverse2Id] = [l1].[Id] +WHERE [l0].[Id] = [l1].[Id] +"""); + } + + public override async Task Navigations_compared_to_each_other3(bool async) + { + await base.Navigations_compared_to_each_other3(async); + + AssertSql( + """ +SELECT [l].[Name] +FROM [LevelTwo] AS [l] +WHERE EXISTS ( + SELECT 1 + FROM [LevelThree] AS [l0] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse3Id]) +"""); + } + + public override async Task Navigations_compared_to_each_other4(bool async) + { + await base.Navigations_compared_to_each_other4(async); + + AssertSql( + """ +SELECT [l].[Name] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[Level2_Required_Id] +WHERE EXISTS ( + SELECT 1 + FROM [LevelFour] AS [l1] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse4Id]) +"""); + } + + public override async Task Navigations_compared_to_each_other5(bool async) + { + await base.Navigations_compared_to_each_other5(async); + + AssertSql( + """ +SELECT [l].[Name] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[Level2_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +WHERE EXISTS ( + SELECT 1 + FROM [LevelFour] AS [l2] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l2].[OneToMany_Optional_Inverse4Id]) +"""); + } + + public override async Task Level4_Include(bool async) + { + await base.Level4_Include(async); + + AssertSql(); + } + + 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 [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[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) [l1].[Name] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] + ORDER BY [l0].[Id]) +FROM [LevelTwo] AS [l] +"""); + } + + 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) [l1].[Name] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] + ORDER BY [l0].[Id]) = N'L1 02' AND ( + SELECT TOP(1) [l1].[Name] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelOne] AS [l1] ON [l0].[Level1_Required_Id] = [l1].[Id] + ORDER BY [l0].[Id]) IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [LevelTwo] AS [l] +"""); + } + + 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) [l2].[Name] + FROM [LevelThree] AS [l0] + INNER JOIN [LevelTwo] AS [l1] ON [l0].[Level2_Required_Id] = [l1].[Id] + INNER JOIN [LevelOne] AS [l2] ON [l1].[Level1_Required_Id] = [l2].[Id] + ORDER BY [l0].[Id]) +FROM [LevelThree] AS [l] +"""); + } + + 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 [l1].[Name] + FROM ( + SELECT DISTINCT [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 [LevelThree] AS [l0] + ) AS [l1] + ORDER BY [l1].[Id] + OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY) +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + 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 [l1].[Name] + FROM ( + SELECT DISTINCT [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 [LevelThree] AS [l0] + ) AS [l1] + ORDER BY (SELECT 1) + OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY) AS [Subquery] +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + public override async Task Project_collection_navigation_count(bool async) + { + await base.Project_collection_navigation_count(async); + + AssertSql( + """ +SELECT [l].[Id], ( + SELECT COUNT(*) + FROM [LevelThree] AS [l1] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id]) AS [Count] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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 [l1].[Id] IS NOT NULL THEN [l1].[Name] + ELSE N'NULL' +END, N'') +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] > 5 +) AS [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +"""); + } + + public override async Task Include_reference_with_groupby_in_subquery(bool async) + { + await base.Include_reference_with_groupby_in_subquery(async); + + AssertSql( + """ +SELECT [s0].[Id], [s0].[Date], [s0].[Name], [s0].[OneToMany_Optional_Self_Inverse1Id], [s0].[OneToMany_Required_Self_Inverse1Id], [s0].[OneToOne_Optional_Self1Id], [s0].[Id0], [s0].[Date0], [s0].[Level1_Optional_Id], [s0].[Level1_Required_Id], [s0].[Name0], [s0].[OneToMany_Optional_Inverse2Id], [s0].[OneToMany_Optional_Self_Inverse2Id], [s0].[OneToMany_Required_Inverse2Id], [s0].[OneToMany_Required_Self_Inverse2Id], [s0].[OneToOne_Optional_PK_Inverse2Id], [s0].[OneToOne_Optional_Self2Id] +FROM ( + SELECT [l].[Name] + FROM [LevelOne] AS [l] + GROUP BY [l].[Name] +) AS [l2] +LEFT JOIN ( + SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [s].[Id0], [s].[Date0], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Name0], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Optional_Self_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToMany_Required_Self_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[OneToOne_Optional_Self2Id] + FROM ( + SELECT [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], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + ) AS [s] + WHERE [s].[row] <= 1 +) AS [s0] ON [l2].[Name] = [s0].[Name] +"""); + } + + public override async Task Multi_include_with_groupby_in_subquery(bool async) + { + await base.Multi_include_with_groupby_in_subquery(async); + + AssertSql( + """ +SELECT [s0].[Id], [s0].[Date], [s0].[Name], [s0].[OneToMany_Optional_Self_Inverse1Id], [s0].[OneToMany_Required_Self_Inverse1Id], [s0].[OneToOne_Optional_Self1Id], [s0].[Id0], [s0].[Date0], [s0].[Level1_Optional_Id], [s0].[Level1_Required_Id], [s0].[Name0], [s0].[OneToMany_Optional_Inverse2Id], [s0].[OneToMany_Optional_Self_Inverse2Id], [s0].[OneToMany_Required_Inverse2Id], [s0].[OneToMany_Required_Self_Inverse2Id], [s0].[OneToOne_Optional_PK_Inverse2Id], [s0].[OneToOne_Optional_Self2Id], [l3].[Name], [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] +FROM ( + SELECT [l].[Name] + FROM [LevelOne] AS [l] + GROUP BY [l].[Name] +) AS [l3] +LEFT JOIN ( + SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [s].[Id0], [s].[Date0], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Name0], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Optional_Self_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToMany_Required_Self_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[OneToOne_Optional_Self2Id] + FROM ( + SELECT [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], ROW_NUMBER() OVER(PARTITION BY [l0].[Name] ORDER BY [l0].[Id]) AS [row] + FROM [LevelOne] AS [l0] + LEFT JOIN [LevelTwo] AS [l1] ON [l0].[Id] = [l1].[Level1_Optional_Id] + ) AS [s] + WHERE [s].[row] <= 1 +) AS [s0] ON [l3].[Name] = [s0].[Name] +LEFT JOIN [LevelThree] AS [l2] ON [s0].[Id0] = [l2].[OneToMany_Optional_Inverse3Id] +ORDER BY [l3].[Name], [s0].[Id], [s0].[Id0] +"""); + } + + 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].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived1Id], [i0].[InheritanceDerived1Id1], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeReference_InheritanceDerived1Id], [i1].[InheritanceDerived1Id], [i1].[InheritanceDerived1Id1], [i1].[InheritanceDerived2Id], [i1].[Name], [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 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].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived1Id], [i0].[InheritanceDerived1Id1], [i0].[InheritanceDerived2Id], [i0].[Name], [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 + 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].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived1Id], [i0].[InheritanceDerived1Id1], [i0].[InheritanceDerived2Id], [i0].[Name], [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 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].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived1Id], [i0].[InheritanceDerived1Id1], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [i1].[Id], [i1].[DifferentTypeReference_InheritanceDerived1Id], [i1].[InheritanceDerived1Id], [i1].[InheritanceDerived1Id1], [i1].[InheritanceDerived2Id], [i1].[Name], [i1].[SameTypeReference_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived2Id] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[InheritanceDerived1Id1] +LEFT JOIN [InheritanceLeafOne] AS [i1] ON [i].[Id] = [i1].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[Id] +"""); + } + + 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].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived1Id], [i0].[InheritanceDerived1Id1], [i0].[InheritanceDerived2Id], [i0].[Name], [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].[InheritanceDerived1Id] +LEFT JOIN [InheritanceLeafTwo] AS [i1] ON [i].[Id] = [i1].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[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].[DifferentTypeReference_InheritanceDerived1Id], [i0].[InheritanceDerived1Id], [i0].[InheritanceDerived1Id1], [i0].[InheritanceDerived2Id], [i0].[Name], [i0].[SameTypeReference_InheritanceDerived1Id], [i0].[SameTypeReference_InheritanceDerived2Id], [s].[Id], [s].[DifferentTypeReference_InheritanceDerived2Id], [s].[InheritanceDerived2Id], [s].[Name], [s].[Id0], [s].[InheritanceLeaf2Id], [s].[Name0] +FROM [InheritanceOne] AS [i] +LEFT JOIN [InheritanceLeafOne] AS [i0] ON [i].[Id] = [i0].[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 [s] ON [i].[Id] = [s].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[Id], [s].[Id] +"""); + } + + 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].[DifferentTypeReference_InheritanceDerived1Id], [i1].[InheritanceDerived1Id], [i1].[InheritanceDerived1Id1], [i1].[InheritanceDerived2Id], [i1].[Name], [i1].[SameTypeReference_InheritanceDerived1Id], [i1].[SameTypeReference_InheritanceDerived2Id], [i2].[Id], [i2].[DifferentTypeReference_InheritanceDerived2Id], [i2].[InheritanceDerived2Id], [i2].[Name], [s].[Id], [s].[Discriminator], [s].[InheritanceBase2Id], [s].[InheritanceBase2Id1], [s].[Name], [s].[Id0], [s].[DifferentTypeReference_InheritanceDerived1Id], [s].[InheritanceDerived1Id], [s].[InheritanceDerived1Id1], [s].[InheritanceDerived2Id], [s].[Name0], [s].[SameTypeReference_InheritanceDerived1Id], [s].[SameTypeReference_InheritanceDerived2Id], [s].[Id1], [s].[DifferentTypeReference_InheritanceDerived1Id0], [s].[InheritanceDerived1Id0], [s].[InheritanceDerived1Id10], [s].[InheritanceDerived2Id0], [s].[Name1], [s].[SameTypeReference_InheritanceDerived1Id0], [s].[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].[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].[DifferentTypeReference_InheritanceDerived1Id], [i4].[InheritanceDerived1Id], [i4].[InheritanceDerived1Id1], [i4].[InheritanceDerived2Id], [i4].[Name] AS [Name0], [i4].[SameTypeReference_InheritanceDerived1Id], [i4].[SameTypeReference_InheritanceDerived2Id], [i5].[Id] AS [Id1], [i5].[DifferentTypeReference_InheritanceDerived1Id] AS [DifferentTypeReference_InheritanceDerived1Id0], [i5].[InheritanceDerived1Id] AS [InheritanceDerived1Id0], [i5].[InheritanceDerived1Id1] AS [InheritanceDerived1Id10], [i5].[InheritanceDerived2Id] AS [InheritanceDerived2Id0], [i5].[Name] AS [Name1], [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 [s] ON [i].[Id] = [s].[InheritanceBase2Id1] +ORDER BY [i].[Id], [i0].[Id], [i1].[Id], [i2].[Id], [s].[Id], [s].[Id0] +"""); + } + + 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 GREATEST([l0].[Level1_Required_Id], 7) +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] +WHERE [l0].[Id] IS NOT NULL +"""); + } + + public override async Task Accessing_optional_property_inside_result_operator_subquery(bool async) + { + await base.Accessing_optional_property_inside_result_operator_subquery(async); + + AssertSql( + """ +@__names_0='["Name1","Name2"]' (Size = 4000) + +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] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Name] NOT IN ( + SELECT [n].[value] + FROM OPENJSON(@__names_0) WITH ([value] nvarchar(max) '$') AS [n] +) OR [l0].[Name] IS NULL +"""); + } + + public override async Task Include1(bool async) + { + await base.Include1(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].[Level1_Optional_Id] +"""); + } + + public override async Task Include2(bool async) + { + await base.Include2(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].[Level1_Optional_Id] +"""); + } + + public override async Task Include3(bool async) + { + await base.Include3(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].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[OneToOne_Optional_PK_Inverse2Id] +"""); + } + + public override async Task Include4(bool async) + { + await base.Include4(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].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +"""); + } + + public override async Task Include5(bool async) + { + await base.Include5(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].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +"""); + } + + public override async Task Include6(bool async) + { + await base.Include6(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], [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].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToOne_Optional_PK_Inverse3Id] +"""); + } + + public override async Task Include7(bool async) + { + await base.Include7(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] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] +"""); + } + + public override async Task Include8(bool async) + { + await base.Include8(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].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelOne] AS [l0] ON [l].[Level1_Optional_Id] = [l0].[Id] +WHERE [l0].[Name] <> N'Fubar' OR [l0].[Name] IS NULL +"""); + } + + public override async Task Include9(bool async) + { + await base.Include9(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].[Date], [l0].[Name], [l0].[OneToMany_Optional_Self_Inverse1Id], [l0].[OneToMany_Required_Self_Inverse1Id], [l0].[OneToOne_Optional_Self1Id] +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelOne] AS [l0] ON [l].[Level1_Optional_Id] = [l0].[Id] +WHERE [l0].[Name] <> N'Fubar' OR [l0].[Name] IS NULL +"""); + } + + public override async Task Include10(bool async) + { + await base.Include10(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].[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], [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], [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Name], [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] +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 [LevelTwo] AS [l2] ON [l].[Id] = [l2].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN [LevelThree] AS [l3] ON [l2].[Id] = [l3].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l4] ON [l3].[Id] = [l4].[OneToOne_Optional_PK_Inverse4Id] +"""); + } + + public override async Task Include11(bool async) + { + await base.Include11(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].[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], [l3].[Id], [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], [l4].[Id], [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], [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Optional_Self_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToMany_Required_Self_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [l5].[OneToOne_Optional_Self4Id], [l6].[Id], [l6].[Level3_Optional_Id], [l6].[Level3_Required_Id], [l6].[Name], [l6].[OneToMany_Optional_Inverse4Id], [l6].[OneToMany_Optional_Self_Inverse4Id], [l6].[OneToMany_Required_Inverse4Id], [l6].[OneToMany_Required_Self_Inverse4Id], [l6].[OneToOne_Optional_PK_Inverse4Id], [l6].[OneToOne_Optional_Self4Id], [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[Name], [l7].[OneToMany_Optional_Inverse3Id], [l7].[OneToMany_Optional_Self_Inverse3Id], [l7].[OneToMany_Required_Inverse3Id], [l7].[OneToMany_Required_Self_Inverse3Id], [l7].[OneToOne_Optional_PK_Inverse3Id], [l7].[OneToOne_Optional_Self3Id] +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].[Level2_Optional_Id] +LEFT JOIN [LevelThree] AS [l2] ON [l0].[Id] = [l2].[OneToOne_Optional_PK_Inverse3Id] +LEFT JOIN [LevelTwo] AS [l3] ON [l].[Id] = [l3].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN [LevelThree] AS [l4] ON [l3].[Id] = [l4].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l5] ON [l4].[Id] = [l5].[Level3_Optional_Id] +LEFT JOIN [LevelFour] AS [l6] ON [l4].[Id] = [l6].[OneToOne_Optional_PK_Inverse4Id] +LEFT JOIN [LevelThree] AS [l7] ON [l3].[Id] = [l7].[OneToOne_Optional_PK_Inverse3Id] +"""); + } + + public override async Task Include12(bool async) + { + await base.Include12(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], [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].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +"""); + } + + public override async Task Include13(bool async) + { + await base.Include13(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].[Level1_Optional_Id] +"""); + } + + public override async Task Include14(bool async) + { + await base.Include14(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], [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], [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].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN [LevelThree] AS [l2] ON [l0].[Id] = [l2].[Level2_Optional_Id] +"""); + } + + public override async Task Include17(bool async) + { + await base.Include17(async); + + AssertSql(); + } + + public override async Task Include18_1(bool async) + { + await base.Include18_1(async); + + AssertSql( + """ +SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[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 ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l] +) AS [l1] +LEFT JOIN [LevelTwo] AS [l0] ON [l1].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + public override async Task Include18_1_1(bool async) + { + await base.Include18_1_1(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Name] AS [Name0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] + ORDER BY [l0].[Name] +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [s].[Name0] +"""); + } + + public override async Task Include18_2(bool async) + { + await base.Include18_2(async); + + AssertSql( + """ +SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [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 ( + SELECT DISTINCT [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 [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] + WHERE [l0].[Name] <> N'Foo' OR [l0].[Name] IS NULL +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + public override async Task Include18_3(bool async) + { + await base.Include18_3(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Name] AS [Name0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] + ORDER BY [l0].[Name] +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [s].[Name0] +"""); + } + + public override async Task Include18_3_1(bool async) + { + await base.Include18_3_1(async); + + // issue #15783 + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Name] AS [Name0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] + ORDER BY [l0].[Name] +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [s].[Name0] +"""); + } + + public override async Task Include18_3_2(bool async) + { + await base.Include18_3_2(async); + + // issue #15783 + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id], [s].[Date], [s].[Name], [s].[OneToMany_Optional_Self_Inverse1Id], [s].[OneToMany_Required_Self_Inverse1Id], [s].[OneToOne_Optional_Self1Id], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Name] AS [Name0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] + ORDER BY [l0].[Name] +) AS [s] +LEFT JOIN [LevelTwo] AS [l1] ON [s].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [s].[Name0] +"""); + } + + public override async Task Include18_3_3(bool async) + { + await base.Include18_3_3(async); + + AssertSql( + """ +SELECT [s].[Id], [s].[Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Optional_Self_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToMany_Required_Self_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[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 ( + 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] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +) AS [s] +LEFT JOIN [LevelThree] AS [l1] ON [s].[Id] = [l1].[Level2_Optional_Id] +"""); + } + + public override async Task Include18_4(bool async) + { + await base.Include18_4(async); + + // issue #15783 + AssertSql( + """ +SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[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], [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 ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l] +) AS [l1] +LEFT JOIN [LevelTwo] AS [l0] ON [l1].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id] +"""); + } + + public override async Task Include18(bool async) + { + await base.Include18(async); + + AssertSql( + """ +@__p_0='10' + +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], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l] + ORDER BY [l].[Id] +) AS [l1] +LEFT JOIN [LevelTwo] AS [l0] ON [l1].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id] +ORDER BY [l1].[Id] +"""); + } + + public override async Task Include19(bool async) + { + await base.Include19(async); + + AssertSql( + """ +SELECT [s].[Id], [s].[Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Optional_Self_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToMany_Required_Self_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[OneToOne_Optional_Self2Id], [s].[Id0], [s].[Date0], [s].[Level1_Optional_Id0], [s].[Level1_Required_Id0], [s].[Name0], [s].[OneToMany_Optional_Inverse2Id0], [s].[OneToMany_Optional_Self_Inverse2Id0], [s].[OneToMany_Required_Inverse2Id0], [s].[OneToMany_Required_Self_Inverse2Id0], [s].[OneToOne_Optional_PK_Inverse2Id0], [s].[OneToOne_Optional_Self2Id0] +FROM ( + 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], [l1].[Id] AS [Id0], [l1].[Date] AS [Date0], [l1].[Level1_Optional_Id] AS [Level1_Optional_Id0], [l1].[Level1_Required_Id] AS [Level1_Required_Id0], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [l1].[OneToMany_Optional_Self_Inverse2Id] AS [OneToMany_Optional_Self_Inverse2Id0], [l1].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [l1].[OneToMany_Required_Self_Inverse2Id] AS [OneToMany_Required_Self_Inverse2Id0], [l1].[OneToOne_Optional_PK_Inverse2Id] AS [OneToOne_Optional_PK_Inverse2Id0], [l1].[OneToOne_Optional_Self2Id] AS [OneToOne_Optional_Self2Id0] + FROM [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[OneToOne_Optional_PK_Inverse2Id] +) AS [s] +"""); + } + + public override async Task Include_with_all_method_include_gets_ignored(bool isAsnc) + { + await base.Include_with_all_method_include_gets_ignored(isAsnc); + + AssertSql( + """ +SELECT CASE + WHEN NOT EXISTS ( + SELECT 1 + FROM [LevelOne] AS [l] + WHERE [l].[Name] = N'Foo') THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +"""); + } + + 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 [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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + public override async Task Join_with_navigations_in_the_result_selector2(bool async) + { + 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] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l2] ON [l0].[Id] = [l2].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Id], [l0].[Id], [l1].[Id] +"""); + } + + public override async Task Member_pushdown_chain_3_levels_deep(bool async) + { + 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] +FROM [LevelOne] AS [l] +WHERE ( + SELECT TOP(1) ( + SELECT TOP(1) ( + SELECT TOP(1) [l2].[Name] + FROM [LevelFour] AS [l2] + WHERE [l2].[Level3_Required_Id] = [l1].[Id] + ORDER BY [l2].[Id]) + FROM [LevelThree] AS [l1] + WHERE [l1].[Level2_Required_Id] = [l0].[Id] + ORDER BY [l1].[Id]) + FROM [LevelTwo] AS [l0] + WHERE [l0].[Level1_Optional_Id] = [l].[Id] + ORDER BY [l0].[Id]) <> N'Foo' OR ( + SELECT TOP(1) ( + SELECT TOP(1) ( + SELECT TOP(1) [l2].[Name] + FROM [LevelFour] AS [l2] + WHERE [l2].[Level3_Required_Id] = [l1].[Id] + ORDER BY [l2].[Id]) + FROM [LevelThree] AS [l1] + WHERE [l1].[Level2_Required_Id] = [l0].[Id] + ORDER BY [l1].[Id]) + FROM [LevelTwo] AS [l0] + WHERE [l0].[Level1_Optional_Id] = [l].[Id] + ORDER BY [l0].[Id]) IS NULL +ORDER BY [l].[Id] +"""); + } + + public override async Task Member_pushdown_chain_3_levels_deep_entity(bool async) + { + await base.Member_pushdown_chain_3_levels_deep_entity(async); + + AssertSql( + """ +SELECT [l4].[c], [l6].[c], [l8].[Id], [l8].[Level3_Optional_Id], [l8].[Level3_Required_Id], [l8].[Name], [l8].[OneToMany_Optional_Inverse4Id], [l8].[OneToMany_Optional_Self_Inverse4Id], [l8].[OneToMany_Required_Inverse4Id], [l8].[OneToMany_Required_Self_Inverse4Id], [l8].[OneToOne_Optional_PK_Inverse4Id], [l8].[OneToOne_Optional_Self4Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l3].[c], [l3].[Id], [l3].[Level1_Optional_Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[Level1_Optional_Id], ROW_NUMBER() OVER(PARTITION BY [l0].[Level1_Optional_Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + ) AS [l3] + WHERE [l3].[row] <= 1 +) AS [l4] ON [l].[Id] = [l4].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l5].[c], [l5].[Id], [l5].[Level2_Required_Id] + FROM ( + SELECT 1 AS [c], [l1].[Id], [l1].[Level2_Required_Id], ROW_NUMBER() OVER(PARTITION BY [l1].[Level2_Required_Id] ORDER BY [l1].[Id]) AS [row] + FROM [LevelThree] AS [l1] + ) AS [l5] + WHERE [l5].[row] <= 1 +) AS [l6] ON [l4].[Id] = [l6].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level3_Optional_Id], [l7].[Level3_Required_Id], [l7].[Name], [l7].[OneToMany_Optional_Inverse4Id], [l7].[OneToMany_Optional_Self_Inverse4Id], [l7].[OneToMany_Required_Inverse4Id], [l7].[OneToMany_Required_Self_Inverse4Id], [l7].[OneToOne_Optional_PK_Inverse4Id], [l7].[OneToOne_Optional_Self4Id] + FROM ( + 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], ROW_NUMBER() OVER(PARTITION BY [l2].[Level3_Required_Id] ORDER BY [l2].[Id]) AS [row] + FROM [LevelFour] AS [l2] + ) AS [l7] + WHERE [l7].[row] <= 1 +) AS [l8] ON [l6].[Id] = [l8].[Level3_Required_Id] +ORDER BY [l].[Id] +"""); + } + + 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( + """ +SELECT ( + SELECT TOP(1) ( + SELECT TOP(1) ( + SELECT TOP(1) [l2].[Name] + FROM [LevelFour] AS [l2] + WHERE [l2].[Level3_Required_Id] = [l1].[Id] + ORDER BY [l2].[Id]) + FROM [LevelThree] AS [l1] + WHERE [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id]) + FROM [LevelTwo] AS [l0] + WHERE [l0].[Level1_Required_Id] = [l].[Id] + ORDER BY [l0].[Id]) +FROM [LevelOne] AS [l] +ORDER BY [l].[Id] +"""); + } + + 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].[Name] + FROM [LevelThree] AS [l0] + WHERE ( + SELECT TOP(1) [l1].[Id] + FROM [LevelTwo] AS [l1] + WHERE [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ORDER BY [l1].[Id]) IS NOT NULL AND (( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY [l2].[Id]) = [l0].[OneToMany_Optional_Inverse3Id] OR (( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY [l2].[Id]) IS NULL AND [l0].[OneToMany_Optional_Inverse3Id] IS NULL)) + ORDER BY [l0].[Id]) +FROM [LevelOne] AS [l] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToOne_Optional_PK_Inverse4Id] +WHERE [l2].[Name] = N'L4 01' +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +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].[Level2_Optional_Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[OneToOne_Optional_PK_Inverse4Id] +WHERE CASE + WHEN [l0].[Id] IS NULL THEN NULL + WHEN [l1].[Id] IS NULL THEN NULL + ELSE [l2].[Name] +END = N'L4 01' +"""); + } + + public override async Task Union_over_entities_with_different_nullability(bool async) + { + await base.Union_over_entities_with_different_nullability(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +UNION ALL +SELECT [l2].[Id] +FROM [LevelTwo] AS [l1] +LEFT JOIN [LevelOne] AS [l2] ON [l1].[Level1_Optional_Id] = [l2].[Id] +WHERE [l2].[Id] IS NULL +"""); + } + + 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], [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], [l4].[Id], [l4].[Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Optional_Self_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToMany_Required_Self_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id], [l4].[OneToOne_Optional_Self2Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[OneToMany_Required_Inverse2Id] +LEFT JOIN ( + SELECT [l3].[Id], [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] + FROM ( + 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], ROW_NUMBER() OVER(PARTITION BY [l2].[OneToMany_Required_Inverse2Id] ORDER BY [l2].[Id] DESC) AS [row] + FROM [LevelTwo] AS [l2] + ) AS [l3] + WHERE [l3].[row] <= 1 +) AS [l4] ON [l].[Id] = [l4].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [l0].[Id] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +ORDER BY ( + SELECT COUNT(*) + FROM [LevelThree] AS [l2] + WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l2].[OneToMany_Required_Inverse3Id]), [l1].[Name] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Id] IS NOT NULL AND [l0].[Name] = N'L2 01' +"""); + } + + 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 [LevelOne] 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +WHERE [l].[Id] > ( + SELECT COALESCE(SUM([l0].[Id]), 0) + FROM [LevelTwo] AS [l0] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id]) +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l].[Id] + 7 = [l0].[Id] +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +INNER JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +LEFT JOIN [LevelOne] AS [l3] ON [l0].[Id] >= [l3].[Id] AND ([l2].[Name] = [l3].[Name] OR ([l2].[Name] IS NULL AND [l3].[Name] 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 [s0].[l1Name], [s0].[l2Name], [s0].[l3Name] +FROM [LevelOne] AS [l] +OUTER APPLY ( + SELECT [s].[l1Name], [s].[l2Name], [s].[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] IS NOT NULL AND [l1].[Id] = [l2].[OneToMany_Optional_Inverse4Id] + ) AS [s] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +) AS [s0] +"""); + } + + 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 [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + WHERE [l0].[Id] IS NULL) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +"""); + } + + 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 [LevelOne] AS [l] + LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + WHERE [l0].[Id] IS NULL) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +"""); + } + + 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], [l0].[Name] AS [OptionalName], CASE + WHEN EXISTS ( + SELECT 1 + FROM [LevelOne] AS [l1] + LEFT JOIN [LevelTwo] AS [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id] + WHERE [l2].[Name] = [l0].[Name] OR ([l2].[Name] IS NULL AND [l0].[Name] IS NULL)) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Contains] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +"""); + } + + 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], [l0].[Name] AS [OptionalName], CASE + WHEN EXISTS ( + SELECT 1 + FROM [LevelOne] AS [l2] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Level1_Optional_Id] + WHERE [l3].[Id] = [l1].[Id] OR ([l3].[Id] IS NULL AND [l1].[Id] IS NULL)) THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Contains] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[OneToOne_Optional_PK_Inverse2Id] +"""); + } + + 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 [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] +HAVING ( + SELECT MIN(COALESCE([l5].[Id], 0) + COALESCE([l5].[Id], 0)) + FROM [LevelOne] AS [l2] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Id] + LEFT JOIN [LevelThree] AS [l4] ON [l3].[Id] = [l4].[Id] + LEFT JOIN [LevelTwo] AS [l5] ON [l2].[Id] = [l5].[Id] + WHERE [l1].[Name] = [l4].[Name] OR ([l1].[Name] IS NULL AND [l4].[Name] IS NULL)) > 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], [l0].[Id], [l1].[Name], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([l].[Name]) AS int)), 0) AS [Aggregate] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE [l0].[Id] IS NOT NULL +GROUP BY [l].[Id], [l].[Date], [l].[Name], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l1].[Name] +"""); + } + + public override async Task GroupBy_aggregate_where_required_relationship(bool async) + { + await base.GroupBy_aggregate_where_required_relationship(async); + + AssertSql( + """ +SELECT [l0].[Id] AS [Key], MAX([l].[Id]) AS [Max] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Required_Inverse2Id] = [l0].[Id] +GROUP BY [l0].[Id] +HAVING MAX([l].[Id]) <> 2 OR MAX([l].[Id]) IS NULL +"""); + } + + public override async Task GroupBy_aggregate_where_required_relationship_2(bool async) + { + await base.GroupBy_aggregate_where_required_relationship_2(async); + + AssertSql( + """ +SELECT [l0].[Id] AS [Key], MAX([l].[Id]) AS [Max] +FROM [LevelTwo] AS [l] +INNER JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Required_Inverse2Id] = [l0].[Id] +GROUP BY [l0].[Id] +HAVING MAX([l].[Id]) < 2 OR MAX([l].[Id]) > 2 +"""); + } + + 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 [l0].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, [l0].[Id], [l0].[Name] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +ORDER BY [l0].[Name], [l].[Id] +"""); + } + + 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 [l0].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, [l0].[Id], [l0].[Name], CASE + WHEN [l1].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, [l1].[Id], [l1].[Name] +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].[Level2_Optional_Id] +WHERE CASE + WHEN [l0].[Id] IS NULL THEN NULL + ELSE [l1].[Name] +END <> N'L' OR CASE + WHEN [l0].[Id] IS NULL THEN NULL + ELSE [l1].[Name] +END IS NULL +"""); + } + + 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], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l2].[Id], [l3].[Id], [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], [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] +FROM [LevelOne] AS [l] +OUTER APPLY ( + 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 [LevelThree] AS [l0] + WHERE [l0].[Level2_Required_Id] IN ( + SELECT [l1].[Id] + FROM [LevelTwo] AS [l1] + WHERE [l].[Id] = [l1].[OneToMany_Required_Inverse2Id] + ) +) AS [l2] +LEFT JOIN [LevelTwo] AS [l3] ON [l].[Id] = [l3].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [l2].[Id] +"""); + } + + public override async Task Multiple_conditionals_in_projection(bool async) + { + await base.Multiple_conditionals_in_projection(async); + + AssertSql( + """ +SELECT [l].[Id], [l0].[Name], CASE + WHEN [l1].[Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelThree] AS [l0] ON [l].[Id] = [l0].[Level2_Optional_Id] +LEFT JOIN [LevelOne] AS [l1] ON [l].[Level1_Optional_Id] = [l1].[Id] +"""); + } + + 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 [l2].[Key] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l1].[Key], COALESCE(SUM([l1].[Id]), 0) AS [Sum] + FROM ( + SELECT [l0].[Id], [l0].[Id] % 3 AS [Key] + FROM [LevelTwo] AS [l0] + ) AS [l1] + GROUP BY [l1].[Key] +) AS [l2] ON [l].[Id] = [l2].[Key] AND [l2].[Sum] > 10 +"""); + } + + public override async Task Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key2(bool async) + { + await base.Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key2(async); + + AssertSql( + """ +SELECT [l2].[Key] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l1].[Key], COALESCE(SUM([l1].[Id]), 0) AS [Sum] + FROM ( + SELECT [l0].[Id], [l0].[Id] % 3 AS [Key] + FROM [LevelTwo] AS [l0] + ) AS [l1] + GROUP BY [l1].[Key] +) AS [l2] ON [l].[Id] = [l2].[Key] AND CASE + WHEN [l2].[Sum] <= 10 THEN CAST(0 AS bit) + ELSE CAST(1 AS bit) +END = CAST(1 AS bit) +"""); + } + + 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 [l0].[Id] IS NULL THEN N'Foo' + ELSE N'Bar' +END AS [Foo] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l1].[Name] AS [Key], COUNT(*) AS [Count] + FROM [LevelThree] AS [l1] + GROUP BY [l1].[Name] +) AS [l2] ON [l].[Name] = [l2].[Key] +WHERE [l0].[Name] IS NOT NULL OR [l2].[Count] > 0 +"""); + } + + 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].[Name] + FROM [LevelTwo] AS [l0] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] AND [l0].[Name] = N'L2 02') AS [Pushdown] +FROM [LevelOne] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + 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], [s0].[Id], [s0].[Level2_Optional_Id], [s0].[Level2_Required_Id], [s0].[Name], [s0].[OneToMany_Optional_Inverse3Id], [s0].[OneToMany_Optional_Self_Inverse3Id], [s0].[OneToMany_Required_Inverse3Id], [s0].[OneToMany_Required_Self_Inverse3Id], [s0].[OneToOne_Optional_PK_Inverse3Id], [s0].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [s].[Id], [s].[Level2_Optional_Id], [s].[Level2_Required_Id], [s].[Name], [s].[OneToMany_Optional_Inverse3Id], [s].[OneToMany_Optional_Self_Inverse3Id], [s].[OneToMany_Required_Inverse3Id], [s].[OneToMany_Required_Self_Inverse3Id], [s].[OneToOne_Optional_PK_Inverse3Id], [s].[OneToOne_Optional_Self3Id], [s].[OneToMany_Optional_Inverse2Id] + 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], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l1].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] + WHERE [l0].[Name] = N'L2 02' + ) AS [s] + WHERE [s].[row] <= 1 +) AS [s0] ON [l].[Id] = [s0].[OneToMany_Optional_Inverse2Id] +WHERE [l].[Id] < 3 +"""); + } + + 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], [l3].[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], [l3].[c] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l2].[c], [l2].[Id], [l2].[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'L2 02' + ) AS [l2] + WHERE [l2].[row] <= 1 +) AS [l3] ON [l].[Id] = [l3].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] AS [l1] ON [l3].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +WHERE [l].[Id] < 2 +ORDER BY [l].[Id], [l3].[Id] +"""); + } + + 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].[Name] + FROM [LevelThree] AS [l0] + WHERE ( + SELECT TOP(1) [l1].[Id] + FROM [LevelTwo] AS [l1] + WHERE [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] AND [l1].[Name] = N'L2 02') IS NOT NULL AND (( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Name] = N'L2 02') = [l0].[OneToMany_Optional_Inverse3Id] OR (( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Name] = N'L2 02') IS NULL AND [l0].[OneToMany_Optional_Inverse3Id] IS NULL)) + ORDER BY [l0].[Id]) AS [Pushdown] +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) + { + await base.Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id1] AS [Foo], [s].[Id2] AS [Bar], [s].[Id3] AS [Baz] +FROM ( + SELECT DISTINCT TOP(@__p_0) [l].[Id] AS [Id1], [l0].[Id] AS [Id2], [l1].[Id] AS [Id3], [l].[Name] AS [Name1], [l0].[Name] AS [Name2] + FROM [LevelOne] AS [l] + INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] + INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +) AS [s] +"""); + } + + 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 SelectMany_without_collection_selector_returning_queryable(bool async) + { + await base.SelectMany_without_collection_selector_returning_queryable(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] +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 [l1] +"""); + } + + 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 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 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 [l2].[Id], [l2].[Date], [l2].[Name], [l2].[OneToMany_Optional_Self_Inverse1Id], [l2].[OneToMany_Required_Self_Inverse1Id], [l2].[OneToOne_Optional_Self1Id] +FROM ( + SELECT 1 AS empty +) AS [e] +LEFT JOIN ( + SELECT [l].[Level1_Required_Id] + FROM [LevelTwo] AS [l] + WHERE [l].[Id] < 5 +) AS [l0] ON 1 = 1 +CROSS APPLY ( + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id] + FROM [LevelOne] AS [l1] + WHERE [l1].[Id] <> COALESCE([l0].[Level1_Required_Id], 0) +) AS [l2] +"""); + } + + 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 [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id] +"""); + } + + 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], [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] +GROUP BY [l1].[Name] +HAVING ( + SELECT MIN(COALESCE([l5].[Id], 0)) + FROM [LevelOne] AS [l2] + LEFT JOIN [LevelTwo] AS [l3] ON [l2].[Id] = [l3].[Id] + LEFT JOIN [LevelThree] AS [l4] ON [l3].[Id] = [l4].[Id] + LEFT JOIN [LevelTwo] AS [l5] ON [l2].[Id] = [l5].[Id] + WHERE [l1].[Name] = [l4].[Name] OR ([l1].[Name] IS NULL AND [l4].[Name] IS NULL)) > 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_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] +"""); + } + + 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] +"""); + } + + 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] +"""); + } + + 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_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_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] +"""); + } + + public override async Task Multiple_required_navigation_using_multiple_selects_with_EF_Property_Include(bool async) + { + await base.Multiple_required_navigation_using_multiple_selects_with_EF_Property_Include(async); + + AssertSql(); + } + + public override async Task SelectMany_with_EF_Property_Include1(bool async) + { + await base.SelectMany_with_EF_Property_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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] +"""); + } + + public override async Task Multiple_SelectMany_with_EF_Property_Include(bool async) + { + await base.Multiple_SelectMany_with_EF_Property_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], [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] +INNER JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +"""); + } + + public override async Task Multiple_required_navigation_with_EF_Property_Include(bool async) + { + await base.Multiple_required_navigation_with_EF_Property_Include(async); + + AssertSql(); + } + + public override async Task GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure(bool async) + { + await base.GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], [l1].[Id] AS [Id2] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] <> @__prm_0 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_with_predicate_using_closure(bool async) + { + await base.GroupJoin_SelectMany_with_predicate_using_closure(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], [l1].[Id] AS [Id2] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] <> @__prm_0 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested(bool async) + { + await base.GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested(async); + + AssertSql( + """ +@__prm1_0='10' +@__prm2_1='20' + +SELECT [l].[Id] AS [Id1], [l1].[Id] AS [Id2], [l3].[Id] AS [Id3] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] <> @__prm1_0 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id] + FROM [LevelThree] AS [l2] + WHERE [l2].[Id] <> @__prm2_1 +) AS [l3] ON [l1].[Id] = [l3].[Level2_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_with_predicate_using_closure_nested(bool async) + { + await base.GroupJoin_SelectMany_with_predicate_using_closure_nested(async); + + AssertSql( + """ +@__prm1_0='10' +@__prm2_1='20' + +SELECT [l].[Id] AS [Id1], [l1].[Id] AS [Id2], [l3].[Id] AS [Id3] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] <> @__prm1_0 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id] + FROM [LevelThree] AS [l2] + WHERE [l2].[Id] <> @__prm2_1 +) AS [l3] ON [l1].[Id] = [l3].[Level2_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested_same_param(bool async) + { + await base.GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested_same_param(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], [l1].[Id] AS [Id2], [l3].[Id] AS [Id3] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] <> @__prm_0 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id] + FROM [LevelThree] AS [l2] + WHERE [l2].[Id] <> @__prm_0 +) AS [l3] ON [l1].[Id] = [l3].[Level2_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_with_predicate_using_closure_nested_same_param(bool async) + { + await base.GroupJoin_SelectMany_with_predicate_using_closure_nested_same_param(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], [l1].[Id] AS [Id2], [l3].[Id] AS [Id3] +FROM [LevelOne] AS [l] +INNER JOIN ( + SELECT [l0].[Id], [l0].[Level1_Optional_Id] + FROM [LevelTwo] AS [l0] + WHERE [l0].[Id] <> @__prm_0 +) AS [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id] + FROM [LevelThree] AS [l2] + WHERE [l2].[Id] <> @__prm_0 +) AS [l3] ON [l1].[Id] = [l3].[Level2_Optional_Id] +"""); + } + + public override async Task Multiple_optional_navs_should_not_deadlock(bool async) + { + await base.Multiple_optional_navs_should_not_deadlock(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [LevelTwo] AS [l] +LEFT JOIN [LevelOne] AS [l0] ON [l].[OneToMany_Optional_Inverse2Id] = [l0].[Id] +LEFT JOIN [LevelOne] AS [l1] ON [l].[Level1_Optional_Id] = [l1].[Id] +WHERE ([l0].[Id] IS NOT NULL AND [l0].[Name] LIKE N'%L1 01%') OR ([l1].[Id] IS NOT NULL AND [l1].[Name] LIKE N'%L1 01%') +"""); + } + + public override async Task Null_check_removal_applied_recursively_complex(bool async) + { + await base.Null_check_removal_applied_recursively_complex(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Optional_Self_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToMany_Required_Self_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[OneToOne_Optional_Self3Id], [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].[Name], [l1].[OneToMany_Optional_Self_Inverse1Id], [l1].[OneToMany_Required_Self_Inverse1Id], [l1].[OneToOne_Optional_Self1Id], [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 [LevelThree] AS [l] +INNER JOIN [LevelTwo] AS [l0] ON [l].[OneToMany_Required_Inverse3Id] = [l0].[Id] +INNER JOIN [LevelOne] AS [l1] ON [l0].[OneToMany_Required_Inverse2Id] = [l1].[Id] +LEFT JOIN [LevelFour] AS [l2] ON [l].[Id] = [l2].[OneToMany_Optional_Inverse4Id] +WHERE [l1].[Name] = N'L1 01' +ORDER BY [l].[Id], [l0].[Id], [l1].[Id] +"""); + } + + public override async Task Correlated_projection_with_first(bool async) + { + await base.Correlated_projection_with_first(async); + + AssertSql( + """ +SELECT [l].[Id], [s].[Id], [s].[Id0] +FROM [LevelOne] AS [l] +OUTER APPLY ( + SELECT [l3].[Id], [l0].[Id] AS [Id0] + FROM [LevelThree] AS [l0] + LEFT JOIN [LevelFour] AS [l3] ON [l0].[Id] = [l3].[Level3_Required_Id] + WHERE ( + SELECT TOP(1) [l1].[Id] + FROM [LevelTwo] AS [l1] + WHERE [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ORDER BY [l1].[Id]) IS NOT NULL AND (( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY [l2].[Id]) = [l0].[OneToMany_Optional_Inverse3Id] OR (( + SELECT TOP(1) [l2].[Id] + FROM [LevelTwo] AS [l2] + WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY [l2].[Id]) IS NULL AND [l0].[OneToMany_Optional_Inverse3Id] IS NULL)) +) AS [s] +ORDER BY [l].[Id], [s].[Id0] +"""); + } + + public override async Task Max_in_multi_level_nested_subquery(bool async) + { + await base.Max_in_multi_level_nested_subquery(async); + + AssertSql( + """ +@__p_0='2' + +SELECT [l4].[Id], [s].[Id], [s].[Id0], [s].[Id1], [s].[Result] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [LevelOne] AS [l] + ORDER BY [l].[Id] +) AS [l4] +LEFT JOIN ( + SELECT [l0].[Id], [l1].[Id] AS [Id0], [l2].[Id] AS [Id1], CASE + WHEN COALESCE(( + SELECT MAX([l3].[Id]) + FROM [LevelFour] AS [l3] + WHERE [l1].[Id] IS NOT NULL AND [l1].[Id] = [l3].[OneToMany_Optional_Inverse4Id]), 0) > 1 THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [Result], [l0].[OneToMany_Optional_Inverse2Id] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Required_Id] + LEFT JOIN [LevelFour] AS [l2] ON [l1].[Id] = [l2].[Level3_Required_Id] +) AS [s] ON [l4].[Id] = [s].[OneToMany_Optional_Inverse2Id] +ORDER BY [l4].[Id], [s].[Id], [s].[Id0] +"""); + } + + public override async Task Multiple_select_many_in_projection(bool async) + { + await base.Multiple_select_many_in_projection(async); + + AssertSql( + """ +SELECT [l].[Id], [s0].[Id], [s0].[RefId], [s0].[Id0], ( + SELECT COUNT(*) + FROM [LevelTwo] AS [l3] + INNER JOIN [LevelThree] AS [l4] ON [l3].[Id] = [l4].[OneToMany_Optional_Inverse3Id] + WHERE [l].[Id] = [l3].[OneToMany_Optional_Inverse2Id] AND ([l4].[Name] <> N'' OR [l4].[Name] IS NULL)) +FROM [LevelOne] AS [l] +OUTER APPLY ( + SELECT [s].[Id0] AS [Id], [l2].[Id] AS [RefId], [s].[Id] AS [Id0] + FROM ( + SELECT TOP(12) [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] + ORDER BY [l1].[Id] + ) AS [s] + LEFT JOIN [LevelFour] AS [l2] ON [s].[Id0] = [l2].[Level3_Optional_Id] +) AS [s0] +ORDER BY [l].[Id], [s0].[Id], [s0].[Id0] +"""); + } + + public override async Task Single_select_many_in_projection_with_take(bool async) + { + await base.Single_select_many_in_projection_with_take(async); + + AssertSql( + """ +SELECT [l].[Id], [s0].[Id], [s0].[RefId], [s0].[Id0] +FROM [LevelOne] AS [l] +OUTER APPLY ( + SELECT [s].[Id0] AS [Id], [l2].[Id] AS [RefId], [s].[Id] AS [Id0] + FROM ( + SELECT TOP(12) [l0].[Id], [l1].[Id] AS [Id0] + FROM [LevelTwo] AS [l0] + INNER JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] + WHERE [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] + ORDER BY [l1].[Id] + ) AS [s] + LEFT JOIN [LevelFour] AS [l2] ON [s].[Id0] = [l2].[Level3_Optional_Id] +) AS [s0] +ORDER BY [l].[Id], [s0].[Id], [s0].[Id0] +"""); + } + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + + public class Fixture160 : ComplexNavigationsQuerySqlServerFixture + { + protected override string StoreName + => "ComplexNavigations160"; + + public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) + => base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160)); + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index 9a04d360e86..e81cf662e67 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -3122,14 +3122,13 @@ FROM [InheritanceOne] AS [i3] """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] 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 GREATEST([l0].[Level1_Required_Id], 7) +SELECT [l0].[Level1_Required_Id] FROM [LevelOne] AS [l] LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToOne_Optional_PK_Inverse2Id] WHERE [l0].[Id] IS NOT NULL diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServer160Test.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServer160Test.cs new file mode 100644 index 00000000000..83800b92c3b --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServer160Test.cs @@ -0,0 +1,8531 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable +using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel; +using Xunit.Sdk; + +namespace Microsoft.EntityFrameworkCore.Query; + +[SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] +public class ComplexNavigationsSharedTypeQuerySqlServer160Test + : ComplexNavigationsSharedTypeQueryRelationalTestBase +{ + public ComplexNavigationsSharedTypeQuerySqlServer160Test(Fixture160 fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_skip_without_orderby(bool async) + { + await 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); + + AssertSql( + """ +SELECT ( + SELECT TOP(1) [s0].[Level3_Name] + FROM ( + SELECT [s].[Id], [s].[Level2_Required_Id], [s].[Level3_Name], [s].[OneToMany_Required_Inverse3Id] + FROM ( + SELECT DISTINCT [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 [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON 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 = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + 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 [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] + ORDER BY (SELECT 1) + OFFSET 1 ROWS + ) AS [s0] + ORDER BY CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id] + END) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Distinct_take_without_orderby(bool async) + { + await 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); + + AssertSql( + """ +SELECT ( + SELECT TOP(1) [s].[Level3_Name] + FROM ( + SELECT DISTINCT TOP(1) [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 [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON 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 = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + 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 [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] + ORDER BY CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id] + END) +FROM [Level1] AS [l] +WHERE [l].[Id] < 3 +"""); + } + + public override async Task Simple_level1_include(bool async) + { + await base.Simple_level1_include(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +"""); + } + + public override async Task Simple_level1(bool async) + { + await base.Simple_level1(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name] +FROM [Level1] 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], [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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +"""); + } + + public override async Task Simple_level1_level2_GroupBy_Count(bool async) + { + await base.Simple_level1_level2_GroupBy_Count(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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +GROUP BY [l3].[Level3_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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +GROUP BY [l3].[Level3_Name] +HAVING ( + SELECT MIN(COALESCE(CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END, 0)) + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l5] ON [l4].[Id] = 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 + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Required_Id], [l8].[Level3_Name], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + LEFT JOIN ( + SELECT [l9].[Id], [l9].[OneToOne_Required_PK_Date], [l9].[Level1_Required_Id], [l9].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l9] + 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 [l10] ON [l4].[Id] = CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END + WHERE [l3].[Level3_Name] = [l7].[Level3_Name] OR ([l3].[Level3_Name] IS NULL AND [l7].[Level3_Name] IS NULL)) > 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], [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], [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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] +END +"""); + } + + public override async Task Nested_group_join_with_take(bool async) + { + await base.Nested_group_join_with_take(async); + + AssertSql( + """ +@__p_0='2' + +SELECT [s1].[Level2_Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id], [s].[Id0] AS [Id00], [s].[OneToOne_Required_PK_Date], [s].[Level1_Required_Id], [s].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s0] +LEFT JOIN ( + SELECT [l5].[Level1_Optional_Id], [l5].[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] + 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 [l5] ON [l3].[Id] = 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 + 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 [s1] ON CASE + WHEN [s0].[OneToOne_Required_PK_Date] IS NOT NULL AND [s0].[Level1_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s0].[Id00] +END = [s1].[Level1_Optional_Id] +ORDER BY [s0].[Id] +"""); + } + + public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_projection2(bool async) + { + await base.Explicit_GroupJoin_in_subquery_with_unrelated_projection2(async); + + AssertSql( + """ +SELECT [s0].[Id] +FROM ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + WHERE [s].[Level2_Name] <> N'Foo' OR [s].[Level2_Name] IS NULL +) AS [s0] +"""); + } + + public override async Task Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(bool async) + { + await base.Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(async); + + AssertSql( + """ +SELECT COALESCE(SUM(CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NULL OR [s].[Level1_Required_Id] IS NULL OR [s].[OneToMany_Required_Inverse2Id] IS NULL THEN 0 + ELSE [s].[Level1_Required_Id] +END), 0) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[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 [l1].[OneToOne_Required_PK_Date] IS NULL OR [l1].[Level1_Required_Id] IS NULL OR [l1].[OneToMany_Required_Inverse2Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END, [l1].[Level2_Name], CASE + WHEN [l3].[Level2_Required_Id] IS NULL OR [l3].[OneToMany_Required_Inverse3Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END, [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NULL OR [l1].[Level1_Required_Id] IS NULL OR [l1].[OneToMany_Required_Inverse2Id] IS NULL THEN NULL + ELSE [l3].[Level3_Name] +END <> N'L' OR CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NULL OR [l1].[Level1_Required_Id] IS NULL OR [l1].[OneToMany_Required_Inverse2Id] IS NULL THEN NULL + ELSE [l3].[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 [s0].[l1Name], [s0].[l2Name], [s0].[l3Name] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT [s].[l1Name], [s].[l2Name], [s].[l3Name] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Required_Id], [l1].[Level3_Name], [l1].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l2] 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 [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END + CROSS APPLY ( + SELECT [l].[Name] AS [l1Name], [l2].[Level3_Name] AS [l2Name], [l5].[Level3_Name] AS [l3Name] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level2_Required_Id], [l4].[Level3_Name], [l4].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l5] ON [l3].[OneToOne_Optional_PK_Inverse4Id] = CASE + WHEN [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l5].[Id] + END + WHERE [l3].[Level3_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse4Id] IS NOT NULL AND CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END IS NOT NULL AND (CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END = [l3].[OneToMany_Optional_Inverse4Id] OR (CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END IS NULL AND [l3].[OneToMany_Optional_Inverse4Id] IS NULL)) + ) AS [s] + WHERE [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 [s0] +"""); + } + + 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +ORDER BY ( + SELECT COUNT(*) + FROM [Level1] AS [l4] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END = [l4].[OneToMany_Required_Inverse3Id]), [l3].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +GROUP BY [l3].[Level3_Name] +HAVING ( + SELECT MIN(COALESCE(CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END, 0) + COALESCE(CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END, 0)) + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l5] ON [l4].[Id] = 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 + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Required_Id], [l8].[Level3_Name], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + LEFT JOIN ( + SELECT [l9].[Id], [l9].[OneToOne_Required_PK_Date], [l9].[Level1_Required_Id], [l9].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l9] + 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 [l10] ON [l4].[Id] = CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END + WHERE [l3].[Level3_Name] = [l7].[Level3_Name] OR ([l3].[Level3_Name] IS NULL AND [l7].[Level3_Name] IS NULL)) > 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] + WHERE [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 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], [s].[Id0], [s].[Id1], [s].[Id], [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], [s].[Level2_Optional_Id], [s].[Level2_Required_Id], [s].[Level3_Name], [s].[OneToMany_Optional_Inverse3Id], [s].[OneToMany_Required_Inverse3Id], [s].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +OUTER APPLY ( + 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], [l0].[Id] AS [Id0], [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] + 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 [l2] ON [l0].[Id] = 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 + 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] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON 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 = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + 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 [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l4].[Level2_Required_Id] IN ( + SELECT 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] + 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_Required_Inverse2Id] + ) +) AS [s] +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] + FROM [Level1] AS [l6] + 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 [l7] ON [l].[Id] = [l7].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [s].[Id0], [s].[Id1], [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l4].[Level4_Name], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[OneToOne_Optional_PK_Inverse4Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NULL OR [l1].[Level1_Required_Id] IS NULL OR [l1].[OneToMany_Required_Inverse2Id] IS NULL THEN NULL + WHEN [l3].[Level2_Required_Id] IS NULL OR [l3].[OneToMany_Required_Inverse3Id] IS NULL THEN NULL + ELSE [l5].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_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 AND [l1].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END, [l3].[Level3_Name], CASE + WHEN [l4].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +LEFT JOIN [Level1] AS [l4] ON [l1].[Level1_Optional_Id] = [l4].[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 +"""); + } + + 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 [s].[OneToOne_Required_PK_Date] IS NULL OR [s].[Level1_Required_Id] IS NULL OR [s].[OneToMany_Required_Inverse2Id] IS NULL THEN N'Foo' + ELSE N'Bar' +END AS [Foo] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + GROUP BY [l7].[Level3_Name] +) AS [s0] ON [l].[Name] = [s0].[Key] +WHERE [s].[Level2_Name] IS NOT NULL OR [s0].[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 [s].[Id], [s].[Name], [s].[Date], [s].[InnerId] AS [Id], [s].[Level2_Name0] AS [Name], [s].[OneToOne_Required_PK_Date] AS [Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([s].[Name]) AS int)), 0) AS [Aggregate] +FROM ( + SELECT [l].[Id], [l].[Date], [l].[Name], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l3].[Level2_Name] AS [Level2_Name0], CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END AS [InnerId] + 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] + LEFT JOIN ( + SELECT [l2].[Level1_Required_Id], [l2].[Level2_Name] + FROM [Level1] AS [l2] + 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 [l3] ON [l].[Id] = [l3].[Level1_Required_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 [s] +GROUP BY [s].[Id], [s].[Date], [s].[Name], [s].[InnerId], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name0] +"""); + } + + 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].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] + WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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 [l1].[OneToOne_Required_PK_Date] IS NULL OR [l1].[Level1_Required_Id] IS NULL OR [l1].[OneToMany_Required_Inverse2Id] IS NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END, [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l].[Id] + 7 = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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 [s1].[Key] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [s].[Key], ( + SELECT COALESCE(SUM(CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END), 0) + FROM ( + SELECT [l3].[Id], 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 % 3 AS [Key] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + 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 [s0] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l7] ON [s0].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + WHERE [s].[Key] = [s0].[Key] OR ([s].[Key] IS NULL AND [s0].[Key] IS NULL)) AS [Sum] + FROM ( + 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 % 3 AS [Key] + 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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] + GROUP BY [s].[Key] +) AS [s1] ON [l].[Id] = [s1].[Key] AND [s1].[Sum] > 10 +"""); + } + + public override async Task Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key2(bool async) + { + await base.Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key2(async); + + AssertSql( + """ +SELECT [s1].[Key] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [s].[Key], ( + SELECT COALESCE(SUM(CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END), 0) + FROM ( + SELECT [l3].[Id], 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 % 3 AS [Key] + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + 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 [s0] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l7] ON [s0].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + WHERE [s].[Key] = [s0].[Key] OR ([s].[Key] IS NULL AND [s0].[Key] IS NULL)) AS [Sum] + FROM ( + 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 % 3 AS [Key] + 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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] + GROUP BY [s].[Key] +) AS [s1] ON [l].[Id] = [s1].[Key] AND CASE + WHEN [s1].[Sum] <= 10 THEN CAST(0 AS bit) + ELSE CAST(1 AS bit) +END = CAST(1 AS bit) +"""); + } + + 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], [l1].[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].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = [l6].[Level1_Optional_Id] + WHERE CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END OR (CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END IS NULL AND CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + 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 [l3] ON [l].[Id] = [l3].[OneToOne_Optional_PK_Inverse2Id] +"""); + } + + [ConditionalTheory()] + 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], ( + SELECT MAX(CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + LEFT JOIN [Level1] AS [l6] ON [l4].[OneToMany_Required_Inverse2Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l3].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 AND ([l2].[Id] = [l6].[Id] OR ([l2].[Id] IS NULL AND [l6].[Id] IS NULL))) 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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Required_Inverse2Id] = [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 +GROUP BY [l2].[Id] +HAVING ( + SELECT MAX(CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + LEFT JOIN [Level1] AS [l6] ON [l4].[OneToMany_Required_Inverse2Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l3].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 AND ([l2].[Id] = [l6].[Id] OR ([l2].[Id] IS NULL AND [l6].[Id] IS NULL))) < 2 OR ( + SELECT MAX(CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + LEFT JOIN [Level1] AS [l6] ON [l4].[OneToMany_Required_Inverse2Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l3].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 AND ([l2].[Id] = [l6].[Id] OR ([l2].[Id] IS NULL AND [l6].[Id] IS NULL))) > 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], [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], [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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + FROM [Level1] AS [l2] + 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 [l4] ON [l].[Id] = [l4].[OneToMany_Required_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] + FROM ( + 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], ROW_NUMBER() OVER(PARTITION BY [l3].[OneToMany_Required_Inverse2Id] ORDER BY CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END DESC) AS [row] + FROM [Level1] AS [l3] + 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 [l5] + WHERE [l5].[row] <= 1 +) AS [l6] ON [l].[Id] = [l6].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [l1].[Id] +"""); + } + + public override async Task Union_over_entities_with_different_nullability(bool async) + { + await base.Union_over_entities_with_different_nullability(async); + + AssertSql( + """ +SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +UNION ALL +SELECT [l6].[Id] +FROM [Level1] AS [l3] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Optional_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 [l6].[Id] IS NULL +"""); + } + + [ConditionalTheory()] + 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], ( + SELECT MAX(CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + LEFT JOIN [Level1] AS [l6] ON [l4].[OneToMany_Required_Inverse2Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l3].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 AND ([l2].[Id] = [l6].[Id] OR ([l2].[Id] IS NULL AND [l6].[Id] IS NULL))) 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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Required_Inverse2Id] = [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 +GROUP BY [l2].[Id] +HAVING ( + SELECT MAX(CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + LEFT JOIN [Level1] AS [l6] ON [l4].[OneToMany_Required_Inverse2Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l3].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 AND ([l2].[Id] = [l6].[Id] OR ([l2].[Id] IS NULL AND [l6].[Id] IS NULL))) <> 2 OR ( + SELECT MAX(CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) + FROM [Level1] AS [l3] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l4] ON [l3].[Id] = 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 + LEFT JOIN [Level1] AS [l6] ON [l4].[OneToMany_Required_Inverse2Id] = [l6].[Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l3].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 AND ([l2].[Id] = [l6].[Id] OR ([l2].[Id] IS NULL AND [l6].[Id] IS NULL))) 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], [l1].[Level2_Name] AS [OptionalName], CASE + WHEN EXISTS ( + SELECT 1 + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + 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 [l4] ON [l2].[Id] = [l4].[Level1_Optional_Id] + WHERE [l4].[Level2_Name] = [l1].[Level2_Name] OR ([l4].[Level2_Name] IS NULL AND [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [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 [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Required_Id] +INNER JOIN ( + SELECT [l7].[Id] AS [Id1], [l7].[Level2_Required_Id], [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [s0] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END = [s0].[Level2_Required_Id] +INNER JOIN ( + SELECT [l14].[Level3_Required_Id], [l14].[Level4_Name] + FROM [Level1] AS [l8] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[OneToOne_Required_PK_Date], [l9].[Level1_Required_Id], [l9].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l9] + 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 [l10] ON [l8].[Id] = CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END + LEFT JOIN ( + SELECT [l11].[Id], [l11].[Level2_Required_Id], [l11].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l11] + WHERE [l11].[Level2_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l12] ON CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END = CASE + WHEN [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l12].[Id] + END + LEFT JOIN ( + SELECT [l13].[Id], [l13].[Level3_Required_Id], [l13].[Level4_Name], [l13].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l13] + WHERE [l13].[Level3_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l14] ON CASE + WHEN [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l12].[Id] + END = CASE + WHEN [l14].[Level3_Required_Id] IS NOT NULL AND [l14].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l14].[Id] + END + 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 AND [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l14].[Level3_Required_Id] IS NOT NULL AND [l14].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [s1] ON CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id1] +END = [s1].[Level3_Required_Id] +LEFT JOIN [Level1] AS [l15] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END >= [l15].[Id] AND ([s1].[Level4_Name] = [l15].[Name] OR ([s1].[Level4_Name] IS NULL AND [l15].[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].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] + WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +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 +"""); + } + + 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Id] > 5 +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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 [l3].[Id], [l3].[Date], [l3].[Name] +FROM ( + SELECT 1 AS empty +) AS [e] +LEFT JOIN ( + SELECT [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END + 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 AND [l1].[Id] < 5 +) AS [s] ON 1 = 1 +CROSS APPLY ( + SELECT [l2].[Id], [l2].[Date], [l2].[Name] + FROM [Level1] AS [l2] + WHERE [l2].[Id] <> COALESCE([s].[Level1_Required_Id], 0) +) AS [l3] +"""); + } + + 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 [s1].[Id1] AS [Foo], [s1].[Id2] AS [Bar], [s1].[Id3] AS [Baz] +FROM ( + SELECT DISTINCT TOP(@__p_0) [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] + END AS [Id2], CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id1] + END AS [Id3], [l].[Name] AS [Name1], [s].[Level2_Name] AS [Name2] + FROM [Level1] AS [l] + INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[Level2_Name], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + INNER JOIN ( + SELECT [l7].[Id] AS [Id1], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s0] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] + END = [s0].[Level2_Optional_Id] +) AS [s1] +"""); + } + + 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] + WHERE [l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ( + SELECT TOP(1) CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END + FROM [Level1] AS [l1] + 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 AND [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] AND [l1].[Level2_Name] = N'L2 02') IS NOT NULL AND (( + SELECT TOP(1) 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 + FROM [Level1] AS [l2] + 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 [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[Level2_Name] = N'L2 02') = [l0].[OneToMany_Optional_Inverse3Id] OR (( + SELECT TOP(1) 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 + FROM [Level1] AS [l2] + 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 [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] AND [l2].[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], [l3].[Id], [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], [l3].[c] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[c], [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id], [l2].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [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]) AS [row] + FROM [Level1] AS [l0] + WHERE [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 [l2] + WHERE [l2].[row] <= 1 +) AS [l3] ON [l].[Id] = [l3].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Level3_Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l4] ON CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] +END = [l4].[OneToMany_Optional_Inverse3Id] +WHERE [l].[Id] < 2 +ORDER BY [l].[Id], [l3].[Id] +"""); + } + + 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], [s0].[Id], [s0].[Level2_Optional_Id], [s0].[Level2_Required_Id], [s0].[Level3_Name], [s0].[OneToMany_Optional_Inverse3Id], [s0].[OneToMany_Required_Inverse3Id], [s0].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [s].[Id], [s].[Level2_Optional_Id], [s].[Level2_Required_Id], [s].[Level3_Name], [s].[OneToMany_Optional_Inverse3Id], [s].[OneToMany_Required_Inverse3Id], [s].[OneToOne_Optional_PK_Inverse3Id], [s].[OneToMany_Optional_Inverse2Id] + 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], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id], [l2].[Id]) AS [row] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Level3_Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l2] 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 = [l2].[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 [s] + WHERE [s].[row] <= 1 +) AS [s0] ON [l].[Id] = [s0].[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 [s].[Id], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +CROSS 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 [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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] < 10 +) AS [s] +"""); + } + + public override async Task Null_reference_protection_complex_materialization(bool async) + { + await base.Null_reference_protection_complex_materialization(async); + + AssertSql( + """ +SELECT [s0].[Id00], [s0].[OneToOne_Required_PK_Date], [s0].[Level1_Optional_Id], [s0].[Level1_Required_Id], [s0].[Level2_Name], [s0].[OneToMany_Optional_Inverse2Id], [s0].[OneToMany_Required_Inverse2Id], [s0].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [s].[Id0] AS [Id00], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l7].[Id] AS [Id0], [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 [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] + FROM [Level1] AS [l6] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + 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 [s] ON [l4].[Id] = [s].[Level1_Optional_Id] +) AS [s0] ON [l3].[Level2_Required_Id] = CASE + WHEN [s0].[OneToOne_Required_PK_Date] IS NOT NULL AND [s0].[Level1_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s0].[Id00] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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 [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], [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[OneToMany_Required_Inverse4Id] +LEFT JOIN ( + SELECT [l8].[Id] AS [Id0], [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 [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] + 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 [l8] ON [l6].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 [s] ON CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] +END = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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], [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [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 [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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = COALESCE(( + 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 [l3] + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Id] = 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 + 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 + 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), 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], [s].[Level1_Optional_Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s0] +LEFT JOIN [Level1] AS [l3] ON [s0].[Level1_Optional_Id] = [l3].[Id] +ORDER BY [s0].[Id] +"""); + } + + public override async Task Null_reference_protection_complex(bool async) + { + await base.Null_reference_protection_complex(async); + + AssertSql( + """ +SELECT [s0].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [s].[Id0] AS [Id00], [s].[OneToOne_Required_PK_Date], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l7].[Id] AS [Id0], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[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] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + 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 [s] ON [l4].[Id] = [s].[Level1_Optional_Id] +) AS [s0] ON [l3].[Level2_Required_Id] = CASE + WHEN [s0].[OneToOne_Required_PK_Date] IS NOT NULL AND [s0].[Level1_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s0].[Id00] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE 6 IN ( + SELECT CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END + 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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NOT NULL AND (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id] OR (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)) + ) AS [l3] +) +"""); + } + + public override async Task Null_reference_protection_complex_client_eval(bool async) + { + await base.Null_reference_protection_complex_client_eval(async); + + AssertSql( + """ +SELECT [s0].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [s].[Id0] AS [Id00], [s].[OneToOne_Required_PK_Date], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l7].[Id] AS [Id0], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[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] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + 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 [s] ON [l4].[Id] = [s].[Level1_Optional_Id] +) AS [s0] ON [l3].[Level2_Required_Id] = CASE + WHEN [s0].[OneToOne_Required_PK_Date] IS NOT NULL AND [s0].[Level1_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s0].[Id00] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Id] > 5 +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE 5 IN ( + SELECT DISTINCT CAST(LEN([l2].[Level3_Name]) AS int) + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NOT NULL AND (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id] OR (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)) +) +"""); + } + + 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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + INNER JOIN [Level1] AS [l3] ON [l2].[Level1_Required_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 [s] ON [l].[Id] = [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Id] > 5 +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Required_Inverse3Id] +WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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) [l6].[Name] + 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] + 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 [l4] ON [l2].[Id] = 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 + INNER JOIN [Level1] AS [l5] ON [l4].[Level1_Required_Id] = [l5].[Id] + LEFT JOIN [Level1] AS [l6] ON [l4].[Level1_Required_Id] = [l6].[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 + 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) +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 AND [l1].[Id] = 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 [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], [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[OneToMany_Required_Inverse4Id] +INNER JOIN ( + SELECT [l8].[Id] AS [Id0], [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 [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] + 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 [l8] ON [l6].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + 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 [s] ON CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] +END = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 AND [l1].[Id] = 7 AND (( + SELECT TOP(1) [l5].[Name] + 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] + 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 [l4] ON [l2].[Id] = 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 + LEFT JOIN [Level1] AS [l5] ON [l4].[Level1_Required_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 + 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) = N'L1 10' OR ( + SELECT TOP(1) [l9].[Name] + FROM [Level1] AS [l6] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l6].[Id] = CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END + LEFT JOIN [Level1] AS [l9] ON [l8].[Level1_Required_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 + ORDER BY CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END) = N'L1 01') +"""); + } + + 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 [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +LEFT JOIN [Level1] AS [l3] ON [s].[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 [l6].[Id], [l6].[Date], [l6].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +LEFT JOIN [Level1] AS [l6] 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 = [l6].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l4].[Id] AS [Id0], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[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] + 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 [l4] ON [l2].[Id] = 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 + 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 [s] ON [l1].[Level1_Required_Id] = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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], [l1].[Level2_Name] AS [Brand] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [l1].[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 [l14].[Id], [l14].[Date], [l14].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Required_Id], [l4].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] +END +LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l7] ON [l5].[Level3_Required_Id] = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] +END +LEFT JOIN ( + SELECT [l8].[Id], [l8].[OneToOne_Required_PK_Date], [l8].[Level1_Required_Id], [l8].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l8] + 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 [l9] ON [l7].[Level2_Required_Id] = CASE + WHEN [l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l9].[Id] +END +LEFT JOIN ( + SELECT [l10].[Level2_Required_Id], [l10].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l10] + WHERE [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l11] ON CASE + WHEN [l9].[OneToOne_Required_PK_Date] IS NOT NULL AND [l9].[Level1_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l9].[Id] +END = [l11].[OneToMany_Required_Inverse3Id] +LEFT JOIN ( + SELECT [l12].[Id], [l12].[OneToOne_Required_PK_Date], [l12].[Level1_Required_Id], [l12].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l12] + 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 [l13] ON [l11].[Level2_Required_Id] = CASE + WHEN [l13].[OneToOne_Required_PK_Date] IS NOT NULL AND [l13].[Level1_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l13].[Id] +END +LEFT JOIN [Level1] AS [l14] ON CASE + WHEN [l13].[OneToOne_Required_PK_Date] IS NOT NULL AND [l13].[Level1_Required_Id] IS NOT NULL AND [l13].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l13].[Id] +END = [l14].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[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) [l5].[Name] + 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] + 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 [l4] ON [l2].[Id] = 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 + LEFT JOIN [Level1] AS [l5] ON [l4].[Level1_Required_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 + 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) +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 AND [l1].[Id] = 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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + INNER JOIN [Level1] AS [l3] ON [l2].[Level1_Required_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 [s] ON [l].[Id] = [s].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + LEFT JOIN [Level1] AS [l3] ON [l2].[Level1_Required_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 [s] ON [l].[Id] = [s].[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], [s].[Level1_Optional_Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s0] +LEFT JOIN [Level1] AS [l3] ON [s0].[Level1_Optional_Id] = [l3].[Id] +ORDER BY [s0].[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 [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[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] + WHERE [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 [l1] + WHERE [l1].[row] <= 3 +) AS [l2] ON [l].[Id] = [l2].[OneToMany_Required_Inverse2Id] +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 +"""); + } + + 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], [s].[Id], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT DISTINCT [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 [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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] > 2 +) AS [s] ON [l].[Id] = [s].[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 [l3].[Level3_Name] AS [Name1], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l6].[Id] AS [Id0], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Required_Inverse2Id] + 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_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = [l6].[Level1_Optional_Id] +) AS [s] ON [l3].[Level2_Required_Id] = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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 [s1].[Level2_Name] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + ORDER BY [l].[Id] +) AS [s0] +LEFT JOIN ( + SELECT [l5].[Level1_Optional_Id], [l5].[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] + 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 [l5] ON [l3].[Id] = 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 + 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 [s1] ON [s0].[Id] = [s1].[Level1_Optional_Id] +ORDER BY [s0].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +WHERE [l3].[Level3_Name] <> N'L3 05' OR [l3].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS [Id2], [l1].[Level2_Name] AS [Name2], [s].[Id] AS [Id1], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [l2].[Name], [l4].[Level2_Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + 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 [l4] ON [l2].[Id] = [l4].[Level1_Optional_Id] +) AS [s] ON [l1].[Level2_Name] = [s].[Level2_Name] +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 +"""); + } + + 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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Optional_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 +"""); + } + + public override async Task Include11(bool async) + { + await base.Include11(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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], [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], [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], [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], [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], [l11].[Id], [l11].[Level3_Optional_Id], [l11].[Level3_Required_Id], [l11].[Level4_Name], [l11].[OneToMany_Optional_Inverse4Id], [l11].[OneToMany_Required_Inverse4Id], [l11].[OneToOne_Optional_PK_Inverse4Id], [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], [l15].[Id], [l15].[Level2_Optional_Id], [l15].[Level2_Required_Id], [l15].[Level3_Name], [l15].[OneToMany_Optional_Inverse3Id], [l15].[OneToMany_Required_Inverse3Id], [l15].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_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] + FROM [Level1] AS [l4] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l5].[OneToOne_Optional_PK_Inverse3Id] +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] + FROM [Level1] AS [l6] + 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 [l7] ON [l].[Id] = [l7].[OneToOne_Optional_PK_Inverse2Id] +LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Optional_Id], [l8].[Level2_Required_Id], [l8].[Level3_Name], [l8].[OneToMany_Optional_Inverse3Id], [l8].[OneToMany_Required_Inverse3Id], [l8].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l8] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l9] ON CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] +END = [l9].[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] + WHERE [l10].[Level3_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l11] ON CASE + WHEN [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l9].[Id] +END = [l11].[Level3_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] + FROM [Level1] AS [l12] + WHERE [l12].[Level3_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l13] ON CASE + WHEN [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l9].[Id] +END = [l13].[OneToOne_Optional_PK_Inverse4Id] +LEFT JOIN ( + SELECT [l14].[Id], [l14].[Level2_Optional_Id], [l14].[Level2_Required_Id], [l14].[Level3_Name], [l14].[OneToMany_Optional_Inverse3Id], [l14].[OneToMany_Required_Inverse3Id], [l14].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l14] + WHERE [l14].[Level2_Required_Id] IS NOT NULL AND [l14].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l15] ON CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] +END = [l15].[OneToOne_Optional_PK_Inverse3Id] +"""); + } + + public override async Task Include18_3_3(bool async) + { + await base.Include18_3_3(async); + + AssertSql( + """ +SELECT [s].[Id], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [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] +FROM ( + SELECT DISTINCT [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +) AS [s] +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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id] +END = [l3].[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], [s].[Id], [s].[DifferentTypeReference_InheritanceDerived2Id], [s].[InheritanceDerived2Id], [s].[Name], [s].[Id0], [s].[InheritanceLeaf2Id], [s].[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 [s] ON [i].[Id] = [s].[InheritanceDerived2Id] +ORDER BY [i].[Id], [i0].[Id], [s].[Id] +"""); + } + + public override async Task Join_navigation_nested(bool async) + { + await base.Join_navigation_nested(async); + + AssertSql( + """ +SELECT CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END AS [Id3], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +INNER JOIN ( + SELECT [l4].[Id], [l8].[Id] AS [Id1], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = [l6].[Level1_Required_Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l7] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l8] ON CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END = [l8].[Level2_Optional_Id] +) AS [s] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id1] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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) [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Required_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 AND [l2].[Name] = N'L1 03' +ORDER BY CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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) [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +INNER JOIN [Level1] AS [l2] ON [l1].[Level1_Required_Id] = [l2].[Id] +INNER JOIN ( + SELECT [l7].[Level2_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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [s] ON [l2].[Id] = [s].[Level2_Required_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 +ORDER BY [l2].[Id] +"""); + } + + public override async Task Include14(bool async) + { + await base.Include14(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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], [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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + 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 [l3] ON [l].[Id] = [l3].[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] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l5].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Required_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 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 [l6].[Name] +FROM ( + SELECT TOP(@__p_0) [l5].[Level1_Required_Id] AS [Level1_Required_Id0], 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 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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END + LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END + LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 + 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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + 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 +) AS [s] +LEFT JOIN [Level1] AS [l6] ON [s].[Level1_Required_Id0] = [l6].[Id] +ORDER BY [s].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id] +END AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] +LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + 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 [l4] ON [l].[Id] = [l4].[Level1_Optional_Id] +LEFT JOIN [Level1] AS [l5] ON [s].[Level1_Required_Id] = [l5].[Id] +WHERE [l4].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +ORDER BY [l1].[Level2_Name], [l].[Id] +"""); + } + + public override async Task Include18(bool async) + { + await base.Include18(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [l1].[Id], [l1].[Date], [l1].[Name], [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], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] + ORDER BY [l].[Id] +) AS [l1] +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] + WHERE [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 [l2] ON [l1].[Id] = [l2].[OneToOne_Optional_PK_Inverse2Id] +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] + 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 [l4] ON [l1].[Id] = [l4].[Level1_Optional_Id] +ORDER BY [l1].[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], [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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + 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 [l3] ON [l].[Id] = [l3].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id], [l3].[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] + 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 [l2] ON [l0].[Id] = 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 + LEFT JOIN [Level1] AS [l3] ON [l2].[Level1_Optional_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 [s] ON [l].[Id] = [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[OneToMany_Optional_Inverse3Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Required_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l6].[Name] <> N'L1 07' OR [l6].[Name] IS NULL) AND [l6].[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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[OneToMany_Optional_Inverse3Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Required_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l6].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +WHERE [l3].[Level2_Required_Id] IS NULL OR [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + 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 [l3] ON [l].[Id] = [l3].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l4].[Level2_Optional_Id], [l4].[Level3_Name] + FROM [Level1] AS [l4] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[Level2_Optional_Id] +WHERE [l1].[Level2_Name] <> N'L2 05' OR [l1].[Level2_Name] IS NULL OR [l5].[Level3_Name] = N'L3 05' +"""); + } + + public override async Task Include2(bool async) + { + await base.Include2(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS [Id2], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [l4].[Id] AS [Id0], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[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] + 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 [l4] ON [l2].[Id] = [l4].[Level1_Optional_Id] +) AS [s] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +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 +"""); + } + + public override async Task Select_nav_prop_reference_optional1(bool async) + { + await base.Select_nav_prop_reference_optional1(async); + + AssertSql( + """ +SELECT [l1].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id] +END AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] +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] + 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 [l4] ON [l].[Id] = [l4].[Level1_Optional_Id] +WHERE 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 = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id] +END OR (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 IS NULL AND CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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 [l6].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Required_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +"""); + } + + public override async Task Include12(bool async) + { + await base.Include12(async); + + AssertSql( + """ +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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l4].[Id] AS [Id0], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[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] + 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 [l4] ON [l2].[Id] = 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 + 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 [s] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +WHERE [l3].[Level3_Name] <> N'L3 05' OR [l3].[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([l1].[Level1_Required_Id]), 0) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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) [s0].[Id] +FROM ( + SELECT DISTINCT [l].[Id] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] + WHERE [s].[Level2_Name] <> N'Foo' OR [s].[Level2_Name] IS NULL +) AS [s0] +ORDER BY [s0].[Id] +"""); + } + + public override async Task SelectMany_with_string_based_Include1(bool async) + { + await base.SelectMany_with_string_based_Include1(async); + + AssertSql( + """ +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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +"""); + } + + public override async Task SelectMany_nested_navigation_property_required(bool async) + { + await base.SelectMany_nested_navigation_property_required(async); + + AssertSql( + """ +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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE DATEADD(day, CAST(10.0E0 AS int), [l1].[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], [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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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 [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +WHERE [s].[Level2_Name] <> N'Foo' OR [s].[Level2_Name] IS NULL +"""); + } + + public override async Task Include18_1_1(bool async) + { + await base.Include18_1_1(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id], [s].[Date], [s].[Name], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l1].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] + ORDER BY [l1].[Level2_Name] +) AS [s] +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] + 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 [l3] ON [s].[Id] = [l3].[Level1_Optional_Id] +ORDER BY [s].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END, CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END, [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + public override async Task Join_navigation_nested2(bool async) + { + await base.Join_navigation_nested2(async); + + AssertSql( + """ +SELECT CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END AS [Id3], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +INNER JOIN ( + SELECT [l4].[Id], [l8].[Id] AS [Id1], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = [l6].[Level1_Required_Id] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l7] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l8] ON CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END = [l8].[Level2_Optional_Id] +) AS [s] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id1] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToOne_Optional_PK_Inverse2Id] = [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 AND [l2].[Id] > 5 +"""); + } + + public override async Task SelectMany_navigation_property(bool async) + { + await base.SelectMany_navigation_property(async); + + AssertSql( + """ +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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS [Id2], [l1].[Level2_Name] AS [Name2], [s].[Id] AS [Id1], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [l2].[Name], [l4].[Level2_Name] + FROM [Level1] AS [l2] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id], [l3].[Level2_Name] + FROM [Level1] AS [l3] + 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 [l4] ON [l2].[Id] = [l4].[Level1_Optional_Id] +) AS [s] ON [l1].[Level2_Name] = [s].[Level2_Name] +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 +"""); + } + + 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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id], [l3].[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] + 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 [l2] ON [l0].[Id] = 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 + LEFT JOIN [Level1] AS [l3] ON [l2].[Level1_Optional_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 [s] ON [l].[Id] = [s].[Id1] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END + 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 [l6].[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 [l1].[Level2_Name] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l6].[Id], [l6].[Date], [l6].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Required_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +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 +"""); + } + + public override async Task Navigations_compared_to_each_other2(bool async) + { + await base.Navigations_compared_to_each_other2(async); + + AssertSql( + """ +SELECT [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Required_Inverse2Id] = [l2].[Id] +LEFT JOIN [Level1] AS [l3] ON [l1].[OneToOne_Optional_PK_Inverse2Id] = [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 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +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 +"""); + } + + 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 [l3].[Level1_Optional_Id] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + 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 [l3] ON [l1].[Id] = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END + 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 [s] ON [l0].[Id] = [s].[Level1_Optional_Id] + ) AS [s0]) > 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 [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 [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +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] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +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 +"""); + } + + public override async Task SelectMany_with_string_based_Include2(bool async) + { + await base.SelectMany_with_string_based_Include2(async); + + AssertSql( + """ +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], [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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[Level2_Name] IS NOT NULL AND LEFT([l1].[Level2_Name], LEN([l1].[Level2_Name])) = [l1].[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) [l1].[Name] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l0].[Level2_Name] AS [Name], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [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], [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [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 [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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[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] + 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 [l4] ON [l].[Id] = [l4].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Required_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 AND [l2].[Id] = 1 +"""); + } + + public override async Task Include10(bool async) + { + await base.Include10(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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], [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], [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], [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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToOne_Optional_PK_Inverse3Id] +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] + FROM [Level1] AS [l4] + 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 [l5] ON [l].[Id] = [l5].[OneToOne_Optional_PK_Inverse2Id] +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] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l7] 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 = [l7].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level3_Optional_Id], [l8].[Level3_Required_Id], [l8].[Level4_Name], [l8].[OneToMany_Optional_Inverse4Id], [l8].[OneToMany_Required_Inverse4Id], [l8].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l8] + WHERE [l8].[Level3_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l9] ON CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] +END = [l9].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Required_Inverse2Id] = [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 AND ( + SELECT COUNT(*) + FROM [Level1] AS [l3] + 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 [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] +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Optional_Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Optional_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l6].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END <> 6 OR CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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 EXISTS ( + SELECT 1 + 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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[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 [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +ORDER BY [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Required_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +WHERE [l3].[Level3_Name] = N'L3 05' OR [l1].[Level2_Name] <> N'L2 05' OR [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE UPPER([l1].[Level2_Name]) LIKE N'L%' +"""); + } + + public override async Task Multiple_SelectMany_calls(bool async) + { + await base.Multiple_SelectMany_calls(async); + + AssertSql( + """ +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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE [l1].[Level2_Name] LIKE N'L%' +"""); + } + + public override async Task Include5(bool async) + { + await base.Include5(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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 [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_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 AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL AND CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END IS NOT NULL AND (CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END = [l4].[OneToMany_Optional_Inverse4Id] OR (CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END IS NULL AND [l4].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +LEFT JOIN ( + SELECT [l4].[Level4_Name], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[OneToOne_Optional_PK_Inverse4Id] +WHERE [l5].[Level4_Name] = N'L4 01' +"""); + } + + public override async Task SelectMany_where_with_subquery(bool async) + { + await base.SelectMany_where_with_subquery(async); + + AssertSql( + """ +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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[OneToMany_Required_Inverse2Id] +WHERE EXISTS ( + SELECT 1 + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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([l1].[Level1_Required_Id]) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l5].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level2_Optional_Id], [l4].[Level2_Required_Id], [l4].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l5].[Level2_Optional_Id] +WHERE (CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l5].[Id] +END OR (CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END IS NULL AND CASE + WHEN [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l5].[Id] +END IS NULL)) AND (CASE + WHEN [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l5].[Id] +END <> 7 OR CASE + WHEN [l5].[Level2_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l5].[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 [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = 1 OR CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NOT NULL AND (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id] OR (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +"""); + } + + public override async Task Include18_2(bool async) + { + await base.Include18_2(async); + + AssertSql( + """ +SELECT [s].[Id], [s].[Date], [s].[Name], [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 ( + 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] + WHERE [l1].[Level2_Name] <> N'Foo' OR [l1].[Level2_Name] IS NULL +) AS [s] +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] + 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 [l3] ON [s].[Id] = [l3].[Level1_Optional_Id] +"""); + } + + public override async Task Include13(bool async) + { + await base.Include13(async); + + AssertSql( + """ +SELECT [l].[Id], [l].[Date], [l].[Name], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[Level2_Name] <> N'L2 05' OR [l1].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS [Id], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + 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 [l4] ON [l2].[Id] = [l4].[Level1_Optional_Id] + ORDER BY [l4].[Level2_Name] +) AS [s] ON [l1].[Level1_Optional_Id] = [s].[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 +"""); + } + + public override async Task Multiple_SelectMany_with_string_based_Include(bool async) + { + await base.Multiple_SelectMany_with_string_based_Include(async); + + AssertSql( + """ +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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[Level3_Required_Id] +"""); + } + + public override async Task Where_navigation_property_to_collection2(bool async) + { + await base.Where_navigation_property_to_collection2(async); + + AssertSql( + """ +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] +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ( + SELECT COUNT(*) + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL AND 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 NOT NULL AND (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 = [l6].[OneToMany_Optional_Inverse3Id] OR (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 [l6].[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 [l3].[Level1_Optional_Id] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + 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 [l3] ON [l1].[Id] = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END + 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 [s] ON [l0].[Id] = [s].[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 [l4].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +INNER JOIN [Level1] AS [l4] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = ( + SELECT TOP(1) CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id1] + END + 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] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + LEFT JOIN ( + SELECT [l12].[Id] AS [Id1], [l12].[Level2_Optional_Id], [l12].[Level2_Required_Id], [l12].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[OneToOne_Required_PK_Date], [l9].[Level1_Required_Id], [l9].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l9] + 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 [l10] ON [l8].[Id] = CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END + LEFT JOIN ( + SELECT [l11].[Id], [l11].[Level2_Optional_Id], [l11].[Level2_Required_Id], [l11].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l11] + WHERE [l11].[Level2_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l12] ON CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END = CASE + WHEN [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l12].[Id] + END + 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 AND [l12].[Level2_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] ON CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END = [s].[Level2_Optional_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 AND CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id1] + END IS NOT NULL + ORDER BY CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id1] + END) +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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 [s].[Level3_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [s].[Id2] +END AS [Id4], [s].[Level4_Name] AS [Name4], [l].[Id] AS [Id1], [l].[Name] AS [Name1] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l6].[Id] AS [Id2], [l6].[Level3_Required_Id], [l6].[Level4_Name], [l6].[OneToMany_Required_Inverse4Id], [l11].[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] + 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 [l2] ON [l0].[Id] = 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 + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level2_Required_Id], [l3].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON 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 = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + LEFT JOIN ( + SELECT [l5].[Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l5] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l6] ON CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END = CASE + WHEN [l6].[Level3_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l6].[Id] + END + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Required_Id], [l7].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l7] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l8] ON [l6].[Level3_Required_Id] = CASE + WHEN [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l8].[Id] + END + LEFT JOIN ( + SELECT [l9].[Id], [l9].[OneToOne_Required_PK_Date], [l9].[Level1_Required_Id], [l9].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l9] + 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 [l10] ON [l8].[Level2_Required_Id] = CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END + LEFT JOIN [Level1] AS [l11] ON CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END = [l11].[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 [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l6].[Level3_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [s] ON [l].[Name] = [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE [l1].[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 [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l1].[Id] IS NOT NULL AND [l1].[Id] = [l2].[OneToMany_Optional_Inverse3Id]) +"""); + } + + 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l4].[Level3_Required_Id], [l4].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[Level3_Required_Id] +WHERE [l5].[Level3_Required_Id] IS NULL OR [l5].[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 [l3].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[OneToMany_Required_Inverse3Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Required_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l6].[Name] IN (N'L1 10', N'L1 01') +ORDER BY [l3].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +INNER JOIN [Level1] AS [l2] ON [l1].[Level1_Required_Id] = [l2].[Id] +INNER JOIN ( + SELECT [l7].[Level2_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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [s] ON [l2].[Id] = [s].[Level2_Required_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 +ORDER BY [l2].[Id] +"""); + } + + public override async Task Include6(bool async) + { + await base.Include6(async); + + AssertSql( + """ +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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToOne_Optional_PK_Inverse3Id] +"""); + } + + public override async Task Include7(bool async) + { + await base.Include7(async); + + AssertSql( + """ +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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [s].[Level3_Name] + FROM ( + SELECT DISTINCT [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 [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON 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 = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + 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 [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] + ORDER BY CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[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_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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 EXISTS ( + SELECT 1 + 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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[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 [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 [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +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] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +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 +"""); + } + + public override async Task Select_nav_prop_reference_optional2(bool async) + { + await base.Select_nav_prop_reference_optional2(async); + + AssertSql( + """ +SELECT CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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( + """ +@__names_0='["Name1","Name2"]' (Size = 4000) + +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[Level2_Name] NOT IN ( + SELECT [n].[value] + FROM OPENJSON(@__names_0) WITH ([value] nvarchar(max) '$') AS [n] +) OR [l1].[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 [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] +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Optional_Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Optional_Id] = [l6].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l6].[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 [s0].[Id], [s0].[Date], [s0].[Name], [s0].[Id0], [s0].[OneToOne_Required_PK_Date], [s0].[Level1_Optional_Id], [s0].[Level1_Required_Id], [s0].[Level2_Name], [s0].[OneToMany_Optional_Inverse2Id], [s0].[OneToMany_Required_Inverse2Id], [s0].[OneToOne_Optional_PK_Inverse2Id], [l4].[Name], [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 ( + SELECT [l].[Name] + FROM [Level1] AS [l] + GROUP BY [l].[Name] +) AS [l4] +LEFT JOIN ( + SELECT [s].[Id], [s].[Date], [s].[Name], [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l2].[Id] AS [Id0], [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], 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] + 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 [l2] ON [l0].[Id] = [l2].[Level1_Optional_Id] + ) AS [s] + WHERE [s].[row] <= 1 +) AS [s0] ON [l4].[Name] = [s0].[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] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [s0].[OneToOne_Required_PK_Date] IS NOT NULL AND [s0].[Level1_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s0].[Id0] +END = [l5].[OneToMany_Optional_Inverse3Id] +ORDER BY [l4].[Name], [s0].[Id], [s0].[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 [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] +END AS [Id4], [l5].[Level4_Name] AS [Name4], [s].[Id] AS [Id1], [s].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] +END +INNER JOIN ( + SELECT [l6].[Id], [l6].[Name], [l12].[Level4_Name] + FROM [Level1] AS [l6] + LEFT JOIN ( + SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Required_Id], [l7].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l7] + 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 [l8] ON [l6].[Id] = [l8].[Level1_Required_Id] + LEFT JOIN ( + SELECT [l9].[Id], [l9].[Level2_Optional_Id], [l9].[Level2_Required_Id], [l9].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l9] + WHERE [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l10] ON CASE + WHEN [l8].[OneToOne_Required_PK_Date] IS NOT NULL AND [l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l8].[Id] + END = [l10].[Level2_Optional_Id] + LEFT JOIN ( + SELECT [l11].[Id], [l11].[Level3_Required_Id], [l11].[Level4_Name], [l11].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l11] + WHERE [l11].[Level3_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l12] ON CASE + WHEN [l10].[Level2_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l10].[Id] + END = CASE + WHEN [l12].[Level3_Required_Id] IS NOT NULL AND [l12].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l12].[Id] + END +) AS [s] ON [l5].[Level4_Name] = [s].[Level4_Name] +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[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 [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +INNER JOIN ( + SELECT [l8].[Id] AS [Id1], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Required_Id], [l7].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l7] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l8] ON CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END = CASE + WHEN [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l8].[Id] + END + 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 [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [s] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[Level2_Name] = N'L2 05' OR [l1].[Level2_Name] <> N'L2 42' OR [l1].[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 [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +"""); + } + + public override async Task Navigations_compared_to_each_other5(bool async) + { + await base.Navigations_compared_to_each_other5(async); + + AssertSql( + """ +SELECT [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +LEFT JOIN ( + SELECT [l4].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l5].[OneToOne_Optional_PK_Inverse3Id] +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 AND EXISTS ( + SELECT 1 + FROM [Level1] AS [l6] + WHERE [l6].[Level3_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse4Id] IS NOT NULL AND CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END IS NOT NULL AND (CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END = [l6].[OneToMany_Optional_Inverse4Id] OR (CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] + END IS NULL AND [l6].[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], [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], [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 [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] + WHERE [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 [l2] ON [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] +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] + 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 [l3] ON [l].[Id] = [l3].[OneToMany_Required_Inverse2Id] +ORDER BY [l].[Id], [l2].[Id] +"""); + } + + public override async Task Key_equality_using_property_method_required2(bool async) + { + await base.Key_equality_using_property_method_required2(async); + + AssertSql( + """ +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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Required_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 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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END AS [Id3], [l7].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Optional_Id] = [l6].[Id] +INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +"""); + } + + public override async Task Include19(bool async) + { + await base.Include19(async); + + AssertSql( + """ +SELECT [s].[Id], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [s].[Id0], [s].[OneToOne_Required_PK_Date0], [s].[Level1_Optional_Id0], [s].[Level1_Required_Id0], [s].[Level2_Name0], [s].[OneToMany_Optional_Inverse2Id0], [s].[OneToMany_Required_Inverse2Id0], [s].[OneToOne_Optional_PK_Inverse2Id0] +FROM ( + SELECT DISTINCT [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], [l3].[Id] AS [Id0], [l3].[OneToOne_Required_PK_Date] AS [OneToOne_Required_PK_Date0], [l3].[Level1_Optional_Id] AS [Level1_Optional_Id0], [l3].[Level1_Required_Id] AS [Level1_Required_Id0], [l3].[Level2_Name] AS [Level2_Name0], [l3].[OneToMany_Optional_Inverse2Id] AS [OneToMany_Optional_Inverse2Id0], [l3].[OneToMany_Required_Inverse2Id] AS [OneToMany_Required_Inverse2Id0], [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + 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 [l3] ON [l].[Id] = [l3].[OneToOne_Optional_PK_Inverse2Id] +) AS [s] +"""); + } + + public override async Task SelectMany_navigation_property_and_filter_before(bool async) + { + await base.SelectMany_navigation_property_and_filter_before(async); + + AssertSql( + """ +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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [s].[Level3_Name] + FROM ( + SELECT DISTINCT [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 [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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] + FROM [Level1] AS [l3] + WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l4] ON 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 = CASE + WHEN [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l4].[Id] + END + 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 [l4].[Level2_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [s] + 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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[OneToOne_Required_PK_Date] IS NULL OR [l1].[Level1_Required_Id] IS NULL OR [l1].[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 [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Level1_Optional_Id], [l5].[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] + 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 [l5] ON [l3].[Id] = 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 + 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 [s0] ON [l].[Id] = [s0].[Level1_Optional_Id] +WHERE [s].[Level2_Name] = N'L2 05' OR [s0].[Level2_Name] <> N'L2 42' OR [s0].[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([l1].[Level1_Required_Id] AS float)) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE DATEADD(day, CAST(CAST(CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS float) AS int), DATEADD(day, CAST(15.0E0 AS int), [l1].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Required_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 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 [s0].[Id], [s0].[Date], [s0].[Name], [s0].[Id0], [s0].[OneToOne_Required_PK_Date], [s0].[Level1_Optional_Id], [s0].[Level1_Required_Id], [s0].[Level2_Name], [s0].[OneToMany_Optional_Inverse2Id], [s0].[OneToMany_Required_Inverse2Id], [s0].[OneToOne_Optional_PK_Inverse2Id] +FROM ( + SELECT [l].[Name] + FROM [Level1] AS [l] + GROUP BY [l].[Name] +) AS [l3] +LEFT JOIN ( + SELECT [s].[Id], [s].[Date], [s].[Name], [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id] + FROM ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l2].[Id] AS [Id0], [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], 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] + 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 [l2] ON [l0].[Id] = [l2].[Level1_Optional_Id] + ) AS [s] + WHERE [s].[row] <= 1 +) AS [s0] ON [l3].[Name] = [s0].[Name] +"""); + } + + public override async Task SelectMany_navigation_comparison2(bool async) + { + await base.SelectMany_navigation_comparison2(async); + + AssertSql( + """ +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id] +END AS [Id2] +FROM [Level1] AS [l] +CROSS JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] +LEFT JOIN [Level1] AS [l3] ON [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] +WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END IS NOT NULL AND (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END = [l2].[OneToMany_Optional_Inverse3Id] OR (CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[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 [s].[Id], [s].[Level2_Optional_Id], [s].[Level2_Required_Id], [s].[Level3_Name], [s].[OneToMany_Optional_Inverse3Id], [s].[OneToMany_Required_Inverse3Id], [s].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l] +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], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Level3_Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l2] 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 = [l2].[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 [s] ON [l].[Id] = [s].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END AS [Id2], [s].[Id] AS [Id1], CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +INNER JOIN ( + SELECT [l2].[Id], [l4].[Id] AS [Id0], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[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] + 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 [l4] ON [l2].[Id] = [l4].[Level1_Optional_Id] +) AS [s] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +INNER JOIN ( + SELECT [l9].[Id] AS [Id1], [l9].[Level2_Required_Id], [l9].[OneToMany_Required_Inverse3Id], [l11].[Id] AS [Id2], [l11].[OneToOne_Required_PK_Date] AS [OneToOne_Required_PK_Date0], [l11].[Level1_Required_Id] AS [Level1_Required_Id0], [l11].[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] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + LEFT JOIN ( + SELECT [l8].[Id], [l8].[Level2_Optional_Id], [l8].[Level2_Required_Id], [l8].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l8] + WHERE [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l9] ON CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END = CASE + WHEN [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l9].[Id] + END + LEFT JOIN ( + SELECT [l10].[Id], [l10].[OneToOne_Required_PK_Date], [l10].[Level1_Required_Id], [l10].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l10] + 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 [l11] ON [l9].[Level2_Optional_Id] = CASE + WHEN [l11].[OneToOne_Required_PK_Date] IS NOT NULL AND [l11].[Level1_Required_Id] IS NOT NULL AND [l11].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l11].[Id] + END + 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 AND [l9].[Level2_Required_Id] IS NOT NULL AND [l9].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [s0] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [s0].[OneToOne_Required_PK_Date0] IS NOT NULL AND [s0].[Level1_Required_Id0] IS NOT NULL AND [s0].[OneToMany_Required_Inverse2Id0] IS NOT NULL THEN [s0].[Id2] +END +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 +"""); + } + + 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE DATEADD(month, CAST(2 AS int), DATEADD(day, CAST(15.0E0 AS int), DATEADD(day, CAST(10.0E0 AS int), [l1].[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([l1].[Level1_Required_Id] AS float)) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l3].[Level1_Optional_Id] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + 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 [l3] ON [l1].[Id] = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END + 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 [s] ON [l0].[Id] = [s].[Level1_Optional_Id] + WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l7].[Level1_Optional_Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + 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 [s0] ON [l4].[Id] = [s0].[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 [l3].[Level3_Name] AS [Name], [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +LEFT JOIN [Level1] AS [l6] ON [l5].[Level1_Required_Id] = [l6].[Id] +LEFT JOIN [Level1] AS [l7] ON [l5].[Level1_Optional_Id] = [l7].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l6].[Id] <> [l7].[Id] OR [l6].[Id] IS NULL OR [l7].[Id] IS NULL) AND ([l6].[Id] IS NOT NULL OR [l7].[Id] IS NOT NULL) AND ([l7].[Id] <> 7 OR [l7].[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) [l5].[Name] + 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] + 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 [l4] ON [l2].[Id] = 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 + LEFT JOIN [Level1] AS [l5] ON [l4].[Level1_Required_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 + 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) +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 +"""); + } + + 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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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 [l3].[Level1_Optional_Id] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + 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 [l3] ON [l1].[Id] = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END + 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 [s] ON [l0].[Id] = [s].[Level1_Optional_Id]) > 4 +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] + 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 GREATEST([l1].[Level1_Required_Id], 7) +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[OneToOne_Optional_PK_Inverse2Id] +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 +"""); + } + + 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([l1].[Level1_Required_Id]) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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) [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 +ORDER BY CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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 [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] +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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l5].[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 [s].[Level2_Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +WHERE [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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 [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Required_Inverse2Id] = [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 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE [l1].[Level2_Name] <> N'Foo' OR [l1].[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_Required_Id], [l1].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l1] + 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 [l2] ON [l0].[Id] = 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 + 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].[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) [l5].[Name] + 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] + 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 [l4] ON [l2].[Id] = 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 + LEFT JOIN [Level1] AS [l5] ON [l4].[Level1_Required_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 + 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) = N'L1 02' AND ( + SELECT TOP(1) [l5].[Name] + 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] + 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 [l4] ON [l2].[Id] = 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 + LEFT JOIN [Level1] AS [l5] ON [l4].[Level1_Required_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 + 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) 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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +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 +"""); + } + + public override async Task Include18_1(bool async) + { + await base.Include18_1(async); + + AssertSql( + """ +SELECT [l1].[Id], [l1].[Date], [l1].[Name], [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 ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] +) AS [l1] +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] + WHERE [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 [l2] ON [l1].[Id] = [l2].[Level1_Optional_Id] +"""); + } + + public override async Task Include18_4(bool async) + { + await base.Include18_4(async); + + AssertSql( + """ +SELECT [l1].[Id], [l1].[Date], [l1].[Name], [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], [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] +FROM ( + SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] + FROM [Level1] AS [l] +) AS [l1] +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] + WHERE [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 [l2] ON [l1].[Id] = [l2].[Level1_Optional_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] + 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 [l4] ON [l1].[Id] = [l4].[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([l1].[Level1_Required_Id] AS float)) +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[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) [l5].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +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 +"""); + } + + 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 [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l5].[Level1_Optional_Id], [l5].[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] + 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 [l5] ON [l3].[Id] = 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 + 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 [s0] ON [l].[Id] = [s0].[Level1_Optional_Id] +WHERE [s].[Level2_Name] = N'L2 05' OR [s0].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id], [l3].[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] + 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 [l2] ON [l0].[Id] = 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 + LEFT JOIN [Level1] AS [l3] ON [l2].[Level1_Required_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 [s] ON [l].[Id] = [s].[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') 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 [s].[Id], [s].[Date], [s].[Name], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l1].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] + ORDER BY [l1].[Level2_Name] +) AS [s] +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] + 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 [l3] ON [s].[Id] = [l3].[Level1_Optional_Id] +ORDER BY [s].[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 [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[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 [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 [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Required_Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +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] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Required_Id] = 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 +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL +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 +"""); + } + + 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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + 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 [l5] ON [l3].[Level2_Optional_Id] = 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 +LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l7] ON [l3].[Level2_Required_Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] +END +LEFT JOIN [Level1] AS [l8] ON [l7].[Level1_Optional_Id] = [l8].[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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l5].[Level2_Name] <> N'L2 05' OR [l5].[Level2_Name] IS NULL OR [l8].[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) [l11].[Name] + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l5].[Id], [l5].[OneToOne_Required_PK_Date], [l5].[Level1_Required_Id], [l5].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l5] + 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 [l6] ON [l4].[Id] = CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END + LEFT JOIN ( + SELECT [l7].[Id], [l7].[Level2_Required_Id], [l7].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l7] + WHERE [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l8] ON CASE + WHEN [l6].[OneToOne_Required_PK_Date] IS NOT NULL AND [l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l6].[Id] + END = CASE + WHEN [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l8].[Id] + END + LEFT JOIN ( + SELECT [l9].[Id], [l9].[OneToOne_Required_PK_Date], [l9].[Level1_Required_Id], [l9].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l9] + 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 [l10] ON [l8].[Level2_Required_Id] = CASE + WHEN [l10].[OneToOne_Required_PK_Date] IS NOT NULL AND [l10].[Level1_Required_Id] IS NOT NULL AND [l10].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l10].[Id] + END + LEFT JOIN [Level1] AS [l11] ON [l10].[Level1_Required_Id] = [l11].[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 [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL + ORDER BY CASE + WHEN [l8].[Level2_Required_Id] IS NOT NULL AND [l8].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l8].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END +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 AND [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[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 [l3].[Level3_Name] +FROM ( + SELECT TOP(@__p_0) [l1].[Id] AS [Id0], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Required_Id], [l1].[OneToMany_Required_Inverse2Id], CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] + ORDER BY CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END +) AS [s] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END = [l3].[Level2_Optional_Id] +ORDER BY [s].[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 [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +"""); + } + + public override async Task Include18_3(bool async) + { + await base.Include18_3(async); + + AssertSql( + """ +@__p_0='10' + +SELECT [s].[Id], [s].[Date], [s].[Name], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l1].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] + ORDER BY [l1].[Level2_Name] +) AS [s] +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] + 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 [l3] ON [s].[Id] = [l3].[Level1_Optional_Id] +ORDER BY [s].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Required_Inverse2Id] = [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 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 [l2].[Level1_Optional_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +WHERE [s].[Level2_Name] <> N'Foo' OR [s].[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 [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [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 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 [l3].[Level1_Optional_Id] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + 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 [l3] ON [l1].[Id] = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END + 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 [s] ON [l0].[Id] = [s].[Level1_Optional_Id] + ) AS [s0]) > 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 [s].[Id], [s].[Date], [s].[Name], [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 ( + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [l1].[Level2_Name] + FROM [Level1] AS [l] + LEFT JOIN ( + SELECT [l0].[Level1_Required_Id], [l0].[Level2_Name] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Required_Id] + ORDER BY [l1].[Level2_Name] +) AS [s] +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] + 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 [l3] ON [s].[Id] = [l3].[Level1_Optional_Id] +ORDER BY [s].[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 [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 [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] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[Level1_Required_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 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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] + WHERE [l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ( + SELECT TOP(1) CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END + FROM [Level1] AS [l1] + 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 AND [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ORDER BY CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END) IS NOT NULL AND (( + SELECT TOP(1) 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 + FROM [Level1] AS [l2] + 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 [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY 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) = [l0].[OneToMany_Optional_Inverse3Id] OR (( + SELECT TOP(1) 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 + FROM [Level1] AS [l2] + 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 [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY 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) 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 [s].[Id0], [s].[OneToOne_Required_PK_Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], [s].[Level2_Name], [s].[OneToMany_Optional_Inverse2Id], [s].[OneToMany_Required_Inverse2Id], [s].[OneToOne_Optional_PK_Inverse2Id], [l6].[Id], [l6].[Date], [l6].[Name] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [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 [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] + 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 [l2] ON [l0].[Id] = 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 + 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 [s] ON [l].[Id] = [s].[Level1_Optional_Id] +CROSS JOIN ( + SELECT [l5].[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] + 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 [l5] ON [l3].[Id] = 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 + 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 [s0] +INNER JOIN [Level1] AS [l6] ON [s0].[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], [s].[Text], [s].[ComplexNavigationStringDefaultText], [s].[LanguageName], [s].[Name], [s].[CultureString], [s0].[Text], [s0].[ComplexNavigationStringDefaultText], [s0].[LanguageName], [s0].[Name], [s0].[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 [s] ON [m].[DefaultText] = [s].[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 [s0] ON [m0].[DefaultText] = [s0].[ComplexNavigationStringDefaultText] +ORDER BY [f].[Name], [m].[DefaultText], [m0].[DefaultText], [s].[Text], [s].[Name], [s0].[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 [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l2].[Level2_Optional_Id], [l2].[Level3_Name] + FROM [Level1] AS [l2] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Optional_Id] +WHERE [l3].[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) 1 AS empty + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l3].[Level1_Optional_Id] + FROM [Level1] AS [l1] + LEFT JOIN ( + SELECT [l2].[Id], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l2] + 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 [l3] ON [l1].[Id] = CASE + WHEN [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l3].[Id] + END + 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 [s] ON [l0].[Id] = [s].[Level1_Optional_Id] + WHERE ( + SELECT COUNT(*) + FROM [Level1] AS [l4] + LEFT JOIN ( + SELECT [l7].[Level1_Optional_Id] + FROM [Level1] AS [l5] + LEFT JOIN ( + SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l6] + 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 [l7] ON [l5].[Id] = CASE + WHEN [l7].[OneToOne_Required_PK_Date] IS NOT NULL AND [l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l7].[Id] + END + 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 [s0] ON [l4].[Id] = [s0].[Level1_Optional_Id]) > 7 + ORDER BY [l0].[Id] + ) AS [s1]) > 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] + WHERE [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 [l1] ON [l].[Id] = [l1].[Level1_Optional_Id] +WHERE CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[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( + """ +SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [s].[Level1_Optional_Id] + FROM ( + SELECT [l2].[Level1_Optional_Id], ROW_NUMBER() OVER(PARTITION BY [l2].[Level1_Optional_Id] ORDER BY 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 [row] + 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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] > 0 + ) AS [s] + WHERE [s].[row] <= 10 +) AS [s0] ON [l].[Id] = [s0].[Level1_Optional_Id] +"""); + } + + 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 [l].[Id] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [s].[Level1_Optional_Id] + FROM ( + SELECT [l2].[Level1_Optional_Id], ROW_NUMBER() OVER(PARTITION BY [l2].[Level1_Optional_Id] ORDER BY 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 [row] + 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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] > 0 + ) AS [s] + WHERE [s].[row] <= 10 +) AS [s0] ON [l].[Id] = [s0].[Level1_Optional_Id] +"""); + } + + 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], [s].[Id], [s].[Discriminator], [s].[InheritanceBase2Id], [s].[InheritanceBase2Id1], [s].[Name], [s].[Id0], [s].[DifferentTypeCollection_InheritanceDerived1Id], [s].[DifferentTypeReference_InheritanceDerived1Id], [s].[InheritanceDerived2Id], [s].[Name0], [s].[SameTypeCollection_InheritanceDerived1Id], [s].[SameTypeReference_InheritanceDerived1Id], [s].[SameTypeReference_InheritanceDerived2Id], [s].[Id1], [s].[DifferentTypeCollection_InheritanceDerived1Id0], [s].[DifferentTypeReference_InheritanceDerived1Id0], [s].[InheritanceDerived2Id0], [s].[Name1], [s].[SameTypeCollection_InheritanceDerived1Id0], [s].[SameTypeReference_InheritanceDerived1Id0], [s].[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 [s] ON [i].[Id] = [s].[InheritanceBase2Id1] +ORDER BY [i].[Id], [i0].[Id], [i1].[Id], [i2].[Id], [s].[Id], [s].[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] +"""); + } + + public override async Task Multiple_required_navigation_using_multiple_selects_with_EF_Property_Include(bool async) + { + await base.Multiple_required_navigation_using_multiple_selects_with_EF_Property_Include(async); + + AssertSql(); + } + + public override async Task SelectMany_with_EF_Property_Include1(bool async) + { + await base.SelectMany_with_EF_Property_Include1(async); + + AssertSql( + """ +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], [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] +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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[Level2_Required_Id] +"""); + } + + public override async Task Multiple_SelectMany_with_EF_Property_Include(bool async) + { + await base.Multiple_SelectMany_with_EF_Property_Include(async); + + AssertSql( + """ +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], [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 [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] + WHERE [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 [l1] ON [l].[Id] = [l1].[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] + WHERE [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL +) AS [l3] ON CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END = [l3].[OneToMany_Optional_Inverse3Id] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[Level3_Optional_Id], [l4].[Level3_Required_Id], [l4].[Level4_Name], [l4].[OneToMany_Optional_Inverse4Id], [l4].[OneToMany_Required_Inverse4Id], [l4].[OneToOne_Optional_PK_Inverse4Id] + FROM [Level1] AS [l4] + WHERE [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL +) AS [l5] ON CASE + WHEN [l3].[Level2_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l3].[Id] +END = [l5].[Level3_Required_Id] +"""); + } + + public override async Task Multiple_required_navigation_with_EF_Property_Include(bool async) + { + await base.Multiple_required_navigation_with_EF_Property_Include(async); + + AssertSql(); + } + + public override async Task GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure(bool async) + { + await base.GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] <> @__prm_0 OR [l2].[Id] IS NULL) +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_with_predicate_using_closure(bool async) + { + await base.GroupJoin_SelectMany_with_predicate_using_closure(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] <> @__prm_0 OR [l2].[Id] IS NULL) +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested(bool async) + { + await base.GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested(async); + + AssertSql( + """ +@__prm1_0='10' +@__prm2_1='20' + +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2], CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id1] +END AS [Id3] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] <> @__prm1_0 OR [l2].[Id] IS NULL) +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l7].[Id] AS [Id1], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l7].[Id] <> @__prm2_1 OR [l7].[Id] IS NULL) +) AS [s0] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END = [s0].[Level2_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_with_predicate_using_closure_nested(bool async) + { + await base.GroupJoin_SelectMany_with_predicate_using_closure_nested(async); + + AssertSql( + """ +@__prm1_0='10' +@__prm2_1='20' + +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2], CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id1] +END AS [Id3] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] <> @__prm1_0 OR [l2].[Id] IS NULL) +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l7].[Id] AS [Id1], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l7].[Id] <> @__prm2_1 OR [l7].[Id] IS NULL) +) AS [s0] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END = [s0].[Level2_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested_same_param(bool async) + { + await base.GroupJoin_SelectMany_DefaultIfEmpty_with_predicate_using_closure_nested_same_param(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2], CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id1] +END AS [Id3] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] <> @__prm_0 OR [l2].[Id] IS NULL) +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +LEFT JOIN ( + SELECT [l7].[Id] AS [Id1], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l7].[Id] <> @__prm_0 OR [l7].[Id] IS NULL) +) AS [s0] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END = [s0].[Level2_Optional_Id] +"""); + } + + public override async Task GroupJoin_SelectMany_with_predicate_using_closure_nested_same_param(bool async) + { + await base.GroupJoin_SelectMany_with_predicate_using_closure_nested_same_param(async); + + AssertSql( + """ +@__prm_0='10' + +SELECT [l].[Id] AS [Id1], CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END AS [Id2], CASE + WHEN [s0].[Level2_Required_Id] IS NOT NULL AND [s0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s0].[Id1] +END AS [Id3] +FROM [Level1] AS [l] +INNER JOIN ( + SELECT [l2].[Id] AS [Id0], [l2].[OneToOne_Required_PK_Date], [l2].[Level1_Optional_Id], [l2].[Level1_Required_Id], [l2].[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] + 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 [l2] ON [l0].[Id] = 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 + 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].[Id] <> @__prm_0 OR [l2].[Id] IS NULL) +) AS [s] ON [l].[Id] = [s].[Level1_Optional_Id] +INNER JOIN ( + SELECT [l7].[Id] AS [Id1], [l7].[Level2_Optional_Id], [l7].[Level2_Required_Id], [l7].[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] + 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 [l5] ON [l3].[Id] = 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 + LEFT JOIN ( + SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = CASE + WHEN [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l7].[Id] + END + 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 [l7].[Level2_Required_Id] IS NOT NULL AND [l7].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ([l7].[Id] <> @__prm_0 OR [l7].[Id] IS NULL) +) AS [s0] ON CASE + WHEN [s].[OneToOne_Required_PK_Date] IS NOT NULL AND [s].[Level1_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [s].[Id0] +END = [s0].[Level2_Optional_Id] +"""); + } + + public override async Task Multiple_optional_navs_should_not_deadlock(bool async) + { + await base.Multiple_optional_navs_should_not_deadlock(async); + + AssertSql( + """ +SELECT 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_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l0] + WHERE [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 [l1] ON [l].[Id] = CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] +END +LEFT JOIN [Level1] AS [l2] ON [l1].[OneToMany_Optional_Inverse2Id] = [l2].[Id] +LEFT JOIN [Level1] AS [l3] ON [l1].[Level1_Optional_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 AND (([l2].[Id] IS NOT NULL AND [l2].[Name] LIKE N'%L1 01%') OR ([l3].[Id] IS NOT NULL AND [l3].[Name] LIKE N'%L1 01%')) +"""); + } + + public override async Task Null_check_removal_applied_recursively_complex(bool async) + { + await base.Null_check_removal_applied_recursively_complex(async); + + AssertSql(); + } + + public override async Task Correlated_projection_with_first(bool async) + { + await base.Correlated_projection_with_first(async); + + AssertSql( + """ +SELECT [l].[Id], [s].[c], [s].[Id], [s].[Id0] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT CASE + WHEN [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l4].[Id] + END AS [c], [l0].[Id], [l4].[Id] AS [Id0] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level3_Required_Id], [l3].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level3_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l4] ON CASE + WHEN [l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l0].[Id] + END = [l4].[Level3_Required_Id] + WHERE [l0].[Level2_Required_Id] IS NOT NULL AND [l0].[OneToMany_Required_Inverse3Id] IS NOT NULL AND ( + SELECT TOP(1) CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END + FROM [Level1] AS [l1] + 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 AND [l].[Id] = [l1].[OneToMany_Optional_Inverse2Id] + ORDER BY CASE + WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id] + END) IS NOT NULL AND (( + SELECT TOP(1) 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 + FROM [Level1] AS [l2] + 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 [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY 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) = [l0].[OneToMany_Optional_Inverse3Id] OR (( + SELECT TOP(1) 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 + FROM [Level1] AS [l2] + 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 [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id] + ORDER BY 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) IS NULL AND [l0].[OneToMany_Optional_Inverse3Id] IS NULL)) +) AS [s] +ORDER BY [l].[Id], [s].[Id] +"""); + } + + public override async Task Max_in_multi_level_nested_subquery(bool async) + { + await base.Max_in_multi_level_nested_subquery(async); + + AssertSql( + """ +@__p_0='2' + +SELECT [l6].[Id], [s].[Id], [s].[Id0], [s].[Id1], [s].[Result], [s].[Id2], [s].[Id3], [s].[Id4] +FROM ( + SELECT TOP(@__p_0) [l].[Id] + FROM [Level1] AS [l] + ORDER BY [l].[Id] +) AS [l6] +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 [Id], CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END AS [Id0], CASE + WHEN [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l4].[Id] + END AS [Id1], CASE + WHEN COALESCE(( + SELECT MAX(CASE + WHEN [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l5].[Id] + END) + FROM [Level1] AS [l5] + WHERE [l5].[Level3_Required_Id] IS NOT NULL AND [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL AND CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END IS NOT NULL AND (CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END = [l5].[OneToMany_Optional_Inverse4Id] OR (CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END IS NULL AND [l5].[OneToMany_Optional_Inverse4Id] IS NULL))), 0) > 1 THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [Result], [l0].[Id] AS [Id2], [l2].[Id] AS [Id3], [l4].[Id] AS [Id4], [l0].[OneToMany_Optional_Inverse2Id] + FROM [Level1] AS [l0] + LEFT JOIN ( + SELECT [l1].[Id], [l1].[Level2_Required_Id], [l1].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l2] 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 = [l2].[Level2_Required_Id] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level3_Required_Id], [l3].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level3_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l4] ON CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END = [l4].[Level3_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 [s] ON [l6].[Id] = [s].[OneToMany_Optional_Inverse2Id] +ORDER BY [l6].[Id], [s].[Id2], [s].[Id3] +"""); + } + + public override async Task Multiple_select_many_in_projection(bool async) + { + await base.Multiple_select_many_in_projection(async); + + AssertSql( + """ +SELECT [l].[Id], [s0].[Id], [s0].[RefId], [s0].[Id0], [s0].[Id00], [s0].[Id1], ( + SELECT COUNT(*) + FROM [Level1] AS [l5] + INNER JOIN ( + SELECT [l6].[Level3_Name], [l6].[OneToMany_Optional_Inverse3Id] + FROM [Level1] AS [l6] + WHERE [l6].[Level2_Required_Id] IS NOT NULL AND [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l7] 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 = [l7].[OneToMany_Optional_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 AND [l].[Id] = [l5].[OneToMany_Optional_Inverse2Id] AND ([l7].[Level3_Name] <> N'' OR [l7].[Level3_Name] IS NULL)) +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id0] + END AS [Id], CASE + WHEN [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l4].[Id] + END AS [RefId], [s].[Id] AS [Id0], [s].[Id0] AS [Id00], [l4].[Id] AS [Id1], [s].[c] + FROM ( + SELECT TOP(12) [l0].[Id], [l2].[Id] AS [Id0], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id], 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 [l0] + INNER JOIN ( + SELECT [l1].[Id], [l1].[Level2_Required_Id], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l2] 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 = [l2].[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 AND [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] + ORDER BY CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END + ) AS [s] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level3_Optional_Id], [l3].[Level3_Required_Id], [l3].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level3_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l4] ON CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id0] + END = [l4].[Level3_Optional_Id] +) AS [s0] +ORDER BY [l].[Id], [s0].[c], [s0].[Id0], [s0].[Id00] +"""); + } + + public override async Task Single_select_many_in_projection_with_take(bool async) + { + await base.Single_select_many_in_projection_with_take(async); + + AssertSql( + """ +SELECT [l].[Id], [s0].[Id], [s0].[RefId], [s0].[Id0], [s0].[Id00], [s0].[Id1] +FROM [Level1] AS [l] +OUTER APPLY ( + SELECT CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id0] + END AS [Id], CASE + WHEN [l4].[Level3_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse4Id] IS NOT NULL THEN [l4].[Id] + END AS [RefId], [s].[Id] AS [Id0], [s].[Id0] AS [Id00], [l4].[Id] AS [Id1], [s].[c] + FROM ( + SELECT TOP(12) [l0].[Id], [l2].[Id] AS [Id0], [l2].[Level2_Required_Id], [l2].[OneToMany_Required_Inverse3Id], 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 [l0] + INNER JOIN ( + SELECT [l1].[Id], [l1].[Level2_Required_Id], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id] + FROM [Level1] AS [l1] + WHERE [l1].[Level2_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse3Id] IS NOT NULL + ) AS [l2] 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 = [l2].[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 AND [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] + ORDER BY CASE + WHEN [l2].[Level2_Required_Id] IS NOT NULL AND [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [l2].[Id] + END + ) AS [s] + LEFT JOIN ( + SELECT [l3].[Id], [l3].[Level3_Optional_Id], [l3].[Level3_Required_Id], [l3].[OneToMany_Required_Inverse4Id] + FROM [Level1] AS [l3] + WHERE [l3].[Level3_Required_Id] IS NOT NULL AND [l3].[OneToMany_Required_Inverse4Id] IS NOT NULL + ) AS [l4] ON CASE + WHEN [s].[Level2_Required_Id] IS NOT NULL AND [s].[OneToMany_Required_Inverse3Id] IS NOT NULL THEN [s].[Id0] + END = [l4].[Level3_Optional_Id] +) AS [s0] +ORDER BY [l].[Id], [s0].[c], [s0].[Id0], [s0].[Id00] +"""); + } + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + + public class Fixture160 : ComplexNavigationsSharedTypeQuerySqlServerFixture + { + protected override string StoreName + => "ComplexNavigationsOwned160"; + + public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) + => base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160)); + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs index c07c15b88a0..8dea5c736e8 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs @@ -6603,14 +6603,13 @@ WHERE [l3].[OneToOne_Required_PK_Date] IS NOT NULL AND [l3].[Level1_Required_Id] """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] 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 GREATEST([l1].[Level1_Required_Id], 7) +SELECT [l1].[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] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServer160Test.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServer160Test.cs new file mode 100644 index 00000000000..c41575cf0ba --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServer160Test.cs @@ -0,0 +1,1472 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore.TestModels.Northwind; + +namespace Microsoft.EntityFrameworkCore.Query; + +[SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] +public class NorthwindDbFunctionsQuerySqlServer160Test + : NorthwindDbFunctionsQueryRelationalTestBase +{ + public NorthwindDbFunctionsQuerySqlServer160Test(Fixture160 fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + public override async Task Like_literal(bool async) + { + await base.Like_literal(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'%M%' +"""); + } + + public override async Task Like_identity(bool async) + { + await base.Like_identity(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE [c].[ContactName] +"""); + } + + public override async Task Like_literal_with_escape(bool async) + { + await base.Like_literal_with_escape(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'!%' ESCAPE N'!' +"""); + } + + public override async Task Like_all_literals(bool async) + { + await base.Like_all_literals(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE N'FOO' LIKE N'%O%' +"""); + } + + public override async Task Like_all_literals_with_escape(bool async) + { + await base.Like_all_literals_with_escape(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE N'%' LIKE N'!%' ESCAPE N'!' +"""); + } + + public override async Task Collate_case_insensitive(bool async) + { + await base.Collate_case_insensitive(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[ContactName] COLLATE Latin1_General_CI_AI = N'maria anders' +"""); + } + + public override async Task Collate_case_sensitive(bool async) + { + await base.Collate_case_sensitive(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[ContactName] COLLATE Latin1_General_CS_AS = N'maria anders' +"""); + } + + public override async Task Collate_case_sensitive_constant(bool async) + { + await base.Collate_case_sensitive_constant(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[ContactName] = N'maria anders' COLLATE Latin1_General_CS_AS +"""); + } + + public override async Task Collate_is_null(bool async) + { + await base.Collate_is_null(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Customers] AS [c] +WHERE [c].[Region] IS NULL +"""); + } + + public override async Task Least(bool async) + { + await base.Least(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE LEAST([o].[OrderID], 10251) = 10251 +"""); + } + + public override async Task Greatest(bool async) + { + await base.Greatest(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE GREATEST([o].[OrderID], 10251) = 10251 +"""); + } + + public override async Task Least_with_nullable_value_type(bool async) + { + await base.Least_with_nullable_value_type(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE LEAST([o].[OrderID], 10251) = 10251 +"""); + } + + public override async Task Greatest_with_nullable_value_type(bool async) + { + await base.Greatest_with_nullable_value_type(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE GREATEST([o].[OrderID], 10251) = 10251 +"""); + } + + public override async Task Least_with_parameter_array_is_not_supported(bool async) + { + await base.Least_with_parameter_array_is_not_supported(async); + + AssertSql(); + } + + public override async Task Greatest_with_parameter_array_is_not_supported(bool async) + { + await base.Greatest_with_parameter_array_is_not_supported(async); + + AssertSql(); + } + + protected override string CaseInsensitiveCollation + => "Latin1_General_CI_AI"; + + protected override string CaseSensitiveCollation + => "Latin1_General_CS_AS"; + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task FreeText_literal() + { + using var context = CreateContext(); + var result = await context.Employees + .Where(c => EF.Functions.FreeText(c.Title, "Representative")) + .ToListAsync(); + + Assert.Equal(1u, result.First().EmployeeID); + + AssertSql( + """ +SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE FREETEXT([e].[Title], N'Representative') +"""); + } + + [ConditionalFact] + public void FreeText_client_eval_throws() + { + Assert.Throws(() => EF.Functions.FreeText("teststring", "teststring")); + Assert.Throws(() => EF.Functions.FreeText("teststring", "teststring", 1033)); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_multiple_words() + { + using var context = CreateContext(); + var result = context.Employees + .Where(c => EF.Functions.FreeText(c.Title, "Representative Sales")) + .Count(); + + Assert.Equal(9, result); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Employees] AS [e] +WHERE FREETEXT([e].[Title], N'Representative Sales') +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_with_language_term() + { + using var context = CreateContext(); + var result = context.Employees.SingleOrDefault(c => EF.Functions.FreeText(c.Title, "President", 1033)); + + Assert.Equal(2u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE FREETEXT([e].[Title], N'President', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_with_non_literal_language_term() + { + var language = 1033; + using var context = CreateContext(); + var result = context.Employees.SingleOrDefault(c => EF.Functions.FreeText(c.Title, "President", language)); + + Assert.Equal(2u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE FREETEXT([e].[Title], N'President', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_with_multiple_words_and_language_term() + { + using var context = CreateContext(); + var result = context.Employees + .Where(c => EF.Functions.FreeText(c.Title, "Representative President", 1033)) + .ToList(); + + Assert.Equal(1u, result.First().EmployeeID); + + AssertSql( + """ +SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE FREETEXT([e].[Title], N'Representative President', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_multiple_predicates() + { + using var context = CreateContext(); + var result = context.Employees + .Where( + c => EF.Functions.FreeText(c.City, "London") + && EF.Functions.FreeText(c.Title, "Manager", 1033)) + .FirstOrDefault(); + + Assert.Equal(5u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE FREETEXT([e].[City], N'London') AND FREETEXT([e].[Title], N'Manager', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_throws_for_no_FullText_index() + { + using var context = CreateContext(); + Assert.Throws( + () => context.Employees.Where(c => EF.Functions.FreeText(c.FirstName, "Fred")).ToArray()); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_through_navigation() + { + using var context = CreateContext(); + var result = context.Employees + .Where( + c => EF.Functions.FreeText(c.Manager.Title, "President") + && EF.Functions.FreeText(c.Title, "Inside") + && c.FirstName.Contains("Lau")) + .OrderBy(e => e.EmployeeID) + .LastOrDefault(); + + Assert.Equal(8u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +LEFT JOIN [Employees] AS [e0] ON [e].[ReportsTo] = [e0].[EmployeeID] +WHERE FREETEXT([e0].[Title], N'President') AND FREETEXT([e].[Title], N'Inside') AND [e].[FirstName] LIKE N'%Lau%' +ORDER BY [e].[EmployeeID] DESC +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void FreeText_through_navigation_with_language_terms() + { + using var context = CreateContext(); + var result = context.Employees + .Where( + c => EF.Functions.FreeText(c.Manager.Title, "President", 1033) + && EF.Functions.FreeText(c.Title, "Inside", 1031) + && c.FirstName.Contains("Lau")) + .FirstOrDefault(); + + Assert.Equal(8u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +LEFT JOIN [Employees] AS [e0] ON [e].[ReportsTo] = [e0].[EmployeeID] +WHERE FREETEXT([e0].[Title], N'President', LANGUAGE 1033) AND FREETEXT([e].[Title], N'Inside', LANGUAGE 1031) AND [e].[FirstName] LIKE N'%Lau%' +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task FreeText_throws_when_using_non_parameter_or_constant_for_freetext_string() + { + using var context = CreateContext(); + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.FreeText(e.City, e.FirstName))); + + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.FreeText(e.City, ""))); + + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.FreeText(e.City, e.FirstName.ToUpper()))); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task FreeText_throws_when_using_non_column_for_property_reference() + { + using var context = CreateContext(); + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.FreeText(e.City + "1", "President"))); + + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.FreeText(e.City.ToLower(), "President"))); + + await Assert.ThrowsAsync( + async () => await (from e1 in context.Employees + join m1 in context.Employees.OrderBy(e => e.EmployeeID).Skip(0) + on e1.ReportsTo equals m1.EmployeeID + where EF.Functions.FreeText(m1.Title, "President") + select e1).LastOrDefaultAsync()); + } + + [ConditionalFact] + public void Contains_should_throw_on_client_eval() + { + var exNoLang = Assert.Throws(() => EF.Functions.Contains("teststring", "teststring")); + Assert.Equal( + CoreStrings.FunctionOnClient(nameof(SqlServerDbFunctionsExtensions.Contains)), + exNoLang.Message); + + var exLang = Assert.Throws(() => EF.Functions.Contains("teststring", "teststring", 1033)); + Assert.Equal( + CoreStrings.FunctionOnClient(nameof(SqlServerDbFunctionsExtensions.Contains)), + exLang.Message); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task Contains_should_throw_when_using_non_parameter_or_constant_for_contains_string() + { + using var context = CreateContext(); + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.Contains(e.City, e.FirstName))); + + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.Contains(e.City, ""))); + + await Assert.ThrowsAsync( + async () => await context.Employees.FirstOrDefaultAsync( + e => EF.Functions.Contains(e.City, e.FirstName.ToUpper()))); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void Contains_should_throw_for_no_FullText_index() + { + using var context = CreateContext(); + Assert.Throws( + () => context.Employees.Where(c => EF.Functions.Contains(c.FirstName, "Fred")).ToArray()); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task Contains_literal() + { + using var context = CreateContext(); + var result = await context.Employees + .Where(c => EF.Functions.Contains(c.Title, "Representative")) + .ToListAsync(); + + Assert.Equal(1u, result.First().EmployeeID); + + AssertSql( + """ +SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE CONTAINS([e].[Title], N'Representative') +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void Contains_with_language_term() + { + using var context = CreateContext(); + var result = context.Employees.SingleOrDefault(c => EF.Functions.Contains(c.Title, "President", 1033)); + + Assert.Equal(2u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE CONTAINS([e].[Title], N'President', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void Contains_with_non_literal_language_term() + { + var language = 1033; + using var context = CreateContext(); + var result = context.Employees.SingleOrDefault(c => EF.Functions.Contains(c.Title, "President", language)); + + Assert.Equal(2u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE CONTAINS([e].[Title], N'President', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task Contains_with_logical_operator() + { + using var context = CreateContext(); + var result = await context.Employees + .Where(c => EF.Functions.Contains(c.Title, "Vice OR Inside")) + .ToListAsync(); + + Assert.Equal(2, result.Count); + Assert.Equal(2u, result.First().EmployeeID); + + AssertSql( + """ +SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE CONTAINS([e].[Title], N'Vice OR Inside') +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task Contains_with_prefix_term_and_language_term() + { + using var context = CreateContext(); + var result = await context.Employees + .SingleOrDefaultAsync(c => EF.Functions.Contains(c.Title, "\"Mana*\"", 1033)); + + Assert.Equal(5u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE CONTAINS([e].[Title], N'"Mana*"', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public async Task Contains_with_proximity_term_and_language_term() + { + using var context = CreateContext(); + var result = await context.Employees + .SingleOrDefaultAsync(c => EF.Functions.Contains(c.Title, "NEAR((Sales, President), 1)", 1033)); + + Assert.Equal(2u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(2) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE CONTAINS([e].[Title], N'NEAR((Sales, President), 1)', LANGUAGE 1033) +"""); + } + + [ConditionalFact] + [SqlServerCondition(SqlServerCondition.SupportsFullTextSearch)] + public void Contains_through_navigation() + { + using var context = CreateContext(); + var result = context.Employees + .Where( + c => EF.Functions.Contains(c.Manager.Title, "President") + && EF.Functions.Contains(c.Title, "\"Ins*\"")) + .FirstOrDefault(); + + Assert.NotNull(result); + Assert.Equal(8u, result.EmployeeID); + + AssertSql( + """ +SELECT TOP(1) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +LEFT JOIN [Employees] AS [e0] ON [e].[ReportsTo] = [e0].[EmployeeID] +WHERE CONTAINS([e0].[Title], N'President') AND CONTAINS([e].[Title], N'"Ins*"') +"""); + } + + [ConditionalFact] + public async Task PatIndex_literal() + { + using var context = CreateContext(); + var result = await context.Employees + .Where(c => EF.Functions.PatIndex("%Nancy%", c.FirstName) == 1) + .ToListAsync(); + + Assert.Equal(1u, result.First().EmployeeID); + + AssertSql( + """ +SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] +FROM [Employees] AS [e] +WHERE PATINDEX(N'%Nancy%', [e].[FirstName]) = CAST(1 AS bigint) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Year(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffYear(c.OrderDate, DateTime.Now) == 0, + c => c.OrderDate.Value.Year - DateTime.Now.Year == 0); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(year, [o].[OrderDate], GETDATE()) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Month(bool async) + { + var now = DateTime.Now; + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffMonth(c.OrderDate, DateTime.Now) == 0, + c => c.OrderDate.Value.Year * 12 + c.OrderDate.Value.Month - (now.Year * 12 + now.Month) == 0); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(month, [o].[OrderDate], GETDATE()) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Day(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffDay(c.OrderDate, DateTime.Now) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(day, [o].[OrderDate], GETDATE()) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Hour(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffHour(c.OrderDate, DateTime.Now) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(hour, [o].[OrderDate], GETDATE()) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Minute(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffMinute(c.OrderDate, DateTime.Now) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(minute, [o].[OrderDate], GETDATE()) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Second(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffSecond(c.OrderDate, DateTime.Now) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(second, [o].[OrderDate], GETDATE()) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Millisecond(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffMillisecond(DateTime.Now, DateTime.Now.AddDays(1)) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(millisecond, GETDATE(), DATEADD(day, CAST(1.0E0 AS int), GETDATE())) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Microsecond(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffMicrosecond(DateTime.Now, DateTime.Now.AddSeconds(1)) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(microsecond, GETDATE(), DATEADD(second, CAST(1.0E0 AS int), GETDATE())) = 0 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateDiff_Nanosecond(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.DateDiffNanosecond(DateTime.Now, DateTime.Now.AddSeconds(1)) == 0, + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(nanosecond, GETDATE(), DATEADD(second, CAST(1.0E0 AS int), GETDATE())) = 0 +"""); + } + + [ConditionalFact] + public virtual void DateDiff_Week_datetime() + { + using var context = CreateContext(); + var count = context.Orders + .Count( + c => EF.Functions.DateDiffWeek( + c.OrderDate, + new DateTime(1998, 5, 6, 0, 0, 0)) + == 5); + + Assert.Equal(16, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(week, [o].[OrderDate], '1998-05-06T00:00:00.000') = 5 +"""); + } + + [ConditionalFact] + public virtual void DateDiff_Week_datetimeoffset() + { + using var context = CreateContext(); + var count = context.Orders + .Count( + c => EF.Functions.DateDiffWeek( + c.OrderDate, + new DateTimeOffset(1998, 5, 6, 0, 0, 0, TimeSpan.Zero)) + == 5); + + Assert.Equal(16, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(week, CAST([o].[OrderDate] AS datetimeoffset), '1998-05-06T00:00:00.0000000+00:00') = 5 +"""); + } + + [ConditionalFact] + public virtual void DateDiff_Week_parameters_null() + { + using var context = CreateContext(); + var count = context.Orders + .Count( + c => EF.Functions.DateDiffWeek( + null, + c.OrderDate) + == 5); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE DATEDIFF(week, NULL, [o].[OrderDate]) = 5 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task IsDate_not_valid(bool async) + { + await AssertQueryScalar( + async, + ss => ss.Set().Where(o => !EF.Functions.IsDate(o.CustomerID)).Select(o => EF.Functions.IsDate(o.CustomerID)), + ss => ss.Set().Select(c => false)); + + AssertSql( + """ +SELECT CAST(ISDATE([o].[CustomerID]) AS bit) +FROM [Orders] AS [o] +WHERE CAST(ISDATE([o].[CustomerID]) AS bit) = CAST(0 AS bit) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task IsDate_valid(bool async) + { + await AssertQueryScalar( + async, + ss => ss.Set() + .Where(o => EF.Functions.IsDate(o.OrderDate.Value.ToString())) + .Select(o => EF.Functions.IsDate(o.OrderDate.Value.ToString())), + ss => ss.Set().Select(o => true)); + + AssertSql( + """ +SELECT CAST(ISDATE(COALESCE(CONVERT(varchar(100), [o].[OrderDate]), '')) AS bit) +FROM [Orders] AS [o] +WHERE CAST(ISDATE(COALESCE(CONVERT(varchar(100), [o].[OrderDate]), '')) AS bit) = CAST(1 AS bit) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task IsDate_join_fields(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.IsDate(c.CustomerID + c.OrderID), + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE CAST(ISDATE(COALESCE([o].[CustomerID], N'') + CAST([o].[OrderID] AS nvarchar(max))) AS bit) = CAST(1 AS bit) +"""); + } + + [ConditionalFact] + public void IsDate_should_throw_on_client_eval() + { + var exIsDate = Assert.Throws(() => EF.Functions.IsDate("#ISDATE#")); + + Assert.Equal( + CoreStrings.FunctionOnClient(nameof(SqlServerDbFunctionsExtensions.IsDate)), + exIsDate.Message); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task IsNumeric_not_valid(bool async) + { + await AssertQueryScalar( + async, + ss => ss.Set() + .Where(o => !EF.Functions.IsNumeric(o.OrderDate.Value.ToString())) + .Select(o => EF.Functions.IsNumeric(o.OrderDate.Value.ToString())), + ss => ss.Set().Select(c => false)); + + AssertSql( + """ +SELECT ~CAST(ISNUMERIC(COALESCE(CONVERT(varchar(100), [o].[OrderDate]), '')) ^ 1 AS bit) +FROM [Orders] AS [o] +WHERE ISNUMERIC(COALESCE(CONVERT(varchar(100), [o].[OrderDate]), '')) <> 1 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task IsNummeric_valid(bool async) + { + await AssertQueryScalar( + async, + ss => ss.Set() + .Where(o => EF.Functions.IsNumeric(o.UnitPrice.ToString())) + .Select(o => EF.Functions.IsNumeric(o.UnitPrice.ToString())), + ss => ss.Set().Select(o => true)); + + AssertSql( + """ +SELECT ~CAST(ISNUMERIC(CONVERT(varchar(100), [o].[UnitPrice])) ^ 1 AS bit) +FROM [Order Details] AS [o] +WHERE ISNUMERIC(CONVERT(varchar(100), [o].[UnitPrice])) = 1 +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task IsNumeric_join_fields(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => EF.Functions.IsNumeric(c.CustomerID + c.OrderID), + c => false); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE ISNUMERIC(COALESCE([o].[CustomerID], N'') + CAST([o].[OrderID] AS nvarchar(max))) = 1 +"""); + } + + [ConditionalFact] + public void IsNumeric_should_throw_on_client_eval() + { + var exIsDate = Assert.Throws(() => EF.Functions.IsNumeric("#ISNUMERIC#")); + + Assert.Equal( + CoreStrings.FunctionOnClient(nameof(SqlServerDbFunctionsExtensions.IsNumeric)), + exIsDate.Message); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateTimeFromParts_column_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => c.OrderDate > EF.Functions.DateTimeFromParts(DateTime.Now.Year, 12, 31, 23, 59, 59, 999), + c => c.OrderDate > new DateTime(DateTime.Now.Year, 12, 31, 23, 59, 59, 999)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > DATETIMEFROMPARTS(DATEPART(year, GETDATE()), 12, 31, 23, 59, 59, 999) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateTimeFromParts_constant_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => new DateTime(2018, 12, 29, 23, 20, 40) > EF.Functions.DateTimeFromParts(DateTime.Now.Year, 12, 31, 23, 59, 59, 999), + c => new DateTime(2018, 12, 29, 23, 20, 40) > new DateTime(DateTime.Now.Year, 12, 31, 23, 59, 59, 999)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE '2018-12-29T23:20:40.000' > DATETIMEFROMPARTS(DATEPART(year, GETDATE()), 12, 31, 23, 59, 59, 999) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateTimeFromParts_compare_with_local_variable(bool async) + { + var dateTime = new DateTime(1919, 12, 12, 10, 20, 15, 0); + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => dateTime + > EF.Functions.DateTimeFromParts( + DateTime.Now.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, + dateTime.Millisecond), + c => dateTime + > new DateTime( + DateTime.Now.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, + dateTime.Millisecond)); + + AssertSql( + """ +@__dateTime_7='1919-12-12T10:20:15.0000000' (DbType = DateTime) +@__dateTime_Month_1='12' +@__dateTime_Day_2='12' +@__dateTime_Hour_3='10' +@__dateTime_Minute_4='20' +@__dateTime_Second_5='15' +@__dateTime_Millisecond_6='0' + +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE @__dateTime_7 > DATETIMEFROMPARTS(DATEPART(year, GETDATE()), @__dateTime_Month_1, @__dateTime_Day_2, @__dateTime_Hour_3, @__dateTime_Minute_4, @__dateTime_Second_5, @__dateTime_Millisecond_6) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateFromParts_column_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => c.OrderDate > EF.Functions.DateFromParts(DateTime.Now.Year, 12, 31), + c => c.OrderDate > new DateTime(DateTime.Now.Year, 12, 31)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > DATEFROMPARTS(DATEPART(year, GETDATE()), 12, 31) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateFromParts_constant_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => new DateTime(2018, 12, 29) > EF.Functions.DateFromParts(DateTime.Now.Year, 12, 31), + c => new DateTime(2018, 12, 29) > new DateTime(DateTime.Now.Year, 12, 31)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE '2018-12-29' > DATEFROMPARTS(DATEPART(year, GETDATE()), 12, 31) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DateFromParts_compare_with_local_variable(bool async) + { + var date = new DateTime(1919, 12, 12); + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => date > EF.Functions.DateFromParts(DateTime.Now.Year, date.Month, date.Day), + c => date > new DateTime(DateTime.Now.Year, date.Month, date.Day)); + + AssertSql( + """ +@__date_3='1919-12-12T00:00:00.0000000' (DbType = Date) +@__date_Month_1='12' +@__date_Day_2='12' + +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE @__date_3 > DATEFROMPARTS(DATEPART(year, GETDATE()), @__date_Month_1, @__date_Day_2) +"""); + } + + [ConditionalFact] + public virtual void DateTime2FromParts_column_compare() + { + using (var context = CreateContext()) + { + var count = context.Orders + .Count(c => c.OrderDate > EF.Functions.DateTime2FromParts(DateTime.Now.Year, 12, 31, 23, 59, 59, 999, 3)); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > DATETIME2FROMPARTS(DATEPART(year, GETDATE()), 12, 31, 23, 59, 59, 999, 3) +"""); + } + } + + [ConditionalFact] + public virtual void DateTime2FromParts_constant_compare() + { + using (var context = CreateContext()) + { + var count = context.Orders + .Count( + c => new DateTime(2018, 12, 29, 23, 20, 40) + > EF.Functions.DateTime2FromParts(DateTime.Now.Year, 12, 31, 23, 59, 59, 9999999, 7)); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE '2018-12-29T23:20:40.0000000' > DATETIME2FROMPARTS(DATEPART(year, GETDATE()), 12, 31, 23, 59, 59, 9999999, 7) +"""); + } + } + + [ConditionalFact] + public virtual void DateTime2FromParts_compare_with_local_variable() + { + var dateTime = new DateTime(1919, 12, 12, 10, 20, 15); + var fractions = 9999999; + using (var context = CreateContext()) + { + var count = context.Orders + .Count( + c => dateTime + > EF.Functions.DateTime2FromParts( + DateTime.Now.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, fractions, + 7)); + + Assert.Equal(0, count); + + AssertSql( + """ +@__dateTime_7='1919-12-12T10:20:15.0000000' +@__dateTime_Month_1='12' +@__dateTime_Day_2='12' +@__dateTime_Hour_3='10' +@__dateTime_Minute_4='20' +@__dateTime_Second_5='15' +@__fractions_6='9999999' + +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE @__dateTime_7 > DATETIME2FROMPARTS(DATEPART(year, GETDATE()), @__dateTime_Month_1, @__dateTime_Day_2, @__dateTime_Hour_3, @__dateTime_Minute_4, @__dateTime_Second_5, @__fractions_6, 7) +"""); + } + } + + [ConditionalFact] + public virtual void DateTimeOffsetFromParts_column_compare() + { + using (var context = CreateContext()) + { + var count = context.Orders + .Count(c => c.OrderDate > EF.Functions.DateTimeOffsetFromParts(DateTime.Now.Year, 12, 31, 23, 59, 59, 5, 12, 30, 1)); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE CAST([o].[OrderDate] AS datetimeoffset) > DATETIMEOFFSETFROMPARTS(DATEPART(year, GETDATE()), 12, 31, 23, 59, 59, 5, 12, 30, 1) +"""); + } + } + + [ConditionalFact] + public virtual void DateTimeOffsetFromParts_constant_compare() + { + using (var context = CreateContext()) + { + var count = context.Orders + .Count( + c => new DateTimeOffset(2018, 12, 29, 23, 20, 40, new TimeSpan(1, 0, 0)) + > EF.Functions.DateTimeOffsetFromParts(DateTime.Now.Year, 12, 31, 23, 59, 59, 50, 1, 0, 7)); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE '2018-12-29T23:20:40.0000000+01:00' > DATETIMEOFFSETFROMPARTS(DATEPART(year, GETDATE()), 12, 31, 23, 59, 59, 50, 1, 0, 7) +"""); + } + } + + [ConditionalFact] + public virtual void DateTimeOffsetFromParts_compare_with_local_variable() + { + var dateTimeOffset = new DateTimeOffset(1919, 12, 12, 10, 20, 15, new TimeSpan(1, 30, 0)); + var fractions = 5; + var hourOffset = 1; + var minuteOffset = 30; + using (var context = CreateContext()) + { + var count = context.Orders + .Count( + c => dateTimeOffset + > EF.Functions.DateTimeOffsetFromParts( + DateTime.Now.Year, dateTimeOffset.Month, dateTimeOffset.Day, dateTimeOffset.Hour, dateTimeOffset.Minute, + dateTimeOffset.Second, fractions, hourOffset, minuteOffset, 7)); + + Assert.Equal(0, count); + + AssertSql( + """ +@__dateTimeOffset_9='1919-12-12T10:20:15.0000000+01:30' +@__dateTimeOffset_Month_1='12' +@__dateTimeOffset_Day_2='12' +@__dateTimeOffset_Hour_3='10' +@__dateTimeOffset_Minute_4='20' +@__dateTimeOffset_Second_5='15' +@__fractions_6='5' +@__hourOffset_7='1' +@__minuteOffset_8='30' + +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE @__dateTimeOffset_9 > DATETIMEOFFSETFROMPARTS(DATEPART(year, GETDATE()), @__dateTimeOffset_Month_1, @__dateTimeOffset_Day_2, @__dateTimeOffset_Hour_3, @__dateTimeOffset_Minute_4, @__dateTimeOffset_Second_5, @__fractions_6, @__hourOffset_7, @__minuteOffset_8, 7) +"""); + } + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task SmallDateTimeFromParts_column_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => c.OrderDate > EF.Functions.SmallDateTimeFromParts(DateTime.Now.Year, 12, 31, 12, 59), + c => c.OrderDate > new DateTime(DateTime.Now.Year, 12, 31, 12, 59, 0)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > SMALLDATETIMEFROMPARTS(DATEPART(year, GETDATE()), 12, 31, 12, 59) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task SmallDateTimeFromParts_constant_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => new DateTime(2018, 12, 29, 23, 20, 0) > EF.Functions.SmallDateTimeFromParts(DateTime.Now.Year, 12, 31, 12, 59), + c => new DateTime(2018, 12, 29, 23, 20, 0) > new DateTime(DateTime.Now.Year, 12, 31, 12, 59, 0)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE '2018-12-29T23:20:00' > SMALLDATETIMEFROMPARTS(DATEPART(year, GETDATE()), 12, 31, 12, 59) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task SmallDateTimeFromParts_compare_with_local_variable(bool async) + { + var dateTime = new DateTime(1919, 12, 12, 23, 20, 0); + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => dateTime + > EF.Functions.SmallDateTimeFromParts(DateTime.Now.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute), + c => dateTime > new DateTime(DateTime.Now.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0)); + + AssertSql( + """ +@__dateTime_5='1919-12-12T23:20:00.0000000' (DbType = DateTime) +@__dateTime_Month_1='12' +@__dateTime_Day_2='12' +@__dateTime_Hour_3='23' +@__dateTime_Minute_4='20' + +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE @__dateTime_5 > SMALLDATETIMEFROMPARTS(DATEPART(year, GETDATE()), @__dateTime_Month_1, @__dateTime_Day_2, @__dateTime_Hour_3, @__dateTime_Minute_4) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task TimeFromParts_constant_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => new TimeSpan(23, 59, 0) > EF.Functions.TimeFromParts(23, 59, 59, c.OrderID % 60, 3), + c => new TimeSpan(23, 59, 0) > new TimeSpan(0, 23, 59, 59, c.OrderID % 60)); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE '23:59:00' > TIMEFROMPARTS(23, 59, 59, [o].[OrderID] % 60, 3) +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task TimeFromParts_select(bool async) + { + await AssertQueryScalar( + async, + ss => ss.Set() + .Select(o => EF.Functions.TimeFromParts(23, 59, 59, o.OrderID % 60, 3)), + ss => ss.Set().Select(o => new TimeSpan(0, 23, 59, 59, o.OrderID % 60))); + + AssertSql( + """ +SELECT TIMEFROMPARTS(23, 59, 59, [o].[OrderID] % 60, 3) +FROM [Orders] AS [o] +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task DataLength_column_compare(bool async) + { + await AssertCount( + async, + ss => ss.Set(), + ss => ss.Set(), + c => c.OrderID % 10 == EF.Functions.DataLength(c.OrderDate), + c => c.OrderID % 10 == 8); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE [o].[OrderID] % 10 = DATALENGTH([o].[OrderDate]) +"""); + } + + [ConditionalFact] + public virtual void DataLength_constant_compare() + { + using (var context = CreateContext()) + { + var count = context.Orders + .Count(c => 100 < EF.Functions.DataLength(c.OrderDate)); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE 100 < DATALENGTH([o].[OrderDate]) +"""); + } + } + + [ConditionalFact] + public virtual void DataLength_compare_with_local_variable() + { + int? length = 100; + using (var context = CreateContext()) + { + var count = context.Orders + .Count(c => length < EF.Functions.DataLength(c.OrderDate)); + + Assert.Equal(0, count); + + AssertSql( + """ +@__length_1='100' (Nullable = true) + +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE @__length_1 < DATALENGTH([o].[OrderDate]) +"""); + } + } + + [ConditionalFact] + public virtual void DataLength_all_constants() + { + using (var context = CreateContext()) + { + var count = context.Orders + .Count(c => EF.Functions.DataLength("foo") == 3); + + Assert.Equal(0, count); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE CAST(DATALENGTH(N'foo') AS int) = 3 +"""); + } + } + + public override async Task Random_return_less_than_1(bool async) + { + await base.Random_return_less_than_1(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE RAND() < 1.0E0 +"""); + } + + public override async Task Random_return_greater_than_0(bool async) + { + await base.Random_return_greater_than_0(async); + + AssertSql( + """ +SELECT COUNT(*) +FROM [Orders] AS [o] +WHERE RAND() >= 0.0E0 +"""); + } + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + + public class Fixture160 : NorthwindQuerySqlServerFixture + { + public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) + => base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160)); + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServerTest.cs index f37ff6ba75d..6d6c0dd17f3 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServerTest.cs @@ -133,57 +133,17 @@ WHERE [c].[Region] IS NULL """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Least(bool async) - { - await base.Least(async); - - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE LEAST([o].[OrderID], 10251) = 10251 -"""); - } - - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Greatest(bool async) - { - await base.Greatest(async); - - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE GREATEST([o].[OrderID], 10251) = 10251 -"""); - } - - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Least_with_nullable_value_type(bool async) - { - await base.Least_with_nullable_value_type(async); + public override Task Least(bool async) + => AssertTranslationFailed(() => base.Least(async)); - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE LEAST([o].[OrderID], 10251) = 10251 -"""); - } + public override Task Greatest(bool async) + => AssertTranslationFailed(() => base.Greatest(async)); - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Greatest_with_nullable_value_type(bool async) - { - await base.Greatest_with_nullable_value_type(async); + public override Task Least_with_nullable_value_type(bool async) + => AssertTranslationFailed(() => base.Least_with_nullable_value_type(async)); - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE GREATEST([o].[OrderID], 10251) = 10251 -"""); - } + public override Task Greatest_with_nullable_value_type(bool async) + => AssertTranslationFailed(() => base.Greatest_with_nullable_value_type(async)); public override async Task Least_with_parameter_array_is_not_supported(bool async) { diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServer160Test.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServer160Test.cs new file mode 100644 index 00000000000..555f1733719 --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServer160Test.cs @@ -0,0 +1,3013 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable +using Microsoft.EntityFrameworkCore.TestModels.Northwind; + +namespace Microsoft.EntityFrameworkCore.Query; + +[SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] +public class NorthwindFunctionsQuerySqlServer160Test + : NorthwindFunctionsQueryRelationalTestBase +{ + public NorthwindFunctionsQuerySqlServer160Test(Fixture160 fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + ClearLog(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + public override async Task TimeSpan_Compare_to_simple_zero(bool async, bool compareTo) + { + await base.TimeSpan_Compare_to_simple_zero(async, compareTo); + + AssertSql( + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] = @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] <> @__myDatetime_0 OR [o].[OrderDate] IS NULL +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] <= @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] <= @__myDatetime_0 +"""); + } + + #region String.StartsWith + + public override async Task String_StartsWith_Literal(bool async) + { + await base.String_StartsWith_Literal(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'M%' +"""); + } + + public override async Task String_StartsWith_Parameter(bool async) + { + await base.String_StartsWith_Parameter(async); + + AssertSql( + """ +@__pattern_0_startswith='M%' (Size = 30) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE @__pattern_0_startswith ESCAPE N'\' +"""); + } + + public override async Task String_StartsWith_Identity(bool async) + { + await base.String_StartsWith_Identity(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NOT NULL AND LEFT([c].[ContactName], LEN([c].[ContactName])) = [c].[ContactName] +"""); + } + + public override async Task String_StartsWith_Column(bool async) + { + await base.String_StartsWith_Column(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NOT NULL AND LEFT([c].[ContactName], LEN([c].[ContactName])) = [c].[ContactName] +"""); + } + + public override async Task String_StartsWith_MethodCall(bool async) + { + await base.String_StartsWith_MethodCall(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'M%' +"""); + } + + public override async Task String_StartsWith_with_StringComparison_Ordinal(bool async) + { + await base.String_StartsWith_with_StringComparison_Ordinal(async); + + AssertSql(); + } + + public override async Task String_StartsWith_with_StringComparison_OrdinalIgnoreCase(bool async) + { + await base.String_StartsWith_with_StringComparison_OrdinalIgnoreCase(async); + + AssertSql(); + } + + public override async Task String_StartsWith_with_StringComparison_unsupported(bool async) + { + await base.String_StartsWith_with_StringComparison_unsupported(async); + + AssertSql(); + } + + #endregion String.StartsWith + + #region String.EndsWith + + public override async Task String_EndsWith_Literal(bool async) + { + await base.String_EndsWith_Literal(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'%b' +"""); + } + + public override async Task String_EndsWith_Parameter(bool async) + { + await base.String_EndsWith_Parameter(async); + + AssertSql( + """ +@__pattern_0_endswith='%b' (Size = 30) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE @__pattern_0_endswith ESCAPE N'\' +"""); + } + + public override async Task String_EndsWith_Identity(bool async) + { + await base.String_EndsWith_Identity(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NOT NULL AND RIGHT([c].[ContactName], LEN([c].[ContactName])) = [c].[ContactName] +"""); + } + + public override async Task String_EndsWith_Column(bool async) + { + await base.String_EndsWith_Column(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NOT NULL AND RIGHT([c].[ContactName], LEN([c].[ContactName])) = [c].[ContactName] +"""); + } + + public override async Task String_EndsWith_MethodCall(bool async) + { + await base.String_EndsWith_MethodCall(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'%m' +"""); + } + + public override async Task String_EndsWith_with_StringComparison_Ordinal(bool async) + { + await base.String_EndsWith_with_StringComparison_Ordinal(async); + + AssertSql(); + } + + public override async Task String_EndsWith_with_StringComparison_OrdinalIgnoreCase(bool async) + { + await base.String_EndsWith_with_StringComparison_OrdinalIgnoreCase(async); + + AssertSql(); + } + + public override async Task String_EndsWith_with_StringComparison_unsupported(bool async) + { + await base.String_EndsWith_with_StringComparison_unsupported(async); + + AssertSql(); + } + + #endregion String.EndsWith + + public override async Task String_Contains_Literal(bool async) + { + await AssertQuery( + async, + ss => ss.Set().Where(c => c.ContactName.Contains("M")), // case-insensitive + ss => ss.Set().Where(c => c.ContactName.Contains("M") || c.ContactName.Contains("m"))); // case-sensitive + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'%M%' +"""); + } + + public override async Task String_Contains_Identity(bool async) + { + await base.String_Contains_Identity(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NOT NULL AND (CHARINDEX([c].[ContactName], [c].[ContactName]) > 0 OR [c].[ContactName] LIKE N'') +"""); + } + + public override async Task String_Contains_Column(bool async) + { + await base.String_Contains_Column(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NOT NULL AND (CHARINDEX([c].[ContactName], [c].[CompanyName]) > 0 OR [c].[ContactName] LIKE N'') +"""); + } + + public override async Task String_Contains_constant_with_whitespace(bool async) + { + await base.String_Contains_constant_with_whitespace(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'% %' +"""); + } + + public override async Task String_Contains_parameter_with_whitespace(bool async) + { + await base.String_Contains_parameter_with_whitespace(async); + + AssertSql( + """ +@__pattern_0_contains='% %' (Size = 30) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE @__pattern_0_contains ESCAPE N'\' +"""); + } + + public override async Task String_FirstOrDefault_MethodCall(bool async) + { + await base.String_FirstOrDefault_MethodCall(async); + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE SUBSTRING([c].[ContactName], 1, 1) = N'A' +"""); + } + + public override async Task String_LastOrDefault_MethodCall(bool async) + { + await base.String_LastOrDefault_MethodCall(async); + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE SUBSTRING([c].[ContactName], LEN([c].[ContactName]), 1) = N's' +"""); + } + + public override async Task String_Contains_MethodCall(bool async) + { + await AssertQuery( + async, + ss => ss.Set().Where(c => c.ContactName.Contains(LocalMethod1())), // case-insensitive + ss => ss.Set().Where( + c => c.ContactName.Contains(LocalMethod1().ToLower()) + || c.ContactName.Contains(LocalMethod1().ToUpper()))); // case-sensitive + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] LIKE N'%M%' +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2017)] + public override async Task String_Join_over_non_nullable_column(bool async) + { + await base.String_Join_over_non_nullable_column(async); + + AssertSql( + """ +SELECT [c].[City], COALESCE(STRING_AGG([c].[CustomerID], N'|'), N'') AS [Customers] +FROM [Customers] AS [c] +GROUP BY [c].[City] +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2017)] + public override async Task String_Join_over_nullable_column(bool async) + { + await base.String_Join_over_nullable_column(async); + + AssertSql( + """ +SELECT [c].[City], COALESCE(STRING_AGG(COALESCE([c].[Region], N''), N'|'), N'') AS [Regions] +FROM [Customers] AS [c] +GROUP BY [c].[City] +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2017)] + public override async Task String_Join_with_predicate(bool async) + { + await base.String_Join_with_predicate(async); + + AssertSql( + """ +SELECT [c].[City], COALESCE(STRING_AGG(CASE + WHEN CAST(LEN([c].[ContactName]) AS int) > 10 THEN [c].[CustomerID] +END, N'|'), N'') AS [Customers] +FROM [Customers] AS [c] +GROUP BY [c].[City] +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2017)] + public override async Task String_Join_with_ordering(bool async) + { + await base.String_Join_with_ordering(async); + + AssertSql( + """ +SELECT [c].[City], COALESCE(STRING_AGG([c].[CustomerID], N'|') WITHIN GROUP (ORDER BY [c].[CustomerID] DESC), N'') AS [Customers] +FROM [Customers] AS [c] +GROUP BY [c].[City] +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2017)] + public override async Task String_Join_non_aggregate(bool async) + { + await base.String_Join_non_aggregate(async); + + AssertSql( + """ +@__foo_0='foo' (Size = 4000) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CONCAT_WS(N'|', [c].[CompanyName], @__foo_0, N'', N'bar') = N'Around the Horn|foo||bar' +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsFunctions2017)] + public override async Task String_Concat(bool async) + { + await base.String_Concat(async); + + AssertSql( + """ +SELECT [c].[City], COALESCE(STRING_AGG([c].[CustomerID], N''), N'') AS [Customers] +FROM [Customers] AS [c] +GROUP BY [c].[City] +"""); + } + + public override async Task String_Compare_simple_zero(bool async) + { + await base.String_Compare_simple_zero(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <> N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +"""); + } + + public override async Task String_Compare_simple_one(bool async) + { + await base.String_Compare_simple_one(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] < N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= N'AROUT' +"""); + } + + public override async Task String_compare_with_parameter(bool async) + { + await base.String_compare_with_parameter(async); + + AssertSql( + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] < @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= @__customer_CustomerID_0 +"""); + } + + public override async Task String_Compare_simple_more_than_one(bool async) + { + await base.String_Compare_simple_more_than_one(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CASE + WHEN [c].[CustomerID] = N'ALFKI' THEN 0 + WHEN [c].[CustomerID] > N'ALFKI' THEN 1 + WHEN [c].[CustomerID] < N'ALFKI' THEN -1 +END = 42 +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CASE + WHEN [c].[CustomerID] = N'ALFKI' THEN 0 + WHEN [c].[CustomerID] > N'ALFKI' THEN 1 + WHEN [c].[CustomerID] < N'ALFKI' THEN -1 +END > 42 +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE 42 > CASE + WHEN [c].[CustomerID] = N'ALFKI' THEN 0 + WHEN [c].[CustomerID] > N'ALFKI' THEN 1 + WHEN [c].[CustomerID] < N'ALFKI' THEN -1 +END +"""); + } + + public override async Task String_Compare_nested(bool async) + { + await base.String_Compare_nested(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'M' + [c].[CustomerID] +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <> UPPER([c].[CustomerID]) +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > REPLACE(N'ALFKI', N'ALF', [c].[CustomerID]) +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'M' + [c].[CustomerID] +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > UPPER([c].[CustomerID]) +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] < REPLACE(N'ALFKI', N'ALF', [c].[CustomerID]) +"""); + } + + public override async Task String_Compare_multi_predicate(bool async) + { + await base.String_Compare_multi_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= N'ALFKI' AND [c].[CustomerID] < N'CACTU' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactTitle] = N'Owner' AND ([c].[Country] <> N'USA' OR [c].[Country] IS NULL) +"""); + } + + public override async Task String_Compare_to_simple_zero(bool async) + { + await base.String_Compare_to_simple_zero(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <> N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +"""); + } + + public override async Task String_Compare_to_simple_one(bool async) + { + await base.String_Compare_to_simple_one(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] < N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= N'AROUT' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= N'AROUT' +"""); + } + + public override async Task String_compare_to_with_parameter(bool async) + { + await base.String_compare_to_with_parameter(async); + + AssertSql( + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] < @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= @__customer_CustomerID_0 +""", + // + """ +@__customer_CustomerID_0='AROUT' (Size = 5) (DbType = StringFixedLength) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= @__customer_CustomerID_0 +"""); + } + + public override async Task String_Compare_to_simple_more_than_one(bool async) + { + await base.String_Compare_to_simple_more_than_one(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CASE + WHEN [c].[CustomerID] = N'ALFKI' THEN 0 + WHEN [c].[CustomerID] > N'ALFKI' THEN 1 + WHEN [c].[CustomerID] < N'ALFKI' THEN -1 +END = 42 +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CASE + WHEN [c].[CustomerID] = N'ALFKI' THEN 0 + WHEN [c].[CustomerID] > N'ALFKI' THEN 1 + WHEN [c].[CustomerID] < N'ALFKI' THEN -1 +END > 42 +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE 42 > CASE + WHEN [c].[CustomerID] = N'ALFKI' THEN 0 + WHEN [c].[CustomerID] > N'ALFKI' THEN 1 + WHEN [c].[CustomerID] < N'ALFKI' THEN -1 +END +"""); + } + + public override async Task String_Compare_to_nested(bool async) + { + await base.String_Compare_to_nested(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <> N'M' + [c].[CustomerID] +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = UPPER([c].[CustomerID]) +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > REPLACE(N'AROUT', N'OUT', [c].[CustomerID]) +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] <= N'M' + [c].[CustomerID] +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] > UPPER([c].[CustomerID]) +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] < REPLACE(N'AROUT', N'OUT', [c].[CustomerID]) +"""); + } + + public override async Task String_Compare_to_multi_predicate(bool async) + { + await base.String_Compare_to_multi_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] >= N'ALFKI' AND [c].[CustomerID] < N'CACTU' +""", + // + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactTitle] = N'Owner' AND ([c].[Country] <> N'USA' OR [c].[Country] IS NULL) +"""); + } + + public override async Task DateTime_Compare_to_simple_zero(bool async, bool compareTo) + { + await base.DateTime_Compare_to_simple_zero(async, compareTo); + + AssertSql( + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] = @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] <> @__myDatetime_0 OR [o].[OrderDate] IS NULL +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] <= @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] > @__myDatetime_0 +""", + // + """ +@__myDatetime_0='1998-05-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] <= @__myDatetime_0 +"""); + } + + public override async Task Int_Compare_to_simple_zero(bool async) + { + await base.Int_Compare_to_simple_zero(async); + + AssertSql( + """ +@__orderId_0='10250' + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderID] = @__orderId_0 +""", + // + """ +@__orderId_0='10250' + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderID] <> @__orderId_0 +""", + // + """ +@__orderId_0='10250' + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderID] > @__orderId_0 +""", + // + """ +@__orderId_0='10250' + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderID] <= @__orderId_0 +""", + // + """ +@__orderId_0='10250' + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderID] > @__orderId_0 +""", + // + """ +@__orderId_0='10250' + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderID] <= @__orderId_0 +"""); + } + + public override async Task Where_math_abs1(bool async) + { + await base.Where_math_abs1(async); + + AssertSql( + """ +SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock] +FROM [Products] AS [p] +WHERE ABS([p].[ProductID]) > 10 +"""); + } + + public override async Task Where_math_abs2(bool async) + { + await base.Where_math_abs2(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[UnitPrice] < 7.0 AND ABS([o].[Quantity]) > CAST(10 AS smallint) +"""); + } + + public override async Task Where_math_abs3(bool async) + { + await base.Where_math_abs3(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND ABS([o].[UnitPrice]) > 10.0 +"""); + } + + public override async Task Where_math_abs_uncorrelated(bool async) + { + await base.Where_math_abs_uncorrelated(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[UnitPrice] < 7.0 AND 10 < [o].[ProductID] +"""); + } + + public override async Task Where_math_ceiling1(bool async) + { + await base.Where_math_ceiling1(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[UnitPrice] < 7.0 AND CEILING(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_ceiling2(bool async) + { + await base.Where_math_ceiling2(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND CEILING([o].[UnitPrice]) > 10.0 +"""); + } + + public override async Task Where_math_floor(bool async) + { + await base.Where_math_floor(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND FLOOR([o].[UnitPrice]) > 10.0 +"""); + } + + public override async Task Where_math_power(bool async) + { + await base.Where_math_power(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE POWER(CAST([o].[Discount] AS float), 3.0E0) > 0.004999999888241291E0 +"""); + } + + public override async Task Where_math_square(bool async) + { + await base.Where_math_square(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE POWER(CAST([o].[Discount] AS float), 2.0E0) > 0.05000000074505806E0 +"""); + } + + public override async Task Where_math_round(bool async) + { + await base.Where_math_round(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND ROUND([o].[UnitPrice], 0) > 10.0 +"""); + } + + public override async Task Sum_over_round_works_correctly_in_projection(bool async) + { + await base.Sum_over_round_works_correctly_in_projection(async); + + AssertSql( + """ +SELECT [o].[OrderID], ( + SELECT COALESCE(SUM(ROUND([o0].[UnitPrice], 2)), 0.0) + FROM [Order Details] AS [o0] + WHERE [o].[OrderID] = [o0].[OrderID]) AS [Sum] +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10300 +"""); + } + + public override async Task Sum_over_round_works_correctly_in_projection_2(bool async) + { + await base.Sum_over_round_works_correctly_in_projection_2(async); + + AssertSql( + """ +SELECT [o].[OrderID], ( + SELECT COALESCE(SUM(ROUND([o0].[UnitPrice] * [o0].[UnitPrice], 2)), 0.0) + FROM [Order Details] AS [o0] + WHERE [o].[OrderID] = [o0].[OrderID]) AS [Sum] +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10300 +"""); + } + + public override async Task Sum_over_truncate_works_correctly_in_projection(bool async) + { + await base.Sum_over_truncate_works_correctly_in_projection(async); + + AssertSql( + """ +SELECT [o].[OrderID], ( + SELECT COALESCE(SUM(ROUND([o0].[UnitPrice], 0, 1)), 0.0) + FROM [Order Details] AS [o0] + WHERE [o].[OrderID] = [o0].[OrderID]) AS [Sum] +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10300 +"""); + } + + public override async Task Sum_over_truncate_works_correctly_in_projection_2(bool async) + { + await base.Sum_over_truncate_works_correctly_in_projection_2(async); + + AssertSql( + """ +SELECT [o].[OrderID], ( + SELECT COALESCE(SUM(ROUND([o0].[UnitPrice] * [o0].[UnitPrice], 0, 1)), 0.0) + FROM [Order Details] AS [o0] + WHERE [o].[OrderID] = [o0].[OrderID]) AS [Sum] +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10300 +"""); + } + + public override async Task Select_math_round_int(bool async) + { + await base.Select_math_round_int(async); + + AssertSql( + """ +SELECT ROUND(CAST([o].[OrderID] AS float), 0) AS [A] +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10250 +"""); + } + + public override async Task Select_math_truncate_int(bool async) + { + await base.Select_math_truncate_int(async); + + AssertSql( + """ +SELECT ROUND(CAST([o].[OrderID] AS float), 0, 1) AS [A] +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10250 +"""); + } + + public override async Task Where_math_round2(bool async) + { + await base.Where_math_round2(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE ROUND([o].[UnitPrice], 2) > 100.0 +"""); + } + + public override async Task Where_math_truncate(bool async) + { + await base.Where_math_truncate(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND ROUND([o].[UnitPrice], 0, 1) > 10.0 +"""); + } + + public override async Task Where_math_exp(bool async) + { + await base.Where_math_exp(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND EXP(CAST([o].[Discount] AS float)) > 1.0E0 +"""); + } + + public override async Task Where_math_log10(bool async) + { + await base.Where_math_log10(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND [o].[Discount] > CAST(0 AS real) AND LOG10(CAST([o].[Discount] AS float)) < 0.0E0 +"""); + } + + public override async Task Where_math_log(bool async) + { + await base.Where_math_log(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND [o].[Discount] > CAST(0 AS real) AND LOG(CAST([o].[Discount] AS float)) < 0.0E0 +"""); + } + + public override async Task Where_math_log_new_base(bool async) + { + await base.Where_math_log_new_base(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND [o].[Discount] > CAST(0 AS real) AND LOG(CAST([o].[Discount] AS float), 7.0E0) < -1.0E0 +"""); + } + + public override async Task Where_math_sqrt(bool async) + { + await base.Where_math_sqrt(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND SQRT(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_acos(bool async) + { + await base.Where_math_acos(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ACOS(CAST([o].[Discount] AS float)) > 1.0E0 +"""); + } + + public override async Task Where_math_asin(bool async) + { + await base.Where_math_asin(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ASIN(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_atan(bool async) + { + await base.Where_math_atan(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ATAN(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_atan2(bool async) + { + await base.Where_math_atan2(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ATN2(CAST([o].[Discount] AS float), 1.0E0) > 0.0E0 +"""); + } + + public override async Task Where_math_cos(bool async) + { + await base.Where_math_cos(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND COS(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_sin(bool async) + { + await base.Where_math_sin(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND SIN(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_tan(bool async) + { + await base.Where_math_tan(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND TAN(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_sign(bool async) + { + await base.Where_math_sign(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND SIGN([o].[Discount]) > 0 +"""); + } + + public override async Task Where_math_min(bool async) + { + await base.Where_math_min(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND LEAST([o].[OrderID], [o].[ProductID]) = [o].[ProductID] +"""); + } + + public override async Task Where_math_min_nested(bool async) + { + await base.Where_math_min_nested(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND LEAST([o].[OrderID], [o].[ProductID], 99999) = [o].[ProductID] +"""); + } + + public override async Task Where_math_min_nested_twice(bool async) + { + await base.Where_math_min_nested_twice(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND LEAST(99999, [o].[OrderID], 99998, [o].[ProductID]) = [o].[ProductID] +"""); + } + + public override async Task Where_math_max(bool async) + { + await base.Where_math_max(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND GREATEST([o].[OrderID], [o].[ProductID]) = [o].[OrderID] +"""); + } + + public override async Task Where_math_max_nested(bool async) + { + await base.Where_math_max_nested(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND GREATEST([o].[OrderID], [o].[ProductID], 1) = [o].[OrderID] +"""); + } + + public override async Task Where_math_max_nested_twice(bool async) + { + await base.Where_math_max_nested_twice(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND GREATEST(1, [o].[OrderID], 2, [o].[ProductID]) = [o].[OrderID] +"""); + } + + public override async Task Where_math_degrees(bool async) + { + await base.Where_math_degrees(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND DEGREES(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_math_radians(bool async) + { + await base.Where_math_radians(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND RADIANS(CAST([o].[Discount] AS float)) > 0.0E0 +"""); + } + + public override async Task Where_mathf_abs1(bool async) + { + await base.Where_mathf_abs1(async); + + AssertSql( + """ +SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock] +FROM [Products] AS [p] +WHERE ABS(CAST([p].[ProductID] AS real)) > CAST(10 AS real) +"""); + } + + public override async Task Where_mathf_ceiling1(bool async) + { + await base.Where_mathf_ceiling1(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[UnitPrice] < 7.0 AND CEILING([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_floor(bool async) + { + await base.Where_mathf_floor(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND FLOOR(CAST([o].[UnitPrice] AS real)) > CAST(10 AS real) +"""); + } + + public override async Task Where_mathf_power(bool async) + { + await base.Where_mathf_power(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE POWER([o].[Discount], CAST(3 AS real)) > CAST(0.005 AS real) +"""); + } + + public override async Task Where_mathf_square(bool async) + { + await base.Where_mathf_square(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE POWER([o].[Discount], CAST(2 AS real)) > CAST(0.05 AS real) +"""); + } + + public override async Task Where_mathf_round2(bool async) + { + await base.Where_mathf_round2(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE CAST(ROUND(CAST([o].[UnitPrice] AS real), 2) AS real) > CAST(100 AS real) +"""); + } + + public override async Task Select_mathf_round(bool async) + { + await base.Select_mathf_round(async); + + AssertSql( + """ +SELECT CAST(ROUND(CAST([o].[OrderID] AS real), 0) AS real) +FROM [Orders] AS [o] +WHERE [o].[OrderID] < 10250 +"""); + } + + public override async Task Select_mathf_round2(bool async) + { + await base.Select_mathf_round2(async); + + AssertSql( + """ +SELECT CAST(ROUND(CAST([o].[UnitPrice] AS real), 2) AS real) +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) +"""); + } + + public override async Task Where_mathf_truncate(bool async) + { + await base.Where_mathf_truncate(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) AND CAST(ROUND(CAST([o].[UnitPrice] AS real), 0, 1) AS real) > CAST(10 AS real) +"""); + } + + public override async Task Select_mathf_truncate(bool async) + { + await base.Select_mathf_truncate(async); + + AssertSql( + """ +SELECT CAST(ROUND(CAST([o].[UnitPrice] AS real), 0, 1) AS real) +FROM [Order Details] AS [o] +WHERE [o].[Quantity] < CAST(5 AS smallint) +"""); + } + + public override async Task Where_mathf_exp(bool async) + { + await base.Where_mathf_exp(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND EXP([o].[Discount]) > CAST(1 AS real) +"""); + } + + public override async Task Where_mathf_log10(bool async) + { + await base.Where_mathf_log10(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND [o].[Discount] > CAST(0 AS real) AND LOG10([o].[Discount]) < CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_log(bool async) + { + await base.Where_mathf_log(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND [o].[Discount] > CAST(0 AS real) AND LOG([o].[Discount]) < CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_log_new_base(bool async) + { + await base.Where_mathf_log_new_base(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND [o].[Discount] > CAST(0 AS real) AND LOG([o].[Discount], CAST(7 AS real)) < CAST(-1 AS real) +"""); + } + + public override async Task Where_mathf_sqrt(bool async) + { + await base.Where_mathf_sqrt(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND SQRT([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_acos(bool async) + { + await base.Where_mathf_acos(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ACOS([o].[Discount]) > CAST(1 AS real) +"""); + } + + public override async Task Where_mathf_asin(bool async) + { + await base.Where_mathf_asin(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ASIN([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_atan(bool async) + { + await base.Where_mathf_atan(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ATAN([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_atan2(bool async) + { + await base.Where_mathf_atan2(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND ATN2([o].[Discount], CAST(1 AS real)) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_cos(bool async) + { + await base.Where_mathf_cos(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND COS([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_sin(bool async) + { + await base.Where_mathf_sin(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND SIN([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_tan(bool async) + { + await base.Where_mathf_tan(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND TAN([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_sign(bool async) + { + await base.Where_mathf_sign(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND SIGN([o].[Discount]) > 0 +"""); + } + + public override async Task Where_mathf_degrees(bool async) + { + await base.Where_mathf_degrees(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND DEGREES([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_mathf_radians(bool async) + { + await base.Where_mathf_radians(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] +FROM [Order Details] AS [o] +WHERE [o].[OrderID] = 11077 AND RADIANS([o].[Discount]) > CAST(0 AS real) +"""); + } + + public override async Task Where_guid_newguid(bool async) + { + await base.Where_guid_newguid(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE NEWID() <> '00000000-0000-0000-0000-000000000000' +"""); + } + + public override async Task Where_string_to_upper(bool async) + { + await base.Where_string_to_upper(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE UPPER([c].[CustomerID]) = N'ALFKI' +"""); + } + + public override async Task Where_string_to_lower(bool async) + { + await base.Where_string_to_lower(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE LOWER([c].[CustomerID]) = N'alfki' +"""); + } + + public override async Task Where_functions_nested(bool async) + { + await base.Where_functions_nested(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE POWER(CAST(CAST(LEN([c].[CustomerID]) AS int) AS float), 2.0E0) = 25.0E0 +"""); + } + + public override async Task Convert_ToBoolean(bool async) + { + await base.Convert_ToBoolean(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(bit, [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(tinyint, [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(decimal(18, 2), [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(float, [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CAST(CONVERT(float, [o].[OrderID] % 3) AS real)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(smallint, [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(int, [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(bigint, [o].[OrderID] % 3)) = CAST(1 AS bit) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bit, CONVERT(int, [o].[OrderID] % 3)) = CAST(1 AS bit) +"""); + } + + public override async Task Convert_ToByte(bool async) + { + await base.Convert_ToByte(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(bit, [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(tinyint, [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(decimal(18, 2), [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(float, [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(smallint, [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(int, [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(bigint, [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(tinyint, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= CAST(0 AS tinyint) +"""); + } + + public override async Task Convert_ToDecimal(bool async) + { + await base.Convert_ToDecimal(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(bit, [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(tinyint, [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(decimal(18, 2), [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(float, [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(smallint, [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(int, [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(bigint, [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= 0.0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(decimal(18, 2), CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= 0.0 +"""); + } + + public override async Task Convert_ToDouble(bool async) + { + await base.Convert_ToDouble(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(bit, [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(tinyint, [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(decimal(18, 2), [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(float, [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(smallint, [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(int, [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(bigint, [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= 0.0E0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(float, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= 0.0E0 +"""); + } + + public override async Task Convert_ToInt16(bool async) + { + await base.Convert_ToInt16(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(bit, [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(tinyint, [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(decimal(18, 2), [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(float, [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(smallint, [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(int, [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(bigint, [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= CAST(0 AS smallint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(smallint, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= CAST(0 AS smallint) +"""); + } + + public override async Task Convert_ToInt32(bool async) + { + await base.Convert_ToInt32(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(bit, [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(tinyint, [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(decimal(18, 2), [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(float, [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(smallint, [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(int, [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(bigint, [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= 0 +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(int, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= 0 +"""); + } + + public override async Task Convert_ToInt64(bool async) + { + await base.Convert_ToInt64(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(bit, [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(tinyint, [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(decimal(18, 2), [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(float, [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(smallint, [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(int, [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(bigint, [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= CAST(0 AS bigint) +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(bigint, CONVERT(nvarchar(max), [o].[OrderID] % 1)) >= CAST(0 AS bigint) +"""); + } + + public override async Task Convert_ToString(bool async) + { + await base.Convert_ToString(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(bit, [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(tinyint, [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(decimal(18, 2), [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(float, [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CAST(CONVERT(float, [o].[OrderID] % 1) AS real)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(smallint, [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(int, [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(bigint, [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(nvarchar(max), [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND CONVERT(nvarchar(max), CONVERT(nvarchar(max), [o].[OrderID] % 1)) <> N'10' +""", + // + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[CustomerID] = N'ALFKI' AND (CONVERT(nvarchar(max), [o].[OrderDate]) LIKE N'%1997%' OR CONVERT(nvarchar(max), [o].[OrderDate]) LIKE N'%1998%') +"""); + } + + public override async Task Indexof_with_emptystring(bool async) + { + await base.Indexof_with_emptystring(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CASE + WHEN [c].[Region] IS NOT NULL THEN 0 +END = 0 +"""); + } + + public override async Task Indexof_with_one_constant_arg(bool async) + { + await base.Indexof_with_one_constant_arg(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CHARINDEX(N'a', [c].[ContactName]) - 1 = 1 +"""); + } + + public override async Task Indexof_with_one_parameter_arg(bool async) + { + await base.Indexof_with_one_parameter_arg(async); + + AssertSql( + """ +@__pattern_0='a' (Size = 30) + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CHARINDEX(@__pattern_0, [c].[ContactName]) - CASE + WHEN @__pattern_0 = N'' THEN 0 + ELSE 1 +END = 1 +"""); + } + + public override async Task Indexof_with_constant_starting_position(bool async) + { + await base.Indexof_with_constant_starting_position(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CHARINDEX(N'a', [c].[ContactName], 3) - 1 = 4 +"""); + } + + public override async Task Indexof_with_parameter_starting_position(bool async) + { + await base.Indexof_with_parameter_starting_position(async); + + AssertSql( + """ +@__start_0='2' + +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE CHARINDEX(N'a', [c].[ContactName], @__start_0 + 1) - 1 = 4 +"""); + } + + public override async Task Replace_with_emptystring(bool async) + { + await base.Replace_with_emptystring(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE REPLACE([c].[ContactName], N'ia', N'') = N'Mar Anders' +"""); + } + + public override async Task Replace_using_property_arguments(bool async) + { + await base.Replace_using_property_arguments(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE REPLACE([c].[ContactName], [c].[ContactName], [c].[CustomerID]) = [c].[CustomerID] +"""); + } + + public override async Task Substring_with_one_arg_with_zero_startindex(bool async) + { + await base.Substring_with_one_arg_with_zero_startindex(async); + + AssertSql( + """ +SELECT [c].[ContactName] +FROM [Customers] AS [c] +WHERE SUBSTRING([c].[CustomerID], 0 + 1, LEN([c].[CustomerID])) = N'ALFKI' +"""); + } + + public override async Task Substring_with_one_arg_with_constant(bool async) + { + await base.Substring_with_one_arg_with_constant(async); + + AssertSql( + """ +SELECT [c].[ContactName] +FROM [Customers] AS [c] +WHERE SUBSTRING([c].[CustomerID], 1 + 1, LEN([c].[CustomerID])) = N'LFKI' +"""); + } + + public override async Task Substring_with_one_arg_with_closure(bool async) + { + await base.Substring_with_one_arg_with_closure(async); + + AssertSql( + """ +@__start_0='2' + +SELECT [c].[ContactName] +FROM [Customers] AS [c] +WHERE SUBSTRING([c].[CustomerID], @__start_0 + 1, LEN([c].[CustomerID])) = N'FKI' +"""); + } + + public override async Task Substring_with_two_args_with_zero_startindex(bool async) + { + await base.Substring_with_two_args_with_zero_startindex(async); + + AssertSql( + """ +SELECT SUBSTRING([c].[ContactName], 0 + 1, 3) +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI' +"""); + } + + public override async Task Substring_with_two_args_with_zero_length(bool async) + { + await base.Substring_with_two_args_with_zero_length(async); + + AssertSql( + """ +SELECT SUBSTRING([c].[ContactName], 2 + 1, 0) +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI' +"""); + } + + public override async Task Substring_with_two_args_with_constant(bool async) + { + await base.Substring_with_two_args_with_constant(async); + + AssertSql( + """ +SELECT SUBSTRING([c].[ContactName], 1 + 1, 3) +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI' +"""); + } + + public override async Task Substring_with_two_args_with_closure(bool async) + { + await base.Substring_with_two_args_with_closure(async); + + AssertSql( + """ +@__start_0='2' + +SELECT SUBSTRING([c].[ContactName], @__start_0 + 1, 3) +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI' +"""); + } + + public override async Task Substring_with_two_args_with_Index_of(bool async) + { + await base.Substring_with_two_args_with_Index_of(async); + + AssertSql( + """ +SELECT SUBSTRING([c].[ContactName], (CHARINDEX(N'a', [c].[ContactName]) - 1) + 1, 3) +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI' +"""); + } + + public override async Task IsNullOrEmpty_in_predicate(bool async) + { + await base.IsNullOrEmpty_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[Region] IS NULL OR [c].[Region] LIKE N'' +"""); + } + + public override async Task IsNullOrEmpty_in_projection(bool async) + { + await base.IsNullOrEmpty_in_projection(async); + + AssertSql( + """ +SELECT [c].[CustomerID] AS [Id], CASE + WHEN [c].[Region] IS NULL OR [c].[Region] LIKE N'' THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Value] +FROM [Customers] AS [c] +"""); + } + + public override async Task IsNullOrEmpty_negated_in_predicate(bool async) + { + await base.IsNullOrEmpty_negated_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[Region] IS NOT NULL AND [c].[Region] NOT LIKE N'' +"""); + } + + public override async Task IsNullOrEmpty_negated_in_projection(bool async) + { + await base.IsNullOrEmpty_negated_in_projection(async); + + AssertSql( + """ +SELECT [c].[CustomerID] AS [Id], CASE + WHEN [c].[Region] IS NOT NULL AND [c].[Region] NOT LIKE N'' THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Value] +FROM [Customers] AS [c] +"""); + } + + public override async Task IsNullOrWhiteSpace_in_predicate(bool async) + { + await base.IsNullOrWhiteSpace_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[Region] IS NULL OR [c].[Region] = N'' +"""); + } + + public override async Task IsNullOrWhiteSpace_in_predicate_on_non_nullable_column(bool async) + { + await base.IsNullOrWhiteSpace_in_predicate_on_non_nullable_column(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'' +"""); + } + + public override async Task TrimStart_without_arguments_in_predicate(bool async) + { + await base.TrimStart_without_arguments_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE LTRIM([c].[ContactTitle]) = N'Owner' +"""); + } + + public override async Task TrimStart_with_char_argument_in_predicate(bool async) + { + await base.TrimStart_with_char_argument_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE LTRIM([c].[ContactTitle], N'O') = N'wner' +"""); + } + + public override async Task TrimStart_with_char_array_argument_in_predicate(bool async) + { + await base.TrimStart_with_char_array_argument_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE LTRIM([c].[ContactTitle], N'Ow') = N'ner' +"""); + } + + public override async Task TrimEnd_without_arguments_in_predicate(bool async) + { + await base.TrimEnd_without_arguments_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE RTRIM([c].[ContactTitle]) = N'Owner' +"""); + } + + public override async Task TrimEnd_with_char_argument_in_predicate(bool async) + { + await base.TrimEnd_with_char_argument_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE RTRIM([c].[ContactTitle], N'r') = N'Owne' +"""); + } + + public override async Task TrimEnd_with_char_array_argument_in_predicate(bool async) + { + await base.TrimEnd_with_char_array_argument_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE RTRIM([c].[ContactTitle], N'er') = N'Own' +"""); + } + + public override async Task Trim_without_argument_in_predicate(bool async) + { + await base.Trim_without_argument_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE LTRIM(RTRIM([c].[ContactTitle])) = N'Owner' +"""); + } + + public override async Task Trim_with_char_argument_in_predicate(bool async) + { + // String.Trim with parameters. Issue #22927. + await AssertTranslationFailed(() => base.Trim_with_char_argument_in_predicate(async)); + + AssertSql(); + } + + public override async Task Trim_with_char_array_argument_in_predicate(bool async) + { + // String.Trim with parameters. Issue #22927. + await AssertTranslationFailed(() => base.Trim_with_char_array_argument_in_predicate(async)); + + AssertSql(); + } + + public override async Task Order_by_length_twice(bool async) + { + await base.Order_by_length_twice(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +ORDER BY CAST(LEN([c].[CustomerID]) AS int), [c].[CustomerID] +"""); + } + + public override async Task Order_by_length_twice_followed_by_projection_of_naked_collection_navigation(bool async) + { + await base.Order_by_length_twice_followed_by_projection_of_naked_collection_navigation(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Customers] AS [c] +LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +ORDER BY CAST(LEN([c].[CustomerID]) AS int), [c].[CustomerID] +"""); + } + + public override async Task Static_string_equals_in_predicate(bool async) + { + await base.Static_string_equals_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ANATR' +"""); + } + + public override async Task Static_equals_nullable_datetime_compared_to_non_nullable(bool async) + { + await base.Static_equals_nullable_datetime_compared_to_non_nullable(async); + + AssertSql( + """ +@__arg_0='1996-07-04T00:00:00.0000000' (DbType = DateTime) + +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] = @__arg_0 +"""); + } + + public override async Task Static_equals_int_compared_to_long(bool async) + { + await base.Static_equals_int_compared_to_long(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE 0 = 1 +"""); + } + + public override async Task Where_DateOnly_FromDateTime(bool async) + { + await base.Where_DateOnly_FromDateTime(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE [o].[OrderDate] IS NOT NULL AND CAST([o].[OrderDate] AS date) = '1996-09-16' +"""); + } + + public override async Task Projecting_Math_Truncate_and_ordering_by_it_twice(bool async) + => await base.Projecting_Math_Truncate_and_ordering_by_it_twice(async); + + // issue #16038 + // AssertSql( + // @"SELECT ROUND(CAST([o].[OrderID] AS float), 0, 1) AS [A] + //FROM [Orders] AS [o] + //WHERE [o].[OrderID] < 10250 + //ORDER BY [A]"); + public override async Task Projecting_Math_Truncate_and_ordering_by_it_twice2(bool async) + => await base.Projecting_Math_Truncate_and_ordering_by_it_twice2(async); + + // issue #16038 + // AssertSql( + // @"SELECT ROUND(CAST([o].[OrderID] AS float), 0, 1) AS [A] + //FROM [Orders] AS [o] + //WHERE [o].[OrderID] < 10250 + //ORDER BY [A] DESC"); + public override async Task Projecting_Math_Truncate_and_ordering_by_it_twice3(bool async) + => await base.Projecting_Math_Truncate_and_ordering_by_it_twice3(async); + + // issue #16038 + // AssertSql( + // @"SELECT ROUND(CAST([o].[OrderID] AS float), 0, 1) AS [A] + //FROM [Orders] AS [o] + //WHERE [o].[OrderID] < 10250 + //ORDER BY [A] DESC"); + public override Task Regex_IsMatch_MethodCall(bool async) + => AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall(async)); + + public override Task Regex_IsMatch_MethodCall_constant_input(bool async) + => AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall_constant_input(async)); + + public override Task Datetime_subtraction_TotalDays(bool async) + => AssertTranslationFailed(() => base.Datetime_subtraction_TotalDays(async)); + + public override async Task Select_ToString_IndexOf(bool async) + { + await base.Select_ToString_IndexOf(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE CHARINDEX('123', CONVERT(varchar(11), [o].[OrderID])) - 1 = -1 +"""); + } + + public override async Task Select_IndexOf_ToString(bool async) + { + await base.Select_IndexOf_ToString(async); + + AssertSql( + """ +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +FROM [Orders] AS [o] +WHERE CHARINDEX(CONVERT(varchar(11), [o].[OrderID]), '123') - CASE + WHEN CONVERT(varchar(11), [o].[OrderID]) = '' THEN 0 + ELSE 1 +END = -1 +"""); + } + + public override async Task String_Contains_in_projection(bool async) + { + await base.String_Contains_in_projection(async); + + AssertSql( + """ +SELECT [c].[CustomerID] AS [Id], CASE + WHEN [c].[ContactName] IS NOT NULL AND (CHARINDEX([c].[ContactName], [c].[CompanyName]) > 0 OR [c].[ContactName] LIKE N'') THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Value] +FROM [Customers] AS [c] +"""); + } + + public override async Task String_Contains_negated_in_predicate(bool async) + { + await base.String_Contains_negated_in_predicate(async); + + AssertSql( + """ +SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[ContactName] IS NULL OR (CHARINDEX([c].[ContactName], [c].[CompanyName]) <= 0 AND [c].[ContactName] NOT LIKE N'') +"""); + } + + public override async Task String_Contains_negated_in_projection(bool async) + { + await base.String_Contains_negated_in_projection(async); + + AssertSql( + """ +SELECT [c].[CustomerID] AS [Id], CASE + WHEN [c].[ContactName] IS NULL OR (CHARINDEX([c].[ContactName], [c].[CompanyName]) <= 0 AND [c].[ContactName] NOT LIKE N'') THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [Value] +FROM [Customers] AS [c] +"""); + } + + public override async Task String_Contains_with_StringComparison_Ordinal(bool async) + { + await base.String_Contains_with_StringComparison_Ordinal(async); + + AssertSql(); + } + + public override async Task String_Contains_with_StringComparison_OrdinalIgnoreCase(bool async) + { + await base.String_Contains_with_StringComparison_OrdinalIgnoreCase(async); + + AssertSql(); + } + + public override async Task String_Contains_with_StringComparison_unsupported(bool async) + { + await base.String_Contains_with_StringComparison_unsupported(async); + + AssertSql(); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task StandardDeviation(bool async) + { + await using var ctx = CreateContext(); + + var query = ctx.Set() + .GroupBy(od => od.ProductID) + .Select( + g => new + { + ProductID = g.Key, + SampleStandardDeviation = EF.Functions.StandardDeviationSample(g.Select(od => od.UnitPrice)), + PopulationStandardDeviation = EF.Functions.StandardDeviationPopulation(g.Select(od => od.UnitPrice)) + }); + + var results = async + ? await query.ToListAsync() + : query.ToList(); + + var product9 = results.Single(r => r.ProductID == 9); + Assert.Equal(8.675943752699023, product9.SampleStandardDeviation.Value, 5); + Assert.Equal(7.759999999999856, product9.PopulationStandardDeviation.Value, 5); + + AssertSql( + """ +SELECT [o].[ProductID], STDEV([o].[UnitPrice]) AS [SampleStandardDeviation], STDEVP([o].[UnitPrice]) AS [PopulationStandardDeviation] +FROM [Order Details] AS [o] +GROUP BY [o].[ProductID] +"""); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Variance(bool async) + { + await using var ctx = CreateContext(); + + var query = ctx.Set() + .GroupBy(od => od.ProductID) + .Select( + g => new + { + ProductID = g.Key, + SampleStandardDeviation = EF.Functions.VarianceSample(g.Select(od => od.UnitPrice)), + PopulationStandardDeviation = EF.Functions.VariancePopulation(g.Select(od => od.UnitPrice)) + }); + + var results = async + ? await query.ToListAsync() + : query.ToList(); + + var product9 = results.Single(r => r.ProductID == 9); + Assert.Equal(75.2719999999972, product9.SampleStandardDeviation.Value, 5); + Assert.Equal(60.217599999997766, product9.PopulationStandardDeviation.Value, 5); + + AssertSql( + """ +SELECT [o].[ProductID], VAR([o].[UnitPrice]) AS [SampleStandardDeviation], VARP([o].[UnitPrice]) AS [PopulationStandardDeviation] +FROM [Order Details] AS [o] +GROUP BY [o].[ProductID] +"""); + } + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + + protected override void ClearLog() + => Fixture.TestSqlLoggerFactory.Clear(); + + public class Fixture160 : NorthwindQuerySqlServerFixture + { + public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) + => base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160)); + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs index beb327c5ac4..12e35480552 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs @@ -1397,83 +1397,23 @@ FROM [Order Details] AS [o] """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Where_math_min(bool async) - { - await base.Where_math_min(async); - - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE [o].[OrderID] = 11077 AND LEAST([o].[OrderID], [o].[ProductID]) = [o].[ProductID] -"""); - } - - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Where_math_min_nested(bool async) - { - await base.Where_math_min_nested(async); + public override Task Where_math_min(bool async) + => AssertTranslationFailed(() => base.Where_math_min(async)); - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE [o].[OrderID] = 11077 AND LEAST([o].[OrderID], [o].[ProductID], 99999) = [o].[ProductID] -"""); - } + public override Task Where_math_min_nested(bool async) + => AssertTranslationFailed(() => base.Where_math_min_nested(async)); - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Where_math_min_nested_twice(bool async) - { - await base.Where_math_min_nested_twice(async); + public override Task Where_math_min_nested_twice(bool async) + => AssertTranslationFailed(() => base.Where_math_min_nested_twice(async)); - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE [o].[OrderID] = 11077 AND LEAST(99999, [o].[OrderID], 99998, [o].[ProductID]) = [o].[ProductID] -"""); - } - - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Where_math_max(bool async) - { - await base.Where_math_max(async); - - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE [o].[OrderID] = 11077 AND GREATEST([o].[OrderID], [o].[ProductID]) = [o].[OrderID] -"""); - } - - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Where_math_max_nested(bool async) - { - await base.Where_math_max_nested(async); - - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE [o].[OrderID] = 11077 AND GREATEST([o].[OrderID], [o].[ProductID], 1) = [o].[OrderID] -"""); - } + public override Task Where_math_max(bool async) + => AssertTranslationFailed(() => base.Where_math_max(async)); - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task Where_math_max_nested_twice(bool async) - { - await base.Where_math_max_nested_twice(async); + public override Task Where_math_max_nested(bool async) + => AssertTranslationFailed(() => base.Where_math_max_nested(async)); - AssertSql( - """ -SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE [o].[OrderID] = 11077 AND GREATEST(1, [o].[OrderID], 2, [o].[ProductID]) = [o].[OrderID] -"""); - } + public override Task Where_math_max_nested_twice(bool async) + => AssertTranslationFailed(() => base.Where_math_max_nested_twice(async)); public override async Task Where_math_degrees(bool async) { @@ -2656,31 +2596,11 @@ WHERE LTRIM([c].[ContactTitle]) = N'Owner' """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task TrimStart_with_char_argument_in_predicate(bool async) - { - await base.TrimStart_with_char_argument_in_predicate(async); - - AssertSql( - """ -SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] -FROM [Customers] AS [c] -WHERE LTRIM([c].[ContactTitle], N'O') = N'wner' -"""); - } + public override Task TrimStart_with_char_argument_in_predicate(bool async) + => AssertTranslationFailed(() => base.TrimStart_with_char_argument_in_predicate(async)); - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task TrimStart_with_char_array_argument_in_predicate(bool async) - { - await base.TrimStart_with_char_array_argument_in_predicate(async); - - AssertSql( - """ -SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] -FROM [Customers] AS [c] -WHERE LTRIM([c].[ContactTitle], N'Ow') = N'ner' -"""); - } + public override Task TrimStart_with_char_array_argument_in_predicate(bool async) + => AssertTranslationFailed(() => base.TrimStart_with_char_array_argument_in_predicate(async)); public override async Task TrimEnd_without_arguments_in_predicate(bool async) { @@ -2694,31 +2614,11 @@ WHERE RTRIM([c].[ContactTitle]) = N'Owner' """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task TrimEnd_with_char_argument_in_predicate(bool async) - { - await base.TrimEnd_with_char_argument_in_predicate(async); + public override Task TrimEnd_with_char_argument_in_predicate(bool async) + => AssertTranslationFailed(() => base.TrimEnd_with_char_argument_in_predicate(async)); - AssertSql( - """ -SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] -FROM [Customers] AS [c] -WHERE RTRIM([c].[ContactTitle], N'r') = N'Owne' -"""); - } - - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] - public override async Task TrimEnd_with_char_array_argument_in_predicate(bool async) - { - await base.TrimEnd_with_char_array_argument_in_predicate(async); - - AssertSql( - """ -SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] -FROM [Customers] AS [c] -WHERE RTRIM([c].[ContactTitle], N'er') = N'Own' -"""); - } + public override Task TrimEnd_with_char_array_argument_in_predicate(bool async) + => AssertTranslationFailed(() => base.TrimEnd_with_char_array_argument_in_predicate(async)); public override async Task Trim_without_argument_in_predicate(bool async) { diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs new file mode 100644 index 00000000000..09878bccedd --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs @@ -0,0 +1,2004 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.Query; + +[SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] +public class PrimitiveCollectionsQuerySqlServer160Test : PrimitiveCollectionsQueryRelationalTestBase< + PrimitiveCollectionsQuerySqlServer160Test.PrimitiveCollectionsQuerySqlServerFixture> +{ + public PrimitiveCollectionsQuerySqlServer160Test(PrimitiveCollectionsQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper) + : base(fixture) + { + Fixture.TestSqlLoggerFactory.Clear(); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + } + + public override async Task Inline_collection_of_ints_Contains(bool async) + { + await base.Inline_collection_of_ints_Contains(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN (10, 999) +"""); + } + + public override async Task Inline_collection_of_nullable_ints_Contains(bool async) + { + await base.Inline_collection_of_nullable_ints_Contains(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableInt] IN (10, 999) +"""); + } + + public override async Task Inline_collection_of_nullable_ints_Contains_null(bool async) + { + await base.Inline_collection_of_nullable_ints_Contains_null(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableInt] IS NULL OR [p].[NullableInt] = 999 +"""); + } + + public override async Task Inline_collection_Count_with_zero_values(bool async) + { + await base.Inline_collection_Count_with_zero_values(async); + + AssertSql(); + } + + public override async Task Inline_collection_Count_with_one_value(bool async) + { + await base.Inline_collection_Count_with_one_value(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM (VALUES (CAST(2 AS int))) AS [v]([Value]) + WHERE [v].[Value] > [p].[Id]) = 1 +"""); + } + + public override async Task Inline_collection_Count_with_two_values(bool async) + { + await base.Inline_collection_Count_with_two_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM (VALUES (CAST(2 AS int)), (999)) AS [v]([Value]) + WHERE [v].[Value] > [p].[Id]) = 1 +"""); + } + + public override async Task Inline_collection_Count_with_three_values(bool async) + { + await base.Inline_collection_Count_with_three_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM (VALUES (CAST(2 AS int)), (999), (1000)) AS [v]([Value]) + WHERE [v].[Value] > [p].[Id]) = 2 +"""); + } + + public override async Task Inline_collection_Contains_with_zero_values(bool async) + { + await base.Inline_collection_Contains_with_zero_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 0 = 1 +"""); + } + + public override async Task Inline_collection_Contains_with_one_value(bool async) + { + await base.Inline_collection_Contains_with_one_value(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] = 2 +"""); + } + + public override async Task Inline_collection_Contains_with_two_values(bool async) + { + await base.Inline_collection_Contains_with_two_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] IN (2, 999) +"""); + } + + public override async Task Inline_collection_Contains_with_three_values(bool async) + { + await base.Inline_collection_Contains_with_three_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] IN (2, 999, 1000) +"""); + } + + public override async Task Inline_collection_Contains_with_EF_Constant(bool async) + { + await base.Inline_collection_Contains_with_EF_Constant(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] IN (2, 999, 1000) +"""); + } + + public override async Task Inline_collection_Contains_with_all_parameters(bool async) + { + await base.Inline_collection_Contains_with_all_parameters(async); + + AssertSql( + """ +@__i_0='2' +@__j_1='999' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] IN (@__i_0, @__j_1) +"""); + } + + public override async Task Inline_collection_Contains_with_constant_and_parameter(bool async) + { + await base.Inline_collection_Contains_with_constant_and_parameter(async); + + AssertSql( + """ +@__j_0='999' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] IN (2, @__j_0) +"""); + } + + public override async Task Inline_collection_Contains_with_mixed_value_types(bool async) + { + await base.Inline_collection_Contains_with_mixed_value_types(async); + + AssertSql( + """ +@__i_0='11' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN (999, @__i_0, [p].[Id], [p].[Id] + [p].[Int]) +"""); + } + + public override async Task Inline_collection_List_Contains_with_mixed_value_types(bool async) + { + await base.Inline_collection_List_Contains_with_mixed_value_types(async); + + AssertSql( + """ +@__i_0='11' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN (999, @__i_0, [p].[Id], [p].[Id] + [p].[Int]) +"""); + } + + public override async Task Inline_collection_Contains_as_Any_with_predicate(bool async) + { + await base.Inline_collection_Contains_as_Any_with_predicate(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] IN (2, 999) +"""); + } + + public override async Task Inline_collection_negated_Contains_as_All(bool async) + { + await base.Inline_collection_negated_Contains_as_All(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] NOT IN (2, 999) +"""); + } + + public override async Task Inline_collection_Min_with_two_values(bool async) + { + await base.Inline_collection_Min_with_two_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE LEAST(30, [p].[Int]) = 30 +"""); + } + + public override async Task Inline_collection_List_Min_with_two_values(bool async) + { + await base.Inline_collection_List_Min_with_two_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE LEAST(30, [p].[Int]) = 30 +"""); + } + + public override async Task Inline_collection_Max_with_two_values(bool async) + { + await base.Inline_collection_Max_with_two_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE GREATEST(30, [p].[Int]) = 30 +"""); + } + + public override async Task Inline_collection_List_Max_with_two_values(bool async) + { + await base.Inline_collection_List_Max_with_two_values(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE GREATEST(30, [p].[Int]) = 30 +"""); + } + + public override async Task Inline_collection_Min_with_three_values(bool async) + { + await base.Inline_collection_Min_with_three_values(async); + + AssertSql( + """ +@__i_0='25' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE LEAST(30, [p].[Int], @__i_0) = 25 +"""); + } + + public override async Task Inline_collection_List_Min_with_three_values(bool async) + { + await base.Inline_collection_List_Min_with_three_values(async); + + AssertSql( + """ +@__i_0='25' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE LEAST(30, [p].[Int], @__i_0) = 25 +"""); + } + + public override async Task Inline_collection_Max_with_three_values(bool async) + { + await base.Inline_collection_Max_with_three_values(async); + + AssertSql( + """ +@__i_0='35' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE GREATEST(30, [p].[Int], @__i_0) = 35 +"""); + } + + public override async Task Inline_collection_List_Max_with_three_values(bool async) + { + await base.Inline_collection_List_Max_with_three_values(async); + + AssertSql( + """ +@__i_0='35' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE GREATEST(30, [p].[Int], @__i_0) = 35 +"""); + } + + public override async Task Inline_collection_of_nullable_value_type_Min(bool async) + { + await base.Inline_collection_of_nullable_value_type_Min(async); + + AssertSql( + """ +@__i_0='25' (Nullable = true) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE LEAST(30, [p].[Int], @__i_0) = 25 +"""); + } + + public override async Task Inline_collection_of_nullable_value_type_Max(bool async) + { + await base.Inline_collection_of_nullable_value_type_Max(async); + + AssertSql( + """ +@__i_0='35' (Nullable = true) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE GREATEST(30, [p].[Int], @__i_0) = 35 +"""); + } + + public override async Task Inline_collection_of_nullable_value_type_with_null_Min(bool async) + { + await base.Inline_collection_of_nullable_value_type_with_null_Min(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE LEAST(30, [p].[NullableInt], NULL) = 30 +"""); + } + + public override async Task Inline_collection_of_nullable_value_type_with_null_Max(bool async) + { + await base.Inline_collection_of_nullable_value_type_with_null_Max(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE GREATEST(30, [p].[NullableInt], NULL) = 30 +"""); + } + + public override async Task Parameter_collection_Count(bool async) + { + await base.Parameter_collection_Count(async); + + AssertSql( + """ +@__ids_0='[2,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON(@__ids_0) WITH ([value] int '$') AS [i] + WHERE [i].[value] > [p].[Id]) = 1 +"""); + } + + public override async Task Parameter_collection_of_ints_Contains_int(bool async) + { + await base.Parameter_collection_of_ints_Contains_int(async); + + AssertSql( + """ +@__ints_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] +) +""", + // + """ +@__ints_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] NOT IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] +) +"""); + } + + public override async Task Parameter_collection_HashSet_of_ints_Contains_int(bool async) + { + await base.Parameter_collection_HashSet_of_ints_Contains_int(async); + + AssertSql( + """ +@__ints_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] +) +""", + // + """ +@__ints_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] NOT IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] +) +"""); + } + + public override async Task Parameter_collection_of_ints_Contains_nullable_int(bool async) + { + await base.Parameter_collection_of_ints_Contains_nullable_int(async); + + AssertSql( + """ +@__ints_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableInt] IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] +) +""", + // + """ +@__ints_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableInt] NOT IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] +) OR [p].[NullableInt] IS NULL +"""); + } + + public override async Task Parameter_collection_of_nullable_ints_Contains_int(bool async) + { + await base.Parameter_collection_of_nullable_ints_Contains_int(async); + + AssertSql( + """ +@__nullableInts_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN ( + SELECT [n].[value] + FROM OPENJSON(@__nullableInts_0) WITH ([value] int '$') AS [n] +) +""", + // + """ +@__nullableInts_0='[10,999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] NOT IN ( + SELECT [n].[value] + FROM OPENJSON(@__nullableInts_0) WITH ([value] int '$') AS [n] +) +"""); + } + + public override async Task Parameter_collection_of_nullable_ints_Contains_nullable_int(bool async) + { + await base.Parameter_collection_of_nullable_ints_Contains_nullable_int(async); + + AssertSql( + """ +@__nullableInts_0_without_nulls='[999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableInt] IN ( + SELECT [n].[value] + FROM OPENJSON(@__nullableInts_0_without_nulls) AS [n] +) OR [p].[NullableInt] IS NULL +""", + // + """ +@__nullableInts_0_without_nulls='[999]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableInt] NOT IN ( + SELECT [n].[value] + FROM OPENJSON(@__nullableInts_0_without_nulls) AS [n] +) AND [p].[NullableInt] IS NOT NULL +"""); + } + + public override async Task Parameter_collection_of_strings_Contains_string(bool async) + { + await base.Parameter_collection_of_strings_Contains_string(async); + + AssertSql( + """ +@__strings_0='["10","999"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[String] IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0) WITH ([value] nvarchar(max) '$') AS [s] +) +""", + // + """ +@__strings_0='["10","999"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[String] NOT IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0) WITH ([value] nvarchar(max) '$') AS [s] +) +"""); + } + + public override async Task Parameter_collection_of_strings_Contains_nullable_string(bool async) + { + await base.Parameter_collection_of_strings_Contains_nullable_string(async); + + AssertSql( + """ +@__strings_0='["10","999"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableString] IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0) WITH ([value] nvarchar(max) '$') AS [s] +) +""", + // + """ +@__strings_0='["10","999"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableString] NOT IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0) WITH ([value] nvarchar(max) '$') AS [s] +) OR [p].[NullableString] IS NULL +"""); + } + + public override async Task Parameter_collection_of_nullable_strings_Contains_string(bool async) + { + await base.Parameter_collection_of_nullable_strings_Contains_string(async); + + AssertSql( + """ +@__strings_0='["10",null]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[String] IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0) WITH ([value] nvarchar(max) '$') AS [s] +) +""", + // + """ +@__strings_0_without_nulls='["10"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[String] NOT IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0_without_nulls) AS [s] +) +"""); + } + + public override async Task Parameter_collection_of_nullable_strings_Contains_nullable_string(bool async) + { + await base.Parameter_collection_of_nullable_strings_Contains_nullable_string(async); + + AssertSql( + """ +@__strings_0_without_nulls='["999"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableString] IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0_without_nulls) AS [s] +) OR [p].[NullableString] IS NULL +""", + // + """ +@__strings_0_without_nulls='["999"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[NullableString] NOT IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_0_without_nulls) AS [s] +) AND [p].[NullableString] IS NOT NULL +"""); + } + + public override async Task Parameter_collection_of_DateTimes_Contains(bool async) + { + await base.Parameter_collection_of_DateTimes_Contains(async); + + AssertSql( + """ +@__dateTimes_0='["2020-01-10T12:30:00Z","9999-01-01T00:00:00Z"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[DateTime] IN ( + SELECT [d].[value] + FROM OPENJSON(@__dateTimes_0) WITH ([value] datetime '$') AS [d] +) +"""); + } + + public override async Task Parameter_collection_of_bools_Contains(bool async) + { + await base.Parameter_collection_of_bools_Contains(async); + + AssertSql( + """ +@__bools_0='[true]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Bool] IN ( + SELECT [b].[value] + FROM OPENJSON(@__bools_0) WITH ([value] bit '$') AS [b] +) +"""); + } + + public override async Task Parameter_collection_of_enums_Contains(bool async) + { + await base.Parameter_collection_of_enums_Contains(async); + + AssertSql( + """ +@__enums_0='[0,3]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Enum] IN ( + SELECT [e].[value] + FROM OPENJSON(@__enums_0) WITH ([value] int '$') AS [e] +) +"""); + } + + public override async Task Parameter_collection_null_Contains(bool async) + { + await base.Parameter_collection_null_Contains(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN ( + SELECT [i].[value] + FROM OPENJSON(NULL) AS [i] +) +"""); + } + + public override async Task Column_collection_of_ints_Contains(bool async) + { + await base.Column_collection_of_ints_Contains(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 10 IN ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] +) +"""); + } + + public override async Task Column_collection_of_nullable_ints_Contains(bool async) + { + await base.Column_collection_of_nullable_ints_Contains(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 10 IN ( + SELECT [n].[value] + FROM OPENJSON([p].[NullableInts]) WITH ([value] int '$') AS [n] +) +"""); + } + + public override async Task Column_collection_of_nullable_ints_Contains_null(bool async) + { + await base.Column_collection_of_nullable_ints_Contains_null(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE EXISTS ( + SELECT 1 + FROM OPENJSON([p].[NullableInts]) WITH ([value] int '$') AS [n] + WHERE [n].[value] IS NULL) +"""); + } + + public override async Task Column_collection_of_strings_contains_null(bool async) + { + await base.Column_collection_of_strings_contains_null(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 0 = 1 +"""); + } + + public override async Task Column_collection_of_nullable_strings_contains_null(bool async) + { + await base.Column_collection_of_nullable_strings_contains_null(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE EXISTS ( + SELECT 1 + FROM OPENJSON([p].[NullableStrings]) WITH ([value] nvarchar(max) '$') AS [n] + WHERE [n].[value] IS NULL) +"""); + } + + public override async Task Column_collection_of_bools_Contains(bool async) + { + await base.Column_collection_of_bools_Contains(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(1 AS bit) IN ( + SELECT [b].[value] + FROM OPENJSON([p].[Bools]) WITH ([value] bit '$') AS [b] +) +"""); + } + + [ConditionalFact] + public virtual async Task Json_representation_of_bool_array() + { + await using var context = CreateContext(); + + Assert.Equal( + "[true,false]", + await context.Database.SqlQuery($"SELECT [Bools] AS [Value] FROM [PrimitiveCollectionsEntity] WHERE [Id] = 1") + .SingleAsync()); + } + + public override async Task Column_collection_Count_method(bool async) + { + await base.Column_collection_Count_method(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([p].[Ints]) AS [i]) = 2 +"""); + } + + public override async Task Column_collection_Length(bool async) + { + await base.Column_collection_Length(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([p].[Ints]) AS [i]) = 2 +"""); + } + + public override async Task Column_collection_Count_with_predicate(bool async) + { + await base.Column_collection_Count_with_predicate(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + WHERE [i].[value] > 1) = 2 +"""); + } + + public override async Task Column_collection_Where_Count(bool async) + { + await base.Column_collection_Where_Count(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + WHERE [i].[value] > 1) = 2 +"""); + } + + public override async Task Column_collection_index_int(bool async) + { + await base.Column_collection_index_int(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(JSON_VALUE([p].[Ints], '$[1]') AS int) = 10 +"""); + } + + public override async Task Column_collection_index_string(bool async) + { + await base.Column_collection_index_string(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE JSON_VALUE([p].[Strings], '$[1]') = N'10' +"""); + } + + public override async Task Column_collection_index_datetime(bool async) + { + await base.Column_collection_index_datetime(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(JSON_VALUE([p].[DateTimes], '$[1]') AS datetime2) = '2020-01-10T12:30:00.0000000Z' +"""); + } + + public override async Task Column_collection_index_beyond_end(bool async) + { + await base.Column_collection_index_beyond_end(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(JSON_VALUE([p].[Ints], '$[999]') AS int) = 10 +"""); + } + + public override async Task Nullable_reference_column_collection_index_equals_nullable_column(bool async) + { + // TODO: This test is incorrect, see #33784 + await base.Nullable_reference_column_collection_index_equals_nullable_column(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE JSON_VALUE([p].[NullableStrings], '$[2]') = [p].[NullableString] OR (JSON_VALUE([p].[NullableStrings], '$[2]') IS NULL AND [p].[NullableString] IS NULL) +"""); + } + + public override async Task Non_nullable_reference_column_collection_index_equals_nullable_column(bool async) + { + await base.Non_nullable_reference_column_collection_index_equals_nullable_column(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE EXISTS ( + SELECT 1 + FROM OPENJSON([p].[Strings]) AS [s]) AND JSON_VALUE([p].[Strings], '$[1]') = [p].[NullableString] +"""); + } + + public override async Task Inline_collection_index_Column(bool async) + { + await base.Inline_collection_index_Column(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT [v].[Value] + FROM (VALUES (0, CAST(1 AS int)), (1, 2), (2, 3)) AS [v]([_ord], [Value]) + ORDER BY [v].[_ord] + OFFSET [p].[Int] ROWS FETCH NEXT 1 ROWS ONLY) = 1 +"""); + } + + public override async Task Inline_collection_value_index_Column(bool async) + { + await base.Inline_collection_value_index_Column(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT [v].[Value] + FROM (VALUES (0, CAST(1 AS int)), (1, [p].[Int]), (2, 3)) AS [v]([_ord], [Value]) + ORDER BY [v].[_ord] + OFFSET [p].[Int] ROWS FETCH NEXT 1 ROWS ONLY) = 1 +"""); + } + + public override async Task Inline_collection_List_value_index_Column(bool async) + { + await base.Inline_collection_List_value_index_Column(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT [v].[Value] + FROM (VALUES (0, CAST(1 AS int)), (1, [p].[Int]), (2, 3)) AS [v]([_ord], [Value]) + ORDER BY [v].[_ord] + OFFSET [p].[Int] ROWS FETCH NEXT 1 ROWS ONLY) = 1 +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsJsonPathExpressions)] + public override async Task Parameter_collection_index_Column_equal_Column(bool async) + { + await base.Parameter_collection_index_Column_equal_Column(async); + + AssertSql( + """ +@__ints_0='[0,2,3]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(JSON_VALUE(@__ints_0, '$[' + CAST([p].[Int] AS nvarchar(max)) + ']') AS int) = [p].[Int] +"""); + } + + [SqlServerCondition(SqlServerCondition.SupportsJsonPathExpressions)] + public override async Task Parameter_collection_index_Column_equal_constant(bool async) + { + await base.Parameter_collection_index_Column_equal_constant(async); + + AssertSql( + """ +@__ints_0='[1,2,3]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(JSON_VALUE(@__ints_0, '$[' + CAST([p].[Int] AS nvarchar(max)) + ']') AS int) = 1 +"""); + } + + public override async Task Column_collection_ElementAt(bool async) + { + await base.Column_collection_ElementAt(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CAST(JSON_VALUE([p].[Ints], '$[1]') AS int) = 10 +"""); + } + + public override async Task Column_collection_First(bool async) + { + await base.Column_collection_First(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT TOP(1) CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int)) = 1 +"""); + } + + public override async Task Column_collection_FirstOrDefault(bool async) + { + await base.Column_collection_FirstOrDefault(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE COALESCE(( + SELECT TOP(1) CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int)), 0) = 1 +"""); + } + + public override async Task Column_collection_Single(bool async) + { + await base.Column_collection_Single(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT TOP(1) CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int)) = 1 +"""); + } + + public override async Task Column_collection_SingleOrDefault(bool async) + { + await base.Column_collection_SingleOrDefault(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE COALESCE(( + SELECT TOP(1) CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int)), 0) = 1 +"""); + } + + public override async Task Column_collection_Skip(bool async) + { + await base.Column_collection_Skip(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT 1 AS empty + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS + ) AS [i0]) = 2 +"""); + } + + public override async Task Column_collection_Take(bool async) + { + await base.Column_collection_Take(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 11 IN ( + SELECT TOP(2) CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int) +) +"""); + } + + public override async Task Column_collection_Skip_Take(bool async) + { + await base.Column_collection_Skip_Take(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 11 IN ( + SELECT CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY +) +"""); + } + + public override async Task Column_collection_Where_Skip(bool async) + { + await base.Column_collection_Where_Skip(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT 1 AS empty + FROM OPENJSON([p].[Ints]) AS [i] + WHERE CAST([i].[value] AS int) > 1 + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS + ) AS [i0]) = 3 +"""); + } + + public override async Task Column_collection_Where_Take(bool async) + { + await base.Column_collection_Where_Take(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT TOP(2) 1 AS empty + FROM OPENJSON([p].[Ints]) AS [i] + WHERE CAST([i].[value] AS int) > 1 + ORDER BY CAST([i].[key] AS int) + ) AS [i0]) = 2 +"""); + } + + public override async Task Column_collection_Where_Skip_Take(bool async) + { + await base.Column_collection_Where_Skip_Take(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT 1 AS empty + FROM OPENJSON([p].[Ints]) AS [i] + WHERE CAST([i].[value] AS int) > 1 + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY + ) AS [i0]) = 1 +"""); + } + + public override async Task Column_collection_Contains_over_subquery(bool async) + { + await base.Column_collection_Contains_over_subquery(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE 11 IN ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + WHERE [i].[value] > 1 +) +"""); + } + + public override async Task Column_collection_OrderByDescending_ElementAt(bool async) + { + await base.Column_collection_OrderByDescending_ElementAt(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + ORDER BY [i].[value] DESC + OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY) = 111 +"""); + } + + public override async Task Column_collection_Where_ElementAt(bool async) + { + await base.Column_collection_Where_ElementAt(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + WHERE CAST([i].[value] AS int) > 1 + ORDER BY CAST([i].[key] AS int) + OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY) = 11 +"""); + } + + public override async Task Column_collection_Any(bool async) + { + await base.Column_collection_Any(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE EXISTS ( + SELECT 1 + FROM OPENJSON([p].[Ints]) AS [i]) +"""); + } + + public override async Task Column_collection_Distinct(bool async) + { + await base.Column_collection_Distinct(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT DISTINCT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + ) AS [i0]) = 3 +"""); + } + + public override async Task Column_collection_SelectMany(bool async) + { + await base.Column_collection_SelectMany(async); + + AssertSql( + """ +SELECT [i].[value] +FROM [PrimitiveCollectionsEntity] AS [p] +CROSS APPLY OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] +"""); + } + + public override async Task Column_collection_SelectMany_with_filter(bool async) + { + await base.Column_collection_SelectMany_with_filter(async); + + AssertSql( + """ +SELECT [i0].[value] +FROM [PrimitiveCollectionsEntity] AS [p] +CROSS APPLY ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + WHERE [i].[value] > 1 +) AS [i0] +"""); + } + + public override async Task Column_collection_SelectMany_with_Select_to_anonymous_type(bool async) + { + await base.Column_collection_SelectMany_with_Select_to_anonymous_type(async); + + AssertSql( + """ +SELECT [i].[value] AS [Original], [i].[value] + 1 AS [Incremented] +FROM [PrimitiveCollectionsEntity] AS [p] +CROSS APPLY OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] +"""); + } + + public override async Task Column_collection_projection_from_top_level(bool async) + { + await base.Column_collection_projection_from_top_level(async); + + AssertSql( + """ +SELECT [p].[Ints] +FROM [PrimitiveCollectionsEntity] AS [p] +ORDER BY [p].[Id] +"""); + } + + public override async Task Column_collection_Join_parameter_collection(bool async) + { + await base.Column_collection_Join_parameter_collection(async); + + AssertSql( + """ +@__ints_0='[11,111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + INNER JOIN OPENJSON(@__ints_0) WITH ([value] int '$') AS [i0] ON [i].[value] = [i0].[value]) = 2 +"""); + } + + public override async Task Inline_collection_Join_ordered_column_collection(bool async) + { + await base.Inline_collection_Join_ordered_column_collection(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM (VALUES (CAST(11 AS int)), (111)) AS [v]([Value]) + INNER JOIN OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] ON [v].[Value] = [i].[value]) = 2 +"""); + } + + public override async Task Parameter_collection_Concat_column_collection(bool async) + { + await base.Parameter_collection_Concat_column_collection(async); + + AssertSql( + """ +@__ints_0='[11,111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT 1 AS empty + FROM OPENJSON(@__ints_0) AS [i] + UNION ALL + SELECT 1 AS empty + FROM OPENJSON([p].[Ints]) AS [i0] + ) AS [u]) = 2 +"""); + } + + public override async Task Column_collection_Union_parameter_collection(bool async) + { + await base.Column_collection_Union_parameter_collection(async); + + AssertSql( + """ +@__ints_0='[11,111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + UNION + SELECT [i0].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i0] + ) AS [u]) = 2 +"""); + } + + public override async Task Column_collection_Intersect_inline_collection(bool async) + { + await base.Column_collection_Intersect_inline_collection(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + INTERSECT + SELECT [v].[Value] AS [value] + FROM (VALUES (CAST(11 AS int)), (111)) AS [v]([Value]) + ) AS [i0]) = 2 +"""); + } + + public override async Task Inline_collection_Except_column_collection(bool async) + { + await base.Inline_collection_Except_column_collection(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [v].[Value] + FROM (VALUES (CAST(11 AS int)), (111)) AS [v]([Value]) + EXCEPT + SELECT [i].[value] AS [Value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + ) AS [e] + WHERE [e].[Value] % 2 = 1) = 2 +"""); + } + + public override async Task Column_collection_Where_Union(bool async) + { + await base.Column_collection_Where_Union(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + WHERE [i].[value] > 100 + UNION + SELECT [v].[Value] AS [value] + FROM (VALUES (CAST(50 AS int))) AS [v]([Value]) + ) AS [u]) = 2 +"""); + } + + public override async Task Column_collection_equality_parameter_collection(bool async) + { + await base.Column_collection_equality_parameter_collection(async); + + AssertSql( + """ +@__ints_0='[1,10]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Ints] = @__ints_0 +"""); + } + + public override async Task Column_collection_Concat_parameter_collection_equality_inline_collection(bool async) + { + await base.Column_collection_Concat_parameter_collection_equality_inline_collection(async); + + AssertSql(); + } + + public override async Task Column_collection_equality_inline_collection(bool async) + { + await base.Column_collection_equality_inline_collection(async); + + AssertSql( + """ +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Ints] = N'[1,10]' +"""); + } + + public override async Task Column_collection_equality_inline_collection_with_parameters(bool async) + { + await base.Column_collection_equality_inline_collection_with_parameters(async); + + AssertSql(); + } + + public override async Task Column_collection_Where_equality_inline_collection(bool async) + { + await base.Column_collection_Where_equality_inline_collection(async); + + AssertSql(); + } + + public override async Task Parameter_collection_in_subquery_Union_column_collection_as_compiled_query(bool async) + { + await base.Parameter_collection_in_subquery_Union_column_collection_as_compiled_query(async); + + AssertSql( + """ +@__ints='[10,111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [i1].[value] + FROM ( + SELECT CAST([i].[value] AS int) AS [value] + FROM OPENJSON(@__ints) AS [i] + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS + ) AS [i1] + UNION + SELECT [i0].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i0] + ) AS [u]) = 3 +"""); + } + + public override async Task Parameter_collection_in_subquery_Union_column_collection(bool async) + { + await base.Parameter_collection_in_subquery_Union_column_collection(async); + + AssertSql( + """ +@__Skip_0='[111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [s].[value] + FROM OPENJSON(@__Skip_0) WITH ([value] int '$') AS [s] + UNION + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + ) AS [u]) = 3 +"""); + } + + public override async Task Parameter_collection_in_subquery_Union_column_collection_nested(bool async) + { + await base.Parameter_collection_in_subquery_Union_column_collection_nested(async); + + AssertSql( + """ +@__Skip_0='[111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [s].[value] + FROM OPENJSON(@__Skip_0) WITH ([value] int '$') AS [s] + UNION + SELECT [i2].[value] + FROM ( + SELECT TOP(20) [i1].[value] + FROM ( + SELECT DISTINCT [i0].[value] + FROM ( + SELECT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] + ORDER BY [i].[value] + OFFSET 1 ROWS + ) AS [i0] + ) AS [i1] + ORDER BY [i1].[value] DESC + ) AS [i2] + ) AS [u]) = 3 +"""); + } + + public override void Parameter_collection_in_subquery_and_Convert_as_compiled_query() + { + base.Parameter_collection_in_subquery_and_Convert_as_compiled_query(); + + AssertSql(); + } + + public override async Task Parameter_collection_in_subquery_Count_as_compiled_query(bool async) + { + await base.Parameter_collection_in_subquery_Count_as_compiled_query(async); + + // TODO: the subquery projection contains extra columns which we should remove + AssertSql( + """ +@__ints='[10,111]' (Size = 4000) + +SELECT COUNT(*) +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT CAST([i].[value] AS int) AS [value0] + FROM OPENJSON(@__ints) AS [i] + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS + ) AS [i0] + WHERE [i0].[value0] > [p].[Id]) = 1 +"""); + } + + public override async Task Parameter_collection_in_subquery_Union_another_parameter_collection_as_compiled_query(bool async) + { + await base.Parameter_collection_in_subquery_Union_another_parameter_collection_as_compiled_query(async); + + AssertSql(); + } + + public override async Task Column_collection_in_subquery_Union_parameter_collection(bool async) + { + await base.Column_collection_in_subquery_Union_parameter_collection(async); + + AssertSql( + """ +@__ints_0='[10,111]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE ( + SELECT COUNT(*) + FROM ( + SELECT [i1].[value] + FROM ( + SELECT CAST([i].[value] AS int) AS [value] + FROM OPENJSON([p].[Ints]) AS [i] + ORDER BY CAST([i].[key] AS int) + OFFSET 1 ROWS + ) AS [i1] + UNION + SELECT [i0].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i0] + ) AS [u]) = 3 +"""); + } + + public override async Task Project_collection_of_ints_simple(bool async) + { + await base.Project_collection_of_ints_simple(async); + + AssertSql( + """ +SELECT [p].[Ints] +FROM [PrimitiveCollectionsEntity] AS [p] +ORDER BY [p].[Id] +"""); + } + + public override async Task Project_collection_of_ints_ordered(bool async) + { + await base.Project_collection_of_ints_ordered(async); + + AssertSql( + """ +SELECT [p].[Id], CAST([i].[value] AS int) AS [value], [i].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY OPENJSON([p].[Ints]) AS [i] +ORDER BY [p].[Id], CAST([i].[value] AS int) DESC +"""); + } + + public override async Task Project_collection_of_datetimes_filtered(bool async) + { + await base.Project_collection_of_datetimes_filtered(async); + + AssertSql( + """ +SELECT [p].[Id], [d0].[value], [d0].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT CAST([d].[value] AS datetime2) AS [value], [d].[key], CAST([d].[key] AS int) AS [c] + FROM OPENJSON([p].[DateTimes]) AS [d] + WHERE DATEPART(day, CAST([d].[value] AS datetime2)) <> 1 +) AS [d0] +ORDER BY [p].[Id], [d0].[c] +"""); + } + + public override async Task Project_collection_of_nullable_ints_with_paging(bool async) + { + await base.Project_collection_of_nullable_ints_with_paging(async); + + AssertSql( + """ +SELECT [p].[Id], [n0].[value], [n0].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT TOP(20) CAST([n].[value] AS int) AS [value], [n].[key], CAST([n].[key] AS int) AS [c] + FROM OPENJSON([p].[NullableInts]) AS [n] + ORDER BY CAST([n].[key] AS int) +) AS [n0] +ORDER BY [p].[Id], [n0].[c] +"""); + } + + public override async Task Project_collection_of_nullable_ints_with_paging2(bool async) + { + await base.Project_collection_of_nullable_ints_with_paging2(async); + + AssertSql( + """ +SELECT [p].[Id], [n0].[value], [n0].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT CAST([n].[value] AS int) AS [value], [n].[key] + FROM OPENJSON([p].[NullableInts]) AS [n] + ORDER BY CAST([n].[value] AS int) + OFFSET 1 ROWS +) AS [n0] +ORDER BY [p].[Id], [n0].[value] +"""); + } + + public override async Task Project_collection_of_nullable_ints_with_paging3(bool async) + { + await base.Project_collection_of_nullable_ints_with_paging3(async); + + AssertSql( + """ +SELECT [p].[Id], [n0].[value], [n0].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT CAST([n].[value] AS int) AS [value], [n].[key], CAST([n].[key] AS int) AS [c] + FROM OPENJSON([p].[NullableInts]) AS [n] + ORDER BY CAST([n].[key] AS int) + OFFSET 2 ROWS +) AS [n0] +ORDER BY [p].[Id], [n0].[c] +"""); + } + + public override async Task Project_collection_of_ints_with_distinct(bool async) + { + await base.Project_collection_of_ints_with_distinct(async); + + AssertSql( + """ +SELECT [p].[Id], [i0].[value] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT DISTINCT [i].[value] + FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i] +) AS [i0] +ORDER BY [p].[Id] +"""); + } + + public override async Task Project_collection_of_nullable_ints_with_distinct(bool async) + { + await base.Project_collection_of_nullable_ints_with_distinct(async); + + AssertSql(""); + } + + public override async Task Project_collection_of_ints_with_ToList_and_FirstOrDefault(bool async) + { + await base.Project_collection_of_ints_with_ToList_and_FirstOrDefault(async); + + AssertSql( + """ +SELECT [p0].[Id], CAST([i].[value] AS int) AS [value], [i].[key] +FROM ( + SELECT TOP(1) [p].[Id], [p].[Ints] + FROM [PrimitiveCollectionsEntity] AS [p] + ORDER BY [p].[Id] +) AS [p0] +OUTER APPLY OPENJSON([p0].[Ints]) AS [i] +ORDER BY [p0].[Id], CAST([i].[key] AS int) +"""); + } + + public override async Task Project_empty_collection_of_nullables_and_collection_only_containing_nulls(bool async) + { + await base.Project_empty_collection_of_nullables_and_collection_only_containing_nulls(async); + + AssertSql( + """ +SELECT [p].[Id], [n1].[value], [n1].[key], [n2].[value], [n2].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT CAST([n].[value] AS int) AS [value], [n].[key], CAST([n].[key] AS int) AS [c] + FROM OPENJSON([p].[NullableInts]) AS [n] + WHERE 0 = 1 +) AS [n1] +OUTER APPLY ( + SELECT CAST([n0].[value] AS int) AS [value], [n0].[key], CAST([n0].[key] AS int) AS [c] + FROM OPENJSON([p].[NullableInts]) AS [n0] + WHERE [n0].[value] IS NULL +) AS [n2] +ORDER BY [p].[Id], [n1].[c], [n1].[key], [n2].[c] +"""); + } + + public override async Task Project_multiple_collections(bool async) + { + await base.Project_multiple_collections(async); + + AssertSql( + """ +SELECT [p].[Id], CAST([i].[value] AS int) AS [value], [i].[key], CAST([i0].[value] AS int) AS [value], [i0].[key], [d1].[value], [d1].[key], [d2].[value], [d2].[key] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY OPENJSON([p].[Ints]) AS [i] +OUTER APPLY OPENJSON([p].[Ints]) AS [i0] +OUTER APPLY ( + SELECT CAST([d].[value] AS datetime2) AS [value], [d].[key], CAST([d].[key] AS int) AS [c] + FROM OPENJSON([p].[DateTimes]) AS [d] + WHERE DATEPART(day, CAST([d].[value] AS datetime2)) <> 1 +) AS [d1] +OUTER APPLY ( + SELECT CAST([d0].[value] AS datetime2) AS [value], [d0].[key], CAST([d0].[key] AS int) AS [c] + FROM OPENJSON([p].[DateTimes]) AS [d0] + WHERE CAST([d0].[value] AS datetime2) > '2000-01-01T00:00:00.0000000' +) AS [d2] +ORDER BY [p].[Id], CAST([i].[key] AS int), [i].[key], CAST([i0].[value] AS int) DESC, [i0].[key], [d1].[c], [d1].[key], [d2].[c] +"""); + } + + public override async Task Project_primitive_collections_element(bool async) + { + await base.Project_primitive_collections_element(async); + + AssertSql( + """ +SELECT CAST(JSON_VALUE([p].[Ints], '$[0]') AS int) AS [Indexer], CAST(JSON_VALUE([p].[DateTimes], '$[0]') AS datetime2) AS [EnumerableElementAt], JSON_VALUE([p].[Strings], '$[1]') AS [QueryableElementAt] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Id] < 4 +ORDER BY [p].[Id] +"""); + } + + public override async Task Project_inline_collection(bool async) + { + await base.Project_inline_collection(async); + + AssertSql( + """ +SELECT [p].[String] +FROM [PrimitiveCollectionsEntity] AS [p] +"""); + } + + public override async Task Project_inline_collection_with_Union(bool async) + { + await base.Project_inline_collection_with_Union(async); + + AssertSql( + """ +SELECT [p].[Id], [u].[Value] +FROM [PrimitiveCollectionsEntity] AS [p] +OUTER APPLY ( + SELECT [v].[Value] + FROM (VALUES ([p].[String])) AS [v]([Value]) + UNION + SELECT [p0].[String] AS [Value] + FROM [PrimitiveCollectionsEntity] AS [p0] +) AS [u] +ORDER BY [p].[Id] +"""); + } + + public override async Task Project_inline_collection_with_Concat(bool async) + { + await base.Project_inline_collection_with_Concat(async); + + AssertSql(); + } + + public override async Task Nested_contains_with_Lists_and_no_inferred_type_mapping(bool async) + { + await base.Nested_contains_with_Lists_and_no_inferred_type_mapping(async); + + AssertSql( + """ +@__ints_0='[1,2,3]' (Size = 4000) +@__strings_1='["one","two","three"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CASE + WHEN [p].[Int] IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] + ) THEN N'one' + ELSE N'two' +END IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_1) WITH ([value] nvarchar(max) '$') AS [s] +) +"""); + } + + public override async Task Nested_contains_with_arrays_and_no_inferred_type_mapping(bool async) + { + await base.Nested_contains_with_arrays_and_no_inferred_type_mapping(async); + + AssertSql( + """ +@__ints_0='[1,2,3]' (Size = 4000) +@__strings_1='["one","two","three"]' (Size = 4000) + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE CASE + WHEN [p].[Int] IN ( + SELECT [i].[value] + FROM OPENJSON(@__ints_0) WITH ([value] int '$') AS [i] + ) THEN N'one' + ELSE N'two' +END IN ( + SELECT [s].[value] + FROM OPENJSON(@__strings_1) WITH ([value] nvarchar(max) '$') AS [s] +) +"""); + } + + [ConditionalFact] + public virtual void Check_all_tests_overridden() + => TestHelpers.AssertAllMethodsOverridden(GetType()); + + private void AssertSql(params string[] expected) + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + + private PrimitiveCollectionsContext CreateContext() + => Fixture.CreateContext(); + + public class PrimitiveCollectionsQuerySqlServerFixture : PrimitiveCollectionsQueryFixtureBase, ITestSqlLoggerFactory + { + protected override string StoreName + => "PrimitiveCollections160Test"; + + public TestSqlLoggerFactory TestSqlLoggerFactory + => (TestSqlLoggerFactory)ListLoggerFactory; + + protected override ITestStoreFactory TestStoreFactory + => SqlServerTestStoreFactory.Instance; + + public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) + => base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160)); + + protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) + { + base.OnModelCreating(modelBuilder, context); + + // Map DateTime to non-default datetime instead of the default datetime2 to exercise type mapping inference + modelBuilder.Entity().Property(p => p.DateTime).HasColumnType("datetime"); + } + } +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs index 6b417b6dd1b..09d2a392c88 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs @@ -242,7 +242,6 @@ WHERE [p].[Id] NOT IN (2, 999) """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_Min_with_two_values(bool async) { await base.Inline_collection_Min_with_two_values(async); @@ -251,11 +250,12 @@ public override async Task Inline_collection_Min_with_two_values(bool async) """ SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE LEAST(30, [p].[Int]) = 30 +WHERE ( + SELECT MIN([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int])) AS [v]([Value])) = 30 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_List_Min_with_two_values(bool async) { await base.Inline_collection_List_Min_with_two_values(async); @@ -264,11 +264,12 @@ public override async Task Inline_collection_List_Min_with_two_values(bool async """ SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE LEAST(30, [p].[Int]) = 30 +WHERE ( + SELECT MIN([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int])) AS [v]([Value])) = 30 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_Max_with_two_values(bool async) { await base.Inline_collection_Max_with_two_values(async); @@ -277,11 +278,12 @@ public override async Task Inline_collection_Max_with_two_values(bool async) """ SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE GREATEST(30, [p].[Int]) = 30 +WHERE ( + SELECT MAX([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int])) AS [v]([Value])) = 30 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_List_Max_with_two_values(bool async) { await base.Inline_collection_List_Max_with_two_values(async); @@ -290,11 +292,12 @@ public override async Task Inline_collection_List_Max_with_two_values(bool async """ SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE GREATEST(30, [p].[Int]) = 30 +WHERE ( + SELECT MAX([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int])) AS [v]([Value])) = 30 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_Min_with_three_values(bool async) { await base.Inline_collection_Min_with_three_values(async); @@ -305,11 +308,12 @@ public override async Task Inline_collection_Min_with_three_values(bool async) SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE LEAST(30, [p].[Int], @__i_0) = 25 +WHERE ( + SELECT MIN([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int]), (@__i_0)) AS [v]([Value])) = 25 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_List_Min_with_three_values(bool async) { await base.Inline_collection_List_Min_with_three_values(async); @@ -320,11 +324,12 @@ public override async Task Inline_collection_List_Min_with_three_values(bool asy SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE LEAST(30, [p].[Int], @__i_0) = 25 +WHERE ( + SELECT MIN([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int]), (@__i_0)) AS [v]([Value])) = 25 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_Max_with_three_values(bool async) { await base.Inline_collection_Max_with_three_values(async); @@ -335,11 +340,12 @@ public override async Task Inline_collection_Max_with_three_values(bool async) SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE GREATEST(30, [p].[Int], @__i_0) = 35 +WHERE ( + SELECT MAX([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int]), (@__i_0)) AS [v]([Value])) = 35 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_List_Max_with_three_values(bool async) { await base.Inline_collection_List_Max_with_three_values(async); @@ -350,11 +356,12 @@ public override async Task Inline_collection_List_Max_with_three_values(bool asy SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE GREATEST(30, [p].[Int], @__i_0) = 35 +WHERE ( + SELECT MAX([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int]), (@__i_0)) AS [v]([Value])) = 35 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_of_nullable_value_type_Min(bool async) { await base.Inline_collection_of_nullable_value_type_Min(async); @@ -365,11 +372,12 @@ public override async Task Inline_collection_of_nullable_value_type_Min(bool asy SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE LEAST(30, [p].[Int], @__i_0) = 25 +WHERE ( + SELECT MIN([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int]), (@__i_0)) AS [v]([Value])) = 25 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_of_nullable_value_type_Max(bool async) { await base.Inline_collection_of_nullable_value_type_Max(async); @@ -380,11 +388,12 @@ public override async Task Inline_collection_of_nullable_value_type_Max(bool asy SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE GREATEST(30, [p].[Int], @__i_0) = 35 +WHERE ( + SELECT MAX([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[Int]), (@__i_0)) AS [v]([Value])) = 35 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_of_nullable_value_type_with_null_Min(bool async) { await base.Inline_collection_of_nullable_value_type_with_null_Min(async); @@ -393,11 +402,12 @@ public override async Task Inline_collection_of_nullable_value_type_with_null_Mi """ SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE LEAST(30, [p].[NullableInt], NULL) = 30 +WHERE ( + SELECT MIN([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[NullableInt]), (NULL)) AS [v]([Value])) = 30 """); } - [SqlServerCondition(SqlServerCondition.SupportsFunctions2022)] public override async Task Inline_collection_of_nullable_value_type_with_null_Max(bool async) { await base.Inline_collection_of_nullable_value_type_with_null_Max(async); @@ -406,7 +416,9 @@ public override async Task Inline_collection_of_nullable_value_type_with_null_Ma """ SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings] FROM [PrimitiveCollectionsEntity] AS [p] -WHERE GREATEST(30, [p].[NullableInt], NULL) = 30 +WHERE ( + SELECT MAX([v].[Value]) + FROM (VALUES (CAST(30 AS int)), ([p].[NullableInt]), (NULL)) AS [v]([Value])) = 30 """); }