From f4628ea869b971fdbeadab8890d46be192e0af89 Mon Sep 17 00:00:00 2001 From: maumar Date: Thu, 12 Nov 2020 21:05:08 -0800 Subject: [PATCH] Add regression tests to several bugs that were fixed previously Resolves #21836 Resolves #22978 Resolves #23205 --- .../Query/ComplexNavigationsQueryTestBase.cs | 57 +++++++++++++ .../Query/GearsOfWarQueryTestBase.cs | 15 ++++ .../Query/NorthwindWhereQueryTestBase.cs | 10 +++ .../TestModels/GearsOfWarModel/CogTag.cs | 1 + .../GearsOfWarModel/GearsOfWarData.cs | 12 +-- .../ComplexNavigationsQuerySqlServerTest.cs | 27 +++++++ .../Query/GearsOfWarQuerySqlServerTest.cs | 81 ++++++++++++------- .../Query/TPTGearsOfWarQuerySqlServerTest.cs | 62 +++++++------- .../ComplexNavigationsQuerySqliteTest.cs | 6 ++ .../ComplexNavigationsWeakQuerySqliteTest.cs | 6 ++ 10 files changed, 209 insertions(+), 68 deletions(-) diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index 5d69c6b1b56..6fe25a2e2a2 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -5824,5 +5824,62 @@ public virtual Task Projecting_columns_with_same_name_from_different_entities_ma select new { Id1 = l1.Id, Id2 = l2.Id, Id3 = l3.Id, Name1 = l1.Name, Name2 = l2.Name }).Distinct().Select(x => new { Foo = x.Id1, Bar = x.Id2, Baz = x.Id3 }).Take(10), elementSorter: e => (e.Foo, e.Bar, e.Baz)); } + + [ConditionalTheory(Skip = "issue #23302")] + [MemberData(nameof(IsAsyncData))] + public virtual Task Queryable_in_subquery_works_when_final_projection_is_List(bool async) + { + return AssertQuery( + async, + ss => from l1 in ss.Set() + orderby l1.Id + let inner = (from l2 in l1.OneToMany_Optional1 + where l2.Name != "Foo" + let innerL1s = from innerL1 in ss.Set() + where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id) + select innerL1.Name + select innerL1s).FirstOrDefault() + select inner.ToList(), + assertOrder: true, + elementAsserter: (e, a) => AssertCollection(e, a)); + } + + [ConditionalTheory(Skip = "issue #23303")] + [MemberData(nameof(IsAsyncData))] + public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async) + { + return AssertQuery( + async, + ss => from l1 in ss.Set() + orderby l1.Id + let inner = (from l2 in l1.OneToMany_Optional1 + where l2.Name != "Foo" + let innerL1s = from innerL1 in ss.Set() + where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id) + select innerL1.Name + select innerL1s.ToList()).FirstOrDefault() + select inner.ToList(), + assertOrder: true, + elementAsserter: (e, a) => AssertCollection(e, a)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) + { + return AssertQuery( + async, + ss => from l1 in ss.Set() + orderby l1.Id + let inner = (from l2 in l1.OneToMany_Optional1 + where l2.Name != "Foo" + let innerL1s = from innerL1 in ss.Set() + where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id) + select innerL1.Name + select innerL1s.ToList()).FirstOrDefault() + select inner, + assertOrder: true, + elementAsserter: (e, a) => AssertCollection(e, a)); + } } } diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index d69f83acf7f..42d95e70327 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -7933,6 +7933,21 @@ public virtual Task Sum_with_no_data_nullable_double(bool async) ss => ss.Set().Where(m => m.CodeName == "Operation Foobar").Select(m => m.Rating)); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task FirstOrDefault_on_empty_collection_of_DateTime_in_subquery(bool async) + { + return AssertQuery( + async, + ss => from g in ss.Set() + let invalidTagIssueDate = (from t in ss.Set() + where t.GearNickName == g.FullName + orderby t.Id + select t.IssueDate).FirstOrDefault() + where g.Tag.IssueDate > invalidTagIssueDate + select new { g.Nickname, invalidTagIssueDate }); + } + protected GearsOfWarContext CreateContext() => Fixture.CreateContext(); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs index cfda11cfbb5..09c500325ba 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs @@ -2456,5 +2456,15 @@ public virtual Task Two_sets_of_comparison_combine_correctly2(bool async) c => (c.Region != "WA" && c.Region != "OR" && c.Region != null) || (c.Region != "WA" && c.Region != null)), entryCount: 28); } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Filter_with_property_compared_to_null_wrapped_in_explicit_convert_to_object(bool async) + { + return AssertQuery( + async, + ss => ss.Set().Where(c => (object)c.Region == null), + entryCount: 60); + } } } diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/CogTag.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/CogTag.cs index 7ee28cc15b6..fd383f2907f 100644 --- a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/CogTag.cs +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/CogTag.cs @@ -15,5 +15,6 @@ public class CogTag public string GearNickName { get; set; } public int? GearSquadId { get; set; } public virtual Gear Gear { get; set; } + public DateTime IssueDate { get; set; } } } diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs index 601b4fd64c9..dc64d892a2b 100644 --- a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs @@ -267,12 +267,12 @@ public static IReadOnlyList CreateWeapons() public static IReadOnlyList CreateTags() => new List { - new CogTag { Id = Guid.Parse("DF36F493-463F-4123-83F9-6B135DEEB7BA"), Note = "Dom's Tag" }, - new CogTag { Id = Guid.Parse("A8AD98F9-E023-4E2A-9A70-C2728455BD34"), Note = "Cole's Tag" }, - new CogTag { Id = Guid.Parse("A7BE028A-0CF2-448F-AB55-CE8BC5D8CF69"), Note = "Paduk's Tag" }, - new CogTag { Id = Guid.Parse("70534E05-782C-4052-8720-C2C54481CE5F"), Note = "Baird's Tag" }, - new CogTag { Id = Guid.Parse("34C8D86E-A4AC-4BE5-827F-584DDA348A07"), Note = "Marcus' Tag" }, - new CogTag { Id = Guid.Parse("B39A6FBA-9026-4D69-828E-FD7068673E57"), Note = "K.I.A." } + new CogTag { Id = Guid.Parse("DF36F493-463F-4123-83F9-6B135DEEB7BA"), Note = "Dom's Tag", IssueDate = new DateTime(3, 2, 2) }, + new CogTag { Id = Guid.Parse("A8AD98F9-E023-4E2A-9A70-C2728455BD34"), Note = "Cole's Tag", IssueDate = new DateTime(2, 10, 11) }, + new CogTag { Id = Guid.Parse("A7BE028A-0CF2-448F-AB55-CE8BC5D8CF69"), Note = "Paduk's Tag", IssueDate = new DateTime(15, 3, 7) }, + new CogTag { Id = Guid.Parse("70534E05-782C-4052-8720-C2C54481CE5F"), Note = "Baird's Tag", IssueDate = new DateTime(7, 5, 3) }, + new CogTag { Id = Guid.Parse("34C8D86E-A4AC-4BE5-827F-584DDA348A07"), Note = "Marcus' Tag", IssueDate = new DateTime(1, 9, 25) }, + new CogTag { Id = Guid.Parse("B39A6FBA-9026-4D69-828E-FD7068673E57"), Note = "K.I.A.", IssueDate = new DateTime(21, 7, 7) } }; public static IReadOnlyList CreateGears() diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index f8055af551b..54c46d13287 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -6046,6 +6046,33 @@ public override async Task Projecting_columns_with_same_name_from_different_enti ) AS [t]"); } + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) + { + await base.Complex_query_with_let_collection_projection_FirstOrDefault(async); + + AssertSql( + @"SELECT [t0].[c], [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id] + FROM ( + SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row] + FROM [LevelTwo] AS [l0] + WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL + ) AS [t] + WHERE [t].[row] <= 1 +) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id] +OUTER APPLY ( + SELECT [l1].[Name], [l1].[Id] + FROM [LevelOne] AS [l1] + WHERE EXISTS ( + SELECT 1 + FROM [LevelTwo] AS [l2] + WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND ([l2].[Id] = [t0].[Id])) +) AS [t1] +ORDER BY [l].[Id], [t0].[Id], [t1].[Id]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index effbb3d64bd..d0dc82e90b9 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -68,7 +68,7 @@ public override async Task Include_multiple_one_to_one_and_one_to_many(bool asyn await base.Include_multiple_one_to_one_and_one_to_many(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) LEFT JOIN [Weapons] AS [w] ON [g].[FullName] = [w].[OwnerFullName] @@ -80,7 +80,7 @@ public override async Task Include_multiple_one_to_one_optional_and_one_to_one_r await base.Include_multiple_one_to_one_optional_and_one_to_one_required(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) LEFT JOIN [Squads] AS [s] ON [g].[SquadId] = [s].[Id]"); @@ -152,7 +152,7 @@ public override async Task Select_Where_Navigation_Included(bool async) await base.Select_Where_Navigation_Included(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE [g].[Nickname] = N'Marcus'"); @@ -212,7 +212,7 @@ public override async Task Include_where_list_contains_navigation(bool async) @"SELECT [t].[Id] FROM [Tags] AS [t]", // - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) WHERE [t].[Id] IS NOT NULL AND [t].[Id] IN ('34c8d86e-a4ac-4be5-827f-584dda348a07', 'df36f493-463f-4123-83f9-6b135deeb7ba', 'a8ad98f9-e023-4e2a-9a70-c2728455bd34', '70534e05-782c-4052-8720-c2c54481ce5f', 'a7be028a-0cf2-448f-ab55-ce8bc5d8cf69', 'b39a6fba-9026-4d69-828e-fd7068673e57')"); @@ -226,7 +226,7 @@ public override async Task Include_where_list_contains_navigation2(bool async) @"SELECT [t].[Id] FROM [Tags] AS [t]", // - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] INNER JOIN [Cities] AS [c] ON [g].[CityOfBirthName] = [c].[Name] LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) @@ -1194,7 +1194,7 @@ public override async Task Select_Where_Navigation_Scalar_Equals_Navigation_Scal await base.Select_Where_Navigation_Scalar_Equals_Navigation_Scalar(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[IssueDate], [t0].[Note] FROM [Tags] AS [t] CROSS JOIN [Tags] AS [t0] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) @@ -1218,7 +1218,7 @@ public override async Task Select_Where_Navigation(bool async) await base.Select_Where_Navigation(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE [g].[Nickname] = N'Marcus'"); @@ -1229,7 +1229,7 @@ public override async Task Select_Where_Navigation_Equals_Navigation(bool async) await base.Select_Where_Navigation_Equals_Navigation(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[IssueDate], [t0].[Note] FROM [Tags] AS [t] CROSS JOIN [Tags] AS [t0] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) @@ -1242,7 +1242,7 @@ public override async Task Select_Where_Navigation_Null(bool async) await base.Select_Where_Navigation_Null(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE [g].[Nickname] IS NULL OR [g].[SquadId] IS NULL"); @@ -1253,7 +1253,7 @@ public override async Task Select_Where_Navigation_Null_Reverse(bool async) await base.Select_Where_Navigation_Null_Reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE [g].[Nickname] IS NULL OR [g].[SquadId] IS NULL"); @@ -1782,7 +1782,7 @@ public override async Task Collection_with_inheritance_and_join_include_joined(b await base.Collection_with_inheritance_and_join_include_joined(async); AssertSql( - @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[Discriminator], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t1].[Id], [t1].[GearNickName], [t1].[GearSquadId], [t1].[Note] + @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[Discriminator], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t1].[Id], [t1].[GearNickName], [t1].[GearSquadId], [t1].[IssueDate], [t1].[Note] FROM [Tags] AS [t] INNER JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] @@ -1797,7 +1797,7 @@ public override async Task Collection_with_inheritance_and_join_include_source(b await base.Collection_with_inheritance_and_join_include_source(async); AssertSql( - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[Note] + @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[IssueDate], [t0].[Note] FROM [Gears] AS [g] INNER JOIN [Tags] AS [t] ON ([g].[SquadId] = [t].[GearSquadId]) AND ([g].[Nickname] = [t].[GearNickName]) LEFT JOIN [Tags] AS [t0] ON ([g].[Nickname] = [t0].[GearNickName]) AND ([g].[SquadId] = [t0].[GearSquadId]) @@ -2091,7 +2091,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE (([t].[Note] <> N'K.I.A.') OR [t].[Note] IS NULL) AND ([g].[HasSoulPatch] = CAST(1 AS bit))"); @@ -2102,7 +2102,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate2(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE [g].[HasSoulPatch] = CAST(1 AS bit)"); @@ -2113,7 +2113,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate_negated(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE [g].[HasSoulPatch] <> CAST(1 AS bit)"); @@ -2124,7 +2124,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate_negated_complex1(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE CASE @@ -2138,7 +2138,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate_negated_complex2(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE CASE @@ -2152,7 +2152,7 @@ public override async Task Optional_navigation_type_compensation_works_with_cond await base.Optional_navigation_type_compensation_works_with_conditional_expression(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE CASE @@ -2166,7 +2166,7 @@ public override async Task Optional_navigation_type_compensation_works_with_bina await base.Optional_navigation_type_compensation_works_with_binary_expression(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE ([g].[HasSoulPatch] = CAST(1 AS bit)) OR ([t].[Note] LIKE N'%Cole%')"); @@ -2246,7 +2246,7 @@ public override async Task Optional_navigation_type_compensation_works_with_orde await base.Optional_navigation_type_compensation_works_with_orderby(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE ([t].[Note] <> N'K.I.A.') OR [t].[Note] IS NULL @@ -2273,7 +2273,7 @@ public override async Task Optional_navigation_type_compensation_works_with_nega await base.Optional_navigation_type_compensation_works_with_negated_predicate(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE (([t].[Note] <> N'K.I.A.') OR [t].[Note] IS NULL) AND ([g].[HasSoulPatch] <> CAST(1 AS bit))"); @@ -2284,7 +2284,7 @@ public override async Task Optional_navigation_type_compensation_works_with_cont await base.Optional_navigation_type_compensation_works_with_contains(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE (([t].[Note] <> N'K.I.A.') OR [t].[Note] IS NULL) AND EXISTS ( @@ -2785,7 +2785,7 @@ public override async Task Contains_with_local_nullable_guid_list_closure(bool a await base.Contains_with_local_nullable_guid_list_closure(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] WHERE [t].[Id] IN ('d2c26679-562b-44d1-ab96-23d1775e0926', '23cbcf9b-ce14-45cf-aafa-2c2667ebfdd3', 'ab1b82d7-88db-42bd-a132-7eef9aa68af4')"); } @@ -2828,7 +2828,7 @@ public override async Task Where_is_properly_lifted_from_subquery_created_by_inc await base.Where_is_properly_lifted_from_subquery_created_by_include(async); AssertSql( - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) WHERE ([g].[FullName] <> N'Augustus Cole') AND ([g].[HasSoulPatch] <> CAST(1 AS bit)) @@ -3298,7 +3298,7 @@ public override async Task Optional_navigation_with_collection_composite_key(boo await base.Optional_navigation_with_collection_composite_key(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) WHERE ([g].[Discriminator] = N'Officer') AND (( @@ -3487,7 +3487,7 @@ public override async Task Include_base_navigation_on_derived_entity(bool async) await base.Include_base_navigation_on_derived_entity(async); AssertSql( - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] + @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Gears] AS [g] LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) LEFT JOIN [Weapons] AS [w] ON [g].[FullName] = [w].[OwnerFullName] @@ -3499,7 +3499,7 @@ public override async Task ThenInclude_collection_on_derived_after_base_referenc await base.ThenInclude_collection_on_derived_after_base_reference(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) LEFT JOIN [Weapons] AS [w] ON [g].[FullName] = [w].[OwnerFullName] @@ -5577,7 +5577,7 @@ public override async Task Include_with_client_method_and_member_access_still_ap await base.Include_with_client_method_and_member_access_still_applies_includes(async); AssertSql( - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId])"); } @@ -5738,7 +5738,7 @@ public override async Task async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) LEFT JOIN [Squads] AS [s] ON [g].[SquadId] = [s].[Id] @@ -5750,7 +5750,7 @@ public override async Task Filter_with_new_Guid(bool async) await base.Filter_with_new_Guid(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] WHERE [t].[Id] = 'df36f493-463f-4123-83f9-6b135deeb7ba'"); } @@ -6225,7 +6225,7 @@ public override async Task Reference_include_chain_loads_correctly_when_middle_i await base.Reference_include_chain_loads_correctly_when_middle_is_null(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] FROM [Tags] AS [t] LEFT JOIN [Gears] AS [g] ON ([t].[GearNickName] = [g].[Nickname]) AND ([t].[GearSquadId] = [g].[SquadId]) LEFT JOIN [Squads] AS [s] ON [g].[SquadId] = [s].[Id] @@ -7325,6 +7325,25 @@ public override async Task Correlated_collection_take(bool async) ORDER BY [g].[Nickname], [g].[SquadId], [c].[Name], [t0].[OwnerFullName], [t0].[Id]"); } + public override async Task FirstOrDefault_on_empty_collection_of_DateTime_in_subquery(bool async) + { + await base.FirstOrDefault_on_empty_collection_of_DateTime_in_subquery(async); + + AssertSql( + @"SELECT [g].[Nickname], COALESCE(( + SELECT TOP(1) [t].[IssueDate] + FROM [Tags] AS [t] + WHERE [t].[GearNickName] = [g].[FullName] + ORDER BY [t].[Id]), '0001-01-01T00:00:00.0000000') AS [invalidTagIssueDate] +FROM [Gears] AS [g] +LEFT JOIN [Tags] AS [t0] ON ([g].[Nickname] = [t0].[GearNickName]) AND ([g].[SquadId] = [t0].[GearSquadId]) +WHERE [t0].[IssueDate] > COALESCE(( + SELECT TOP(1) [t1].[IssueDate] + FROM [Tags] AS [t1] + WHERE [t1].[GearNickName] = [g].[FullName] + ORDER BY [t1].[Id]), '0001-01-01T00:00:00.0000000')"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs index a6ec291b3ae..f688f44f627 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs @@ -71,7 +71,7 @@ public override async Task Include_multiple_one_to_one_and_one_to_many(bool asyn await base.Include_multiple_one_to_one_and_one_to_many(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE @@ -89,7 +89,7 @@ public override async Task Include_multiple_one_to_one_optional_and_one_to_one_r await base.Include_multiple_one_to_one_optional_and_one_to_one_required(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE @@ -206,7 +206,7 @@ public override async Task Select_Where_Navigation_Included(bool async) await base.Select_Where_Navigation_Included(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE @@ -292,7 +292,7 @@ public override async Task Include_where_list_contains_navigation(bool async) // @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' -END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] +END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Officers] AS [o] ON ([g].[Nickname] = [o].[Nickname]) AND ([g].[SquadId] = [o].[SquadId]) LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) @@ -309,7 +309,7 @@ public override async Task Include_where_list_contains_navigation2(bool async) // @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' -END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] +END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Officers] AS [o] ON ([g].[Nickname] = [o].[Nickname]) AND ([g].[SquadId] = [o].[SquadId]) INNER JOIN [Cities] AS [c] ON [g].[CityOfBirthName] = [c].[Name] @@ -1438,7 +1438,7 @@ public override async Task Select_Where_Navigation_Scalar_Equals_Navigation_Scal await base.Select_Where_Navigation_Scalar_Equals_Navigation_Scalar(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[IssueDate], [t0].[Note] FROM [Tags] AS [t] CROSS JOIN [Tags] AS [t0] LEFT JOIN ( @@ -1474,7 +1474,7 @@ public override async Task Select_Where_Navigation(bool async) await base.Select_Where_Navigation(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -1488,7 +1488,7 @@ public override async Task Select_Where_Navigation_Equals_Navigation(bool async) await base.Select_Where_Navigation_Equals_Navigation(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[IssueDate], [t0].[Note] FROM [Tags] AS [t] CROSS JOIN [Tags] AS [t0] LEFT JOIN ( @@ -1507,7 +1507,7 @@ public override async Task Select_Where_Navigation_Null(bool async) await base.Select_Where_Navigation_Null(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -1521,7 +1521,7 @@ public override async Task Select_Where_Navigation_Null_Reverse(bool async) await base.Select_Where_Navigation_Null_Reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -2149,7 +2149,7 @@ public override async Task Collection_with_inheritance_and_join_include_joined(b await base.Collection_with_inheritance_and_join_include_joined(async); AssertSql( - @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Id], [t1].[GearNickName], [t1].[GearSquadId], [t1].[Note] + @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Id], [t1].[GearNickName], [t1].[GearSquadId], [t1].[IssueDate], [t1].[Note] FROM [Tags] AS [t] INNER JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE @@ -2169,7 +2169,7 @@ public override async Task Collection_with_inheritance_and_join_include_source(b AssertSql( @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' -END AS [Discriminator], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[Note] +END AS [Discriminator], [t0].[Id], [t0].[GearNickName], [t0].[GearSquadId], [t0].[IssueDate], [t0].[Note] FROM [Gears] AS [g] LEFT JOIN [Officers] AS [o] ON ([g].[Nickname] = [o].[Nickname]) AND ([g].[SquadId] = [o].[SquadId]) INNER JOIN [Tags] AS [t] ON ([g].[SquadId] = [t].[GearSquadId]) AND ([g].[Nickname] = [t].[GearNickName]) @@ -2501,7 +2501,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2515,7 +2515,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate2(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2529,7 +2529,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate_negated(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2543,7 +2543,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate_negated_complex1(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2560,7 +2560,7 @@ public override async Task Optional_navigation_type_compensation_works_with_pred await base.Optional_navigation_type_compensation_works_with_predicate_negated_complex2(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2577,7 +2577,7 @@ public override async Task Optional_navigation_type_compensation_works_with_cond await base.Optional_navigation_type_compensation_works_with_conditional_expression(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2594,7 +2594,7 @@ public override async Task Optional_navigation_type_compensation_works_with_bina await base.Optional_navigation_type_compensation_works_with_binary_expression(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2695,7 +2695,7 @@ public override async Task Optional_navigation_type_compensation_works_with_orde await base.Optional_navigation_type_compensation_works_with_orderby(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -2731,7 +2731,7 @@ public override async Task Optional_navigation_type_compensation_works_with_nega await base.Optional_navigation_type_compensation_works_with_negated_predicate(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch] @@ -2745,7 +2745,7 @@ public override async Task Optional_navigation_type_compensation_works_with_cont await base.Optional_navigation_type_compensation_works_with_contains(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -3289,7 +3289,7 @@ public override async Task Contains_with_local_nullable_guid_list_closure(bool a await base.Contains_with_local_nullable_guid_list_closure(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] WHERE [t].[Id] IN ('d2c26679-562b-44d1-ab96-23d1775e0926', '23cbcf9b-ce14-45cf-aafa-2c2667ebfdd3', 'ab1b82d7-88db-42bd-a132-7eef9aa68af4')"); } @@ -3334,7 +3334,7 @@ public override async Task Where_is_properly_lifted_from_subquery_created_by_inc AssertSql( @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' -END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] +END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Officers] AS [o] ON ([g].[Nickname] = [o].[Nickname]) AND ([g].[SquadId] = [o].[SquadId]) LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) @@ -3865,7 +3865,7 @@ public override async Task Optional_navigation_with_collection_composite_key(boo await base.Optional_navigation_with_collection_composite_key(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], CASE @@ -4185,7 +4185,7 @@ public override async Task Include_base_navigation_on_derived_entity(bool async) AssertSql( @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' -END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] +END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Gears] AS [g] LEFT JOIN [Officers] AS [o] ON ([g].[Nickname] = [o].[Nickname]) AND ([g].[SquadId] = [o].[SquadId]) LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId]) @@ -4198,7 +4198,7 @@ public override async Task ThenInclude_collection_on_derived_after_base_referenc await base.ThenInclude_collection_on_derived_after_base_reference(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE @@ -6541,7 +6541,7 @@ public override async Task Include_with_client_method_and_member_access_still_ap AssertSql( @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' -END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] +END AS [Discriminator], [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Gears] AS [g] LEFT JOIN [Officers] AS [o] ON ([g].[Nickname] = [o].[Nickname]) AND ([g].[SquadId] = [o].[SquadId]) LEFT JOIN [Tags] AS [t] ON ([g].[Nickname] = [t].[GearNickName]) AND ([g].[SquadId] = [t].[GearSquadId])"); @@ -6712,7 +6712,7 @@ public override async Task async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -6727,7 +6727,7 @@ public override async Task Filter_with_new_Guid(bool async) await base.Filter_with_new_Guid(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note] FROM [Tags] AS [t] WHERE [t].[Id] = 'df36f493-463f-4123-83f9-6b135deeb7ba'"); } @@ -7251,7 +7251,7 @@ public override async Task Reference_include_chain_loads_correctly_when_middle_i await base.Reference_include_chain_loads_correctly_when_middle_is_null(async); AssertSql( - @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] + @"SELECT [t].[Id], [t].[GearNickName], [t].[GearSquadId], [t].[IssueDate], [t].[Note], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs index c9957e49b4b..50b657dd703 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs @@ -88,5 +88,11 @@ public override async Task Let_let_contains_from_outer_let(bool async) SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Let_let_contains_from_outer_let(async))).Message); + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault(async))).Message); } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs index 692ae597743..a8beeb32908 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs @@ -68,5 +68,11 @@ public override async Task Let_let_contains_from_outer_let(bool async) SqliteStrings.ApplyNotSupported, (await Assert.ThrowsAsync( () => base.Let_let_contains_from_outer_let(async))).Message); + + public override async Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Complex_query_with_let_collection_projection_FirstOrDefault(async))).Message); } }