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: Snapshot selector shape correctly for better match #19835

Merged
merged 1 commit into from
Feb 7, 2020
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 @@ -1522,13 +1522,17 @@ private Expression SnapshotExpression(Expression selector)

case NewExpression newExpression:
{
var allDefault = true;
var arguments = new Expression[newExpression.Arguments.Count];
for (var i = 0; i < newExpression.Arguments.Count; i++)
{
arguments[i] = SnapshotExpression(newExpression.Arguments[i]);
allDefault &= arguments[i].NodeType == ExpressionType.Default;
}

return newExpression.Update(arguments);
return allDefault
? Expression.Default(newExpression.Type)
: (Expression)newExpression.Update(arguments);
}

case OwnedNavigationReference ownedNavigationReference:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,27 @@ public virtual Task GroupBy_scalar_subquery(bool async)
elementSorter: e => e.Key);
}



[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_scalar_aggregate_in_set_operation(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>()
.Where(c => c.CustomerID.StartsWith("F"))
.Select(c => new { c.CustomerID, Sequence = 0 })
.Union(ss.Set<Order>()
.GroupBy(o => o.CustomerID)
.Select(g => new
{
CustomerID = g.Key,
Sequence = 1
})),
elementSorter: e => e.CustomerID);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,20 @@ public override async Task GroupBy_scalar_subquery(bool async)
AssertSql(" ");
}

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

AssertSql(
@"SELECT [c].[CustomerID], 0 AS [Sequence]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] LIKE N'F%'
UNION
SELECT [o].[CustomerID], 1 AS [Sequence]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down