Skip to content

Commit

Permalink
Count > 0 normalized to .Any should also work on ICollection
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJollyAU committed Dec 23, 2024
1 parent f163289 commit 6b71256
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
},
Right: ConstantExpression { Value: 0 }
}
when (member.DeclaringType.GetGenericTypeDefinition().GetInterfaces().Any(
when (member.DeclaringType.GetGenericTypeDefinition() == typeof(ICollection<>) || member.DeclaringType.GetGenericTypeDefinition().GetInterfaces().Any(
x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>)))
=> VisitMethodCall(
Expression.Call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,10 @@ public override async Task Where_navigation_property_to_collection(bool async)
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(*)
WHERE EXISTS (
SELECT 1
FROM [LevelThree] AS [l1]
WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id]) > 0
WHERE [l0].[Id] IS NOT NULL AND [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id])
""");
}

Expand All @@ -1385,10 +1385,10 @@ public override async Task Where_navigation_property_to_collection2(bool async)
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(*)
WHERE EXISTS (
SELECT 1
FROM [LevelThree] AS [l1]
WHERE [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id]) > 0
WHERE [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5031,7 +5031,7 @@ 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 (
Expand All @@ -5057,16 +5057,16 @@ WHERE [l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id]
) 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(*)
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 EXISTS (
SELECT 1
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
END IS NULL AND [l6].[OneToMany_Optional_Inverse3Id] IS NULL)))
""");
}

Expand Down Expand Up @@ -6257,16 +6257,16 @@ LEFT JOIN (
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(*)
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_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
END IS NULL AND [l2].[OneToMany_Optional_Inverse3Id] IS NULL)))
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name]
FROM [EntityOnes] AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name]
FROM [EntityOnes] AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ LEFT JOIN (
FROM [Order] AS [o1]
LEFT JOIN [OrderDetail] AS [o2] ON [o1].[ClientId] = [o2].[OrderClientId] AND [o1].[Id] = [o2].[OrderId]
) AS [s] ON [o].[Id] = [s].[ClientId]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [Order] AS [o0]
WHERE [o].[Id] = [o0].[ClientId]) > 0
WHERE [o].[Id] = [o0].[ClientId])
ORDER BY [o].[Id], [s].[ClientId], [s].[Id], [s].[OrderClientId], [s].[OrderId]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name]
FROM [EntityOnes] AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down Expand Up @@ -2178,11 +2178,11 @@ public override async Task Skip_navigation_count_without_predicate_unidirectiona
"""
SELECT [u].[Id], [u].[Name]
FROM [UnidirectionalEntityOnes] AS [u]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [UnidirectionalJoinOneSelfPayload] AS [u0]
INNER JOIN [UnidirectionalEntityOnes] AS [u1] ON [u0].[LeftId] = [u1].[Id]
WHERE [u].[Id] = [u0].[RightId]) > 0
WHERE [u].[Id] = [u0].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name]
FROM [EntityOnes] AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down Expand Up @@ -2179,11 +2179,11 @@ public override async Task Skip_navigation_count_without_predicate_unidirectiona
"""
SELECT [u].[Id], [u].[Name]
FROM [UnidirectionalEntityOnes] AS [u]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [UnidirectionalJoinOneSelfPayload] AS [u0]
INNER JOIN [UnidirectionalEntityOnes] AS [u1] ON [u0].[LeftId] = [u1].[Id]
WHERE [u].[Id] = [u0].[RightId]) > 0
WHERE [u].[Id] = [u0].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name]
FROM [EntityOnes] AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down Expand Up @@ -2127,11 +2127,11 @@ public override async Task Skip_navigation_count_without_predicate_unidirectiona
"""
SELECT [u].[Id], [u].[Name]
FROM [UnidirectionalEntityOnes] AS [u]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [UnidirectionalJoinOneSelfPayload] AS [u0]
INNER JOIN [UnidirectionalEntityOnes] AS [u1] ON [u0].[LeftId] = [u1].[Id]
WHERE [u].[Id] = [u0].[RightId]) > 0
WHERE [u].[Id] = [u0].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name]
FROM [EntityOnes] AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] AS [j]
INNER JOIN [EntityOnes] AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down Expand Up @@ -2127,11 +2127,11 @@ public override async Task Skip_navigation_count_without_predicate_unidirectiona
"""
SELECT [u].[Id], [u].[Name]
FROM [UnidirectionalEntityOnes] AS [u]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [UnidirectionalJoinOneSelfPayload] AS [u0]
INNER JOIN [UnidirectionalEntityOnes] AS [u1] ON [u0].[LeftId] = [u1].[Id]
WHERE [u].[Id] = [u0].[RightId]) > 0
WHERE [u].[Id] = [u0].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public override async Task Skip_navigation_count_without_predicate(bool async)
"""
SELECT [e].[Id], [e].[Name], [e].[PeriodEnd], [e].[PeriodStart]
FROM [EntityOnes] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [e]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [JoinOneSelfPayload] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [j]
INNER JOIN [EntityOnes] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [e0] ON [j].[LeftId] = [e0].[Id]
WHERE [e].[Id] = [j].[RightId]) > 0
WHERE [e].[Id] = [j].[RightId])
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ LEFT JOIN (
FROM [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o1]
LEFT JOIN [OrderDetail] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o2] ON [o1].[ClientId] = [o2].[OrderClientId] AND [o1].[Id] = [o2].[OrderId]
) AS [s] ON [o].[Id] = [s].[ClientId]
WHERE (
SELECT COUNT(*)
WHERE EXISTS (
SELECT 1
FROM [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0]
WHERE [o].[Id] = [o0].[ClientId]) > 0
WHERE [o].[Id] = [o0].[ClientId])
ORDER BY [o].[Id], [s].[ClientId], [s].[Id], [s].[OrderClientId], [s].[OrderId]
""");
}
Expand Down

0 comments on commit 6b71256

Please sign in to comment.