Skip to content

Commit 6e0d5d0

Browse files
committed
Merge in 'release/7.0' changes
2 parents 1178792 + edeb38f commit 6e0d5d0

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public sealed partial class SelectExpression : TableExpressionBase
2626
{
2727
private const string DiscriminatorColumnAlias = "Discriminator";
2828
private const string SqlQuerySingleColumnAlias = "Value";
29+
30+
private static readonly bool UseOldBehavior30273
31+
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue30273", out var enabled30273) && enabled30273;
32+
2933
private static readonly IdentifierComparer IdentifierComparerInstance = new();
3034

3135
private static readonly Dictionary<ExpressionType, ExpressionType> MirroredOperationMap =
@@ -3961,6 +3965,14 @@ private SelectExpression Prune(IReadOnlyCollection<string>? referencedColumns)
39613965
}
39623966
else if (table is SetOperationBase { IsDistinct: false } setOperation)
39633967
{
3968+
if (!UseOldBehavior30273)
3969+
{
3970+
if (setOperation.Source1.IsDistinct
3971+
|| setOperation.Source2.IsDistinct)
3972+
{
3973+
continue;
3974+
}
3975+
}
39643976
#if DEBUG
39653977
setOperation.Source1.Prune(columnsMap[tableAlias], removedAliases);
39663978
setOperation.Source2.Prune(columnsMap[tableAlias], removedAliases);

test/EFCore.Specification.Tests/Query/NorthwindSetOperationsQueryTestBase.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,4 +877,51 @@ public virtual Task Union_on_entity_plus_other_column_with_correlated_collection
877877
AssertCollection(e.Orders, a.Orders);
878878
},
879879
entryCount: 11);
880+
881+
[ConditionalTheory]
882+
[MemberData(nameof(IsAsyncData))]
883+
public virtual Task Concat_with_pruning(bool async)
884+
=> AssertQuery(
885+
async,
886+
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
887+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("B")))
888+
.Select(x => x.City));
889+
890+
[ConditionalTheory]
891+
[MemberData(nameof(IsAsyncData))]
892+
public virtual Task Concat_with_distinct_on_one_source_and_pruning(bool async)
893+
=> AssertQuery(
894+
async,
895+
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
896+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("B")).Distinct())
897+
.Select(x => x.City));
898+
899+
[ConditionalTheory]
900+
[MemberData(nameof(IsAsyncData))]
901+
public virtual Task Concat_with_distinct_on_both_source_and_pruning(bool async)
902+
=> AssertQuery(
903+
async,
904+
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A")).Distinct()
905+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("B")).Distinct())
906+
.Select(x => x.City));
907+
908+
[ConditionalTheory]
909+
[MemberData(nameof(IsAsyncData))]
910+
public virtual Task Nested_concat_with_pruning(bool async)
911+
=> AssertQuery(
912+
async,
913+
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
914+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("B")))
915+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A")))
916+
.Select(x => x.City));
917+
918+
[ConditionalTheory]
919+
[MemberData(nameof(IsAsyncData))]
920+
public virtual Task Nested_concat_with_distinct_in_the_middle_and_pruning(bool async)
921+
=> AssertQuery(
922+
async,
923+
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
924+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("B")).Distinct())
925+
.Concat(ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("A")))
926+
.Select(x => x.City));
880927
}

test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,103 @@ public override async Task Include_Union_different_includes_throws(bool async)
13171317
AssertSql();
13181318
}
13191319

1320+
public override async Task Concat_with_pruning(bool async)
1321+
{
1322+
await base.Concat_with_pruning(async);
1323+
1324+
AssertSql(
1325+
"""
1326+
SELECT [c].[City]
1327+
FROM [Customers] AS [c]
1328+
WHERE [c].[CustomerID] LIKE N'A%'
1329+
UNION ALL
1330+
SELECT [c0].[City]
1331+
FROM [Customers] AS [c0]
1332+
WHERE [c0].[CustomerID] LIKE N'B%'
1333+
""");
1334+
}
1335+
1336+
public override async Task Concat_with_distinct_on_one_source_and_pruning(bool async)
1337+
{
1338+
await base.Concat_with_distinct_on_one_source_and_pruning(async);
1339+
1340+
AssertSql(
1341+
"""
1342+
SELECT [t].[City]
1343+
FROM (
1344+
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
1345+
FROM [Customers] AS [c]
1346+
WHERE [c].[CustomerID] LIKE N'A%'
1347+
UNION ALL
1348+
SELECT DISTINCT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region]
1349+
FROM [Customers] AS [c0]
1350+
WHERE [c0].[CustomerID] LIKE N'B%'
1351+
) AS [t]
1352+
""");
1353+
}
1354+
1355+
public override async Task Concat_with_distinct_on_both_source_and_pruning(bool async)
1356+
{
1357+
await base.Concat_with_distinct_on_both_source_and_pruning(async);
1358+
1359+
AssertSql(
1360+
"""
1361+
SELECT [t].[City]
1362+
FROM (
1363+
SELECT DISTINCT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
1364+
FROM [Customers] AS [c]
1365+
WHERE [c].[CustomerID] LIKE N'A%'
1366+
UNION ALL
1367+
SELECT DISTINCT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region]
1368+
FROM [Customers] AS [c0]
1369+
WHERE [c0].[CustomerID] LIKE N'B%'
1370+
) AS [t]
1371+
""");
1372+
}
1373+
1374+
public override async Task Nested_concat_with_pruning(bool async)
1375+
{
1376+
await base.Nested_concat_with_pruning(async);
1377+
1378+
AssertSql(
1379+
"""
1380+
SELECT [c].[City]
1381+
FROM [Customers] AS [c]
1382+
WHERE [c].[CustomerID] LIKE N'A%'
1383+
UNION ALL
1384+
SELECT [c0].[City]
1385+
FROM [Customers] AS [c0]
1386+
WHERE [c0].[CustomerID] LIKE N'B%'
1387+
UNION ALL
1388+
SELECT [c1].[City]
1389+
FROM [Customers] AS [c1]
1390+
WHERE [c1].[CustomerID] LIKE N'A%'
1391+
""");
1392+
}
1393+
1394+
public override async Task Nested_concat_with_distinct_in_the_middle_and_pruning(bool async)
1395+
{
1396+
await base.Nested_concat_with_distinct_in_the_middle_and_pruning(async);
1397+
1398+
AssertSql(
1399+
"""
1400+
SELECT [t].[City]
1401+
FROM (
1402+
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
1403+
FROM [Customers] AS [c]
1404+
WHERE [c].[CustomerID] LIKE N'A%'
1405+
UNION ALL
1406+
SELECT DISTINCT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region]
1407+
FROM [Customers] AS [c0]
1408+
WHERE [c0].[CustomerID] LIKE N'B%'
1409+
) AS [t]
1410+
UNION ALL
1411+
SELECT [c1].[City]
1412+
FROM [Customers] AS [c1]
1413+
WHERE [c1].[CustomerID] LIKE N'A%'
1414+
""");
1415+
}
1416+
13201417
public override async Task Client_eval_Union_FirstOrDefault(bool async)
13211418
{
13221419
// Client evaluation in projection. Issue #16243.

0 commit comments

Comments
 (0)