Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Add regression test for #21665 #26009

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2536,5 +2536,53 @@ from l2 in ss.Set<Level2>().Where(x => x.Level1_Required_Id == l1.Id * 2 || x.Na
AssertCollection(e.Collection, a.Collection);
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_query_issue_21665(bool async)
{
return AssertFirstOrDefault(
async,
ss => ss.Set<Level1>()
.OrderBy(l1 => l1.Name)
.Select(l1 => new
{
Level1 = l1,
Level2Name = l1.OneToOne_Optional_FK1.Name,
ChildCount = l1.OneToMany_Optional_Self1.Count,
Level2Count = l1.OneToMany_Optional1.Count(),
IsLevel2There = l1.OneToMany_Optional1.Any(l2 => l2.Id == 2),
Children = l1.OneToMany_Optional_Self1
.OrderBy(e => e.Name)
.Skip(1)
.Take(5)
.Select(lc1 => new
{
Level1 = lc1,
ChildCount = lc1.OneToMany_Optional_Self1.Count,
Level2Name = lc1.OneToOne_Optional_FK1.Name,
Level2Count = lc1.OneToMany_Optional1.Count(),
IsLevel2There = lc1.OneToMany_Optional1.Any(l2 => l2.Id == 2)
})
}),
e => e.Level1.Id == 2,
asserter: (e, a) =>
{
AssertEqual(e.Level1, a.Level1);
AssertEqual(e.Level2Name, a.Level2Name);
AssertEqual(e.ChildCount, a.ChildCount);
AssertEqual(e.Level2Count, a.Level2Count);
AssertEqual(e.IsLevel2There, a.IsLevel2There);
AssertCollection(e.Children, a.Children, ordered: true,
elementAsserter: (ee, aa) =>
{
AssertEqual(ee.Level1, aa.Level1);
AssertEqual(ee.Level2Name, aa.Level2Name);
AssertEqual(ee.ChildCount, aa.ChildCount);
AssertEqual(ee.Level2Count, aa.Level2Count);
AssertEqual(ee.IsLevel2There, aa.IsLevel2There);
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ public override Task Required_navigation_with_Include_ThenInclude(bool async)
// Navigations used are not mapped in shared type.
public override Task SelectMany_DefaultIfEmpty_multiple_times_with_joins_projecting_a_collection(bool async)
=> Task.CompletedTask;

public override Task Complex_query_issue_21665(bool async) => Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,57 @@ FROM [LevelTwo] AS [l0]
ORDER BY [l].[Id], [t].[Id]");
}

public override async Task Complex_query_issue_21665(bool async)
{
await base.Complex_query_issue_21665(async);

AssertSql(
@"SELECT [t].[Id], [t].[Date], [t].[Name], [t].[OneToMany_Optional_Self_Inverse1Id], [t].[OneToMany_Required_Self_Inverse1Id], [t].[OneToOne_Optional_Self1Id], [t].[Name0], [t].[c], [t].[c0], [t].[c1], [t].[Id0], [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[ChildCount], [t0].[Level2Name], [t0].[Level2Count], [t0].[IsLevel2There], [t0].[Id0]
FROM (
SELECT TOP(1) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Name] AS [Name0], (
SELECT COUNT(*)
FROM [LevelOne] AS [l1]
WHERE [l].[Id] = [l1].[OneToMany_Optional_Self_Inverse1Id]) AS [c], (
SELECT COUNT(*)
FROM [LevelTwo] AS [l2]
WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AS [c0], CASE
WHEN EXISTS (
SELECT 1
FROM [LevelTwo] AS [l3]
WHERE ([l].[Id] = [l3].[OneToMany_Optional_Inverse2Id]) AND ([l3].[Id] = 2)) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [c1], [l0].[Id] AS [Id0]
FROM [LevelOne] AS [l]
LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id]
WHERE [l].[Id] = 2
ORDER BY [l].[Name]
) AS [t]
OUTER APPLY (
SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], (
SELECT COUNT(*)
FROM [LevelOne] AS [l5]
WHERE [t1].[Id] = [l5].[OneToMany_Optional_Self_Inverse1Id]) AS [ChildCount], [l4].[Name] AS [Level2Name], (
SELECT COUNT(*)
FROM [LevelTwo] AS [l6]
WHERE [t1].[Id] = [l6].[OneToMany_Optional_Inverse2Id]) AS [Level2Count], CASE
WHEN EXISTS (
SELECT 1
FROM [LevelTwo] AS [l7]
WHERE ([t1].[Id] = [l7].[OneToMany_Optional_Inverse2Id]) AND ([l7].[Id] = 2)) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [IsLevel2There], [l4].[Id] AS [Id0]
FROM (
SELECT [l8].[Id], [l8].[Date], [l8].[Name], [l8].[OneToMany_Optional_Self_Inverse1Id], [l8].[OneToMany_Required_Self_Inverse1Id], [l8].[OneToOne_Optional_Self1Id]
FROM [LevelOne] AS [l8]
WHERE [t].[Id] = [l8].[OneToMany_Optional_Self_Inverse1Id]
ORDER BY [l8].[Name]
OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY
) AS [t1]
LEFT JOIN [LevelTwo] AS [l4] ON [t1].[Id] = [l4].[Level1_Optional_Id]
) AS [t0]
ORDER BY [t].[Name], [t].[Id], [t].[Id0], [t0].[Name], [t0].[Id]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,63 @@ FROM [LevelTwo] AS [l0]
ORDER BY [l].[Id], [t].[Id]");
}

public override async Task Complex_query_issue_21665(bool async)
{
await base.Complex_query_issue_21665(async);

AssertSql(
@"SELECT TOP(1) [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Name], (
SELECT COUNT(*)
FROM [LevelOne] AS [l1]
WHERE [l].[Id] = [l1].[OneToMany_Optional_Self_Inverse1Id]), (
SELECT COUNT(*)
FROM [LevelTwo] AS [l2]
WHERE [l].[Id] = [l2].[OneToMany_Optional_Inverse2Id]), CASE
WHEN EXISTS (
SELECT 1
FROM [LevelTwo] AS [l3]
WHERE ([l].[Id] = [l3].[OneToMany_Optional_Inverse2Id]) AND ([l3].[Id] = 2)) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END, [l0].[Id]
FROM [LevelOne] AS [l]
LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id]
WHERE [l].[Id] = 2
ORDER BY [l].[Name], [l].[Id], [l0].[Id]",
//
@"SELECT [t0].[Id], [t0].[Date], [t0].[Name], [t0].[OneToMany_Optional_Self_Inverse1Id], [t0].[OneToMany_Required_Self_Inverse1Id], [t0].[OneToOne_Optional_Self1Id], [t0].[ChildCount], [t0].[Level2Name], [t0].[Level2Count], [t0].[IsLevel2There], [t].[Id], [t].[Id0]
FROM (
SELECT TOP(1) [l].[Id], [l0].[Id] AS [Id0], [l].[Name]
FROM [LevelOne] AS [l]
LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id]
WHERE [l].[Id] = 2
ORDER BY [l].[Name]
) AS [t]
CROSS APPLY (
SELECT [t1].[Id], [t1].[Date], [t1].[Name], [t1].[OneToMany_Optional_Self_Inverse1Id], [t1].[OneToMany_Required_Self_Inverse1Id], [t1].[OneToOne_Optional_Self1Id], (
SELECT COUNT(*)
FROM [LevelOne] AS [l2]
WHERE [t1].[Id] = [l2].[OneToMany_Optional_Self_Inverse1Id]) AS [ChildCount], [l1].[Name] AS [Level2Name], (
SELECT COUNT(*)
FROM [LevelTwo] AS [l3]
WHERE [t1].[Id] = [l3].[OneToMany_Optional_Inverse2Id]) AS [Level2Count], CASE
WHEN EXISTS (
SELECT 1
FROM [LevelTwo] AS [l4]
WHERE ([t1].[Id] = [l4].[OneToMany_Optional_Inverse2Id]) AND ([l4].[Id] = 2)) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [IsLevel2There]
FROM (
SELECT [l5].[Id], [l5].[Date], [l5].[Name], [l5].[OneToMany_Optional_Self_Inverse1Id], [l5].[OneToMany_Required_Self_Inverse1Id], [l5].[OneToOne_Optional_Self1Id]
FROM [LevelOne] AS [l5]
WHERE [t].[Id] = [l5].[OneToMany_Optional_Self_Inverse1Id]
ORDER BY [l5].[Name]
OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY
) AS [t1]
LEFT JOIN [LevelTwo] AS [l1] ON [t1].[Id] = [l1].[Level1_Optional_Id]
) AS [t0]
ORDER BY [t].[Name], [t].[Id], [t].[Id0], [t0].[Name]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,11 @@ public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecti
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))).Message);

public override async Task Complex_query_issue_21665(bool async)
=> Assert.Equal(
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Complex_query_issue_21665(async))).Message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,11 @@ public override async Task SelectMany_with_predicate_and_DefaultIfEmpty_projecti
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.SelectMany_with_predicate_and_DefaultIfEmpty_projecting_root_collection_element_and_another_collection(async))).Message);

public override async Task Complex_query_issue_21665(bool async)
=> Assert.Equal(
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Complex_query_issue_21665(async))).Message);
}
}