Skip to content

Commit

Permalink
Query: Update materialization marking for set operations
Browse files Browse the repository at this point in the history
Add test for set operation followed group by not translating correctly Issue #6658
  • Loading branch information
smitpatel committed Apr 18, 2017
1 parent eabc74e commit 5ca298f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
15 changes: 15 additions & 0 deletions src/EFCore.Specification.Tests/QueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6675,6 +6675,21 @@ public virtual void Union_simple()
entryCount: 19);
}

[ConditionalFact(Skip = "Unable to bind group by. See Issue#6658")]
public virtual void Union_simple_groupby()
{
AssertQuery<Customer>(
cs => cs.Where(s => s.ContactTitle == "Owner")
.Union(cs.Where(c => c.City == "México D.F."))
.GroupBy(c => c.City)
.Select(g => new
{
g.Key,
Total = g.Count()
}),
entryCount: 19);
}

[ConditionalFact]
public virtual void Union_nested()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -121,13 +123,14 @@ protected override Expression VisitMember(MemberExpression node)
}
else
{
_queryModelVisitor.BindMemberExpression(node, (property, querySource) =>
{
if (querySource != null)
{
DemoteQuerySource(querySource);
}
});
_queryModelVisitor.BindMemberExpression(
node, (property, querySource) =>
{
if (querySource != null)
{
DemoteQuerySource(querySource);
}
});
}
}

Expand All @@ -142,15 +145,16 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
{
var newExpression = (MethodCallExpression)base.VisitMethodCall(node);

_queryModelVisitor.BindMethodCallExpression(node, (property, querySource) =>
{
if (querySource != null)
{
DemoteQuerySource(querySource);
}
});
_queryModelVisitor.BindMethodCallExpression(
node, (property, querySource) =>
{
if (querySource != null)
{
DemoteQuerySource(querySource);
}
});

if (AnonymousObject.IsGetValueExpression(node , out QuerySourceReferenceExpression querySourceReferenceExpression))
if (AnonymousObject.IsGetValueExpression(node, out QuerySourceReferenceExpression querySourceReferenceExpression))
{
DemoteQuerySource(querySourceReferenceExpression.ReferencedQuerySource);
}
Expand Down Expand Up @@ -186,7 +190,7 @@ private Expression VisitBinaryOperand(Expression operand, ExpressionType compari
|| comparison == ExpressionType.NotEqual)
{
var isEntityTypeExpression = _model.FindEntityType(operand.Type) != null
|| _model.IsDelegatedIdentityEntityType(operand.Type);
|| _model.IsDelegatedIdentityEntityType(operand.Type);

if (isEntityTypeExpression)
{
Expand Down Expand Up @@ -238,21 +242,12 @@ protected override Expression VisitSubQuery(SubQueryExpression expression)
if (referencedQuerySource != null)
{
var parentQuerySource = parentQueryModel.SelectClause.Selector.TryGetReferencedQuerySource();
var resultSetOperators = GetSetResultOperatorSourceExpressions(parentQueryModel);

var parentQueryModelResultType
= parentQueryModel.ResultTypeOverride?.TryGetSequenceType()
?? ((CastResultOperator)parentQueryModel.ResultOperators.LastOrDefault(r => r is CastResultOperator))?.CastItemType
?? parentQuerySource?.ItemType;

if (parentQueryModelResultType?.GetTypeInfo().IsAssignableFrom(referencedQuerySource.ItemType.GetTypeInfo()) == true)
if (resultSetOperators.Any(r => r.Equals(expression))
&& _querySourceReferences[parentQuerySource] > 0)
{
var resultSetOperators = GetSetResultOperatorSourceExpressions(parentQueryModel);

if (resultSetOperators.Any(r => r.Equals(expression))
&& _querySourceReferences[parentQuerySource] > 0)
{
PromoteQuerySource(referencedQuerySource);
}
PromoteQuerySource(referencedQuerySource);
}
}

Expand Down Expand Up @@ -468,4 +463,4 @@ private static IEnumerable<Expression> GetSetResultOperatorSourceExpressions(Que
}
}
}
}
}

0 comments on commit 5ca298f

Please sign in to comment.