Skip to content

Commit

Permalink
Public API changes to QueryMethodProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Aug 15, 2019
1 parent 2271170 commit 9186d45
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
// Unwrap AsQueryable around the subquery if present
if (subquery is MethodCallExpression innerMethodCall
&& innerMethodCall.Method.IsGenericMethod
&& innerMethodCall.Method.GetGenericMethodDefinition() == QueryableMethodProvider.AsQueryableMethodInfo)
&& innerMethodCall.Method.GetGenericMethodDefinition() == QueryableMethods.AsQueryable)
{
subquery = innerMethodCall.Arguments[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ protected override ShapedQueryExpression TranslateSelectMany(
var defaultIfEmpty = false;
if (collectionSelector.Body is MethodCallExpression collectionEndingMethod
&& collectionEndingMethod.Method.IsGenericMethod
&& collectionEndingMethod.Method.GetGenericMethodDefinition() == QueryableMethodProvider.DefaultIfEmptyWithoutArgumentMethodInfo)
&& collectionEndingMethod.Method.GetGenericMethodDefinition() == QueryableMethods.DefaultIfEmptyWithoutArgument)
{
defaultIfEmpty = true;
collectionSelector = Expression.Lambda(collectionEndingMethod.Arguments[0], collectionSelector.Parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (subquery.Tables.Count == 0
&& methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.GetGenericMethodDefinition() is MethodInfo genericMethod
&& (genericMethod == QueryableMethodProvider.AnyWithoutPredicateMethodInfo
|| genericMethod == QueryableMethodProvider.AnyWithPredicateMethodInfo
|| genericMethod == QueryableMethodProvider.AllMethodInfo
|| genericMethod == QueryableMethodProvider.ContainsMethodInfo))
&& (genericMethod == QueryableMethods.AnyWithoutPredicate
|| genericMethod == QueryableMethods.AnyWithPredicate
|| genericMethod == QueryableMethods.All
|| genericMethod == QueryableMethods.Contains))
{
return subquery.Projection[0].Expression;
}
Expand Down
128 changes: 64 additions & 64 deletions src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -239,43 +239,43 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
{
// These are methods that require special handling
case nameof(Queryable.Contains)
when genericMethod == QueryableMethodProvider.ContainsMethodInfo:
when genericMethod == QueryableMethods.Contains:
return VisitContainsMethodCall(methodCallExpression);

case nameof(Queryable.OrderBy)
when genericMethod == QueryableMethodProvider.OrderByMethodInfo:
when genericMethod == QueryableMethods.OrderBy:
case nameof(Queryable.OrderByDescending)
when genericMethod == QueryableMethodProvider.OrderByDescendingMethodInfo:
when genericMethod == QueryableMethods.OrderByDescending:
case nameof(Queryable.ThenBy)
when genericMethod == QueryableMethodProvider.ThenByMethodInfo:
case nameof(Queryable.ThenByDescending) when genericMethod == QueryableMethodProvider.ThenByDescendingMethodInfo:
when genericMethod == QueryableMethods.ThenBy:
case nameof(Queryable.ThenByDescending) when genericMethod == QueryableMethods.ThenByDescending:
return VisitOrderingMethodCall(methodCallExpression);

// The following are projecting methods, which flow the entity type from *within* the lambda outside.
case nameof(Queryable.Select)
when genericMethod == QueryableMethodProvider.SelectMethodInfo:
when genericMethod == QueryableMethods.Select:
case nameof(Queryable.SelectMany)
when genericMethod == QueryableMethodProvider.SelectManyWithoutCollectionSelectorMethodInfo
|| genericMethod == QueryableMethodProvider.SelectManyWithCollectionSelectorMethodInfo:
when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector
|| genericMethod == QueryableMethods.SelectManyWithCollectionSelector:
return VisitSelectMethodCall(methodCallExpression);

case nameof(Queryable.GroupJoin)
when genericMethod == QueryableMethodProvider.GroupJoinMethodInfo:
when genericMethod == QueryableMethods.GroupJoin:
case nameof(Queryable.Join)
when genericMethod == QueryableMethodProvider.JoinMethodInfo:
when genericMethod == QueryableMethods.Join:
case nameof(QueryableExtensions.LeftJoin)
when genericMethod == QueryableExtensions.LeftJoinMethodInfo:
return VisitJoinMethodCall(methodCallExpression);

case nameof(Queryable.OfType)
when genericMethod == QueryableMethodProvider.OfTypeMethodInfo:
when genericMethod == QueryableMethods.OfType:
return VisitOfType(methodCallExpression);

case nameof(Queryable.GroupBy)
when genericMethod == QueryableMethodProvider.GroupByWithKeySelectorMethodInfo
|| genericMethod == QueryableMethodProvider.GroupByWithKeyElementSelectorMethodInfo
|| genericMethod == QueryableMethodProvider.GroupByWithKeyResultSelectorMethodInfo
|| genericMethod == QueryableMethodProvider.GroupByWithKeyElementResultSelectorMethodInfo:
when genericMethod == QueryableMethods.GroupByWithKeySelector
|| genericMethod == QueryableMethods.GroupByWithKeyElementSelector
|| genericMethod == QueryableMethods.GroupByWithKeyResultSelector
|| genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector:
break; // TODO: Implement
}

Expand Down Expand Up @@ -425,7 +425,7 @@ protected virtual Expression VisitContainsMethodCall(MethodCallExpression method
var param = Expression.Parameter(entityType.ClrType, "v");
var keySelector = Expression.Lambda(CreatePropertyAccessExpression(param, keyProperty), param);
rewrittenSource = Expression.Call(
QueryableMethodProvider.SelectMethodInfo.MakeGenericMethod(entityType.ClrType, keyProperty.ClrType.MakeNullable()),
QueryableMethods.Select.MakeGenericMethod(entityType.ClrType, keyProperty.ClrType.MakeNullable()),
Unwrap(newSource),
Expression.Quote(keySelector));
}
Expand All @@ -437,7 +437,7 @@ protected virtual Expression VisitContainsMethodCall(MethodCallExpression method

return Expression.Call(
(Unwrap(newSource).Type.IsQueryableType()
? QueryableMethodProvider.ContainsMethodInfo
? QueryableMethods.Contains
: _enumerableContainsMethodInfo).MakeGenericMethod(keyProperty.ClrType.MakeNullable()),
rewrittenSource,
rewrittenItem
Expand Down Expand Up @@ -469,11 +469,11 @@ protected virtual Expression VisitOrderingMethodCall(MethodCallExpression method

var genericMethodDefinition = methodCallExpression.Method.GetGenericMethodDefinition();
var firstOrdering =
genericMethodDefinition == QueryableMethodProvider.OrderByMethodInfo
|| genericMethodDefinition == QueryableMethodProvider.OrderByDescendingMethodInfo;
genericMethodDefinition == QueryableMethods.OrderBy
|| genericMethodDefinition == QueryableMethods.OrderByDescending;
var isAscending =
genericMethodDefinition == QueryableMethodProvider.OrderByMethodInfo
|| genericMethodDefinition == QueryableMethodProvider.ThenByMethodInfo;
genericMethodDefinition == QueryableMethods.OrderBy
|| genericMethodDefinition == QueryableMethods.ThenBy;

var keyProperties = entityType.FindPrimaryKey()?.Properties;
if (keyProperties == null)
Expand Down Expand Up @@ -513,12 +513,12 @@ static MethodInfo GetOrderingMethodInfo(bool firstOrdering, bool ascending)
if (firstOrdering)
{
return ascending
? QueryableMethodProvider.OrderByMethodInfo
: QueryableMethodProvider.OrderByDescendingMethodInfo;
? QueryableMethods.OrderBy
: QueryableMethods.OrderByDescending;
}
return ascending
? QueryableMethodProvider.ThenByMethodInfo
: QueryableMethodProvider.ThenByDescendingMethodInfo;
? QueryableMethods.ThenBy
: QueryableMethods.ThenByDescending;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (arguments[i].Type.TryGetElementType(typeof(IQueryable<>)) == null)
{
arguments[i] = Expression.Call(
QueryableMethodProvider.AsQueryableMethodInfo.MakeGenericMethod(
QueryableMethods.AsQueryable.MakeGenericMethod(
arguments[i].Type.TryGetSequenceType()),
arguments[i]);
}
Expand Down Expand Up @@ -145,9 +145,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
var sourceType = methodCallExpression.Method.DeclaringType.GetGenericArguments()[0];

return Expression.Call(
QueryableMethodProvider.ContainsMethodInfo.MakeGenericMethod(sourceType),
QueryableMethods.Contains.MakeGenericMethod(sourceType),
Expression.Call(
QueryableMethodProvider.AsQueryableMethodInfo.MakeGenericMethod(sourceType),
QueryableMethods.AsQueryable.MakeGenericMethod(sourceType),
methodCallExpression.Object),
methodCallExpression.Arguments[0]);
}
Expand Down
22 changes: 11 additions & 11 deletions src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& methodCallExpression.Method.IsGenericMethod)
{
var genericMethod = methodCallExpression.Method.GetGenericMethodDefinition();
if (genericMethod == QueryableMethodProvider.SelectManyWithCollectionSelectorMethodInfo)
if (genericMethod == QueryableMethods.SelectManyWithCollectionSelector)
{
// SelectMany
var selectManySource = methodCallExpression.Arguments[0];
if (selectManySource is MethodCallExpression groupJoinMethod
&& groupJoinMethod.Method.IsGenericMethod
&& groupJoinMethod.Method.GetGenericMethodDefinition() == QueryableMethodProvider.GroupJoinMethodInfo)
&& groupJoinMethod.Method.GetGenericMethodDefinition() == QueryableMethods.GroupJoin)
{
// GroupJoin
var outer = Visit(groupJoinMethod.Arguments[0]);
Expand All @@ -46,7 +46,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

if (collectionSelectorBody is MethodCallExpression collectionEndingMethod
&& collectionEndingMethod.Method.IsGenericMethod
&& collectionEndingMethod.Method.GetGenericMethodDefinition() == QueryableMethodProvider.DefaultIfEmptyWithoutArgumentMethodInfo)
&& collectionEndingMethod.Method.GetGenericMethodDefinition() == QueryableMethods.DefaultIfEmptyWithoutArgument)
{
defaultIfEmpty = true;
collectionSelectorBody = collectionEndingMethod.Arguments[0];
Expand All @@ -70,7 +70,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
innerKeySelector.Body);

inner = Expression.Call(
QueryableMethodProvider.WhereMethodInfo.MakeGenericMethod(inner.Type.TryGetSequenceType()),
QueryableMethods.Where.MakeGenericMethod(inner.Type.TryGetSequenceType()),
inner,
Expression.Quote(Expression.Lambda(correlationPredicate, innerParameter)));

Expand All @@ -91,7 +91,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

if (inner is MethodCallExpression innerMethodCall
&& innerMethodCall.Method.IsGenericMethod
&& innerMethodCall.Method.GetGenericMethodDefinition() == QueryableMethodProvider.AsQueryableMethodInfo
&& innerMethodCall.Method.GetGenericMethodDefinition() == QueryableMethods.AsQueryable
&& innerMethodCall.Type == innerMethodCall.Arguments[0].Type)
{
// Remove redundant AsQueryable.
Expand Down Expand Up @@ -136,7 +136,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
{
// inner join
return Expression.Call(
QueryableMethodProvider.JoinMethodInfo.MakeGenericMethod(
QueryableMethods.Join.MakeGenericMethod(
outer.Type.TryGetSequenceType(),
inner.Type.TryGetSequenceType(),
outerKeySelector.ReturnType,
Expand All @@ -150,13 +150,13 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}
}
}
else if (genericMethod == QueryableMethodProvider.SelectManyWithoutCollectionSelectorMethodInfo)
else if (genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector)
{
// SelectMany
var selectManySource = methodCallExpression.Arguments[0];
if (selectManySource is MethodCallExpression groupJoinMethod
&& groupJoinMethod.Method.IsGenericMethod
&& groupJoinMethod.Method.GetGenericMethodDefinition() == QueryableMethodProvider.GroupJoinMethodInfo)
&& groupJoinMethod.Method.GetGenericMethodDefinition() == QueryableMethods.GroupJoin)
{
// GroupJoin
var outer = Visit(groupJoinMethod.Arguments[0]);
Expand All @@ -172,7 +172,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

if (groupJoinResultSelectorBody is MethodCallExpression collectionEndingMethod
&& collectionEndingMethod.Method.IsGenericMethod
&& collectionEndingMethod.Method.GetGenericMethodDefinition() == QueryableMethodProvider.DefaultIfEmptyWithoutArgumentMethodInfo)
&& collectionEndingMethod.Method.GetGenericMethodDefinition() == QueryableMethods.DefaultIfEmptyWithoutArgument)
{
defaultIfEmpty = true;
groupJoinResultSelectorBody = collectionEndingMethod.Arguments[0];
Expand Down Expand Up @@ -242,7 +242,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
{
// inner join
return Expression.Call(
QueryableMethodProvider.JoinMethodInfo.MakeGenericMethod(
QueryableMethods.Join.MakeGenericMethod(
outer.Type.TryGetSequenceType(),
inner.Type.TryGetSequenceType(),
outerKeySelector.ReturnType,
Expand Down Expand Up @@ -346,7 +346,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& !_allowedMethods.Contains(methodCallExpression.Method.Name))
{
if (methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.GetGenericMethodDefinition() == QueryableMethodProvider.SelectMethodInfo)
&& methodCallExpression.Method.GetGenericMethodDefinition() == QueryableMethods.Select)
{
var selector = methodCallExpression.Arguments[1].UnwrapLambdaFromQuote();
if (selector.Body == selector.Parameters[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected Expression ExpandNavigation(
{
var elementType = ownedExpansion.Type.TryGetSequenceType();
var subquery = Expression.Call(
QueryableMethodProvider.AsQueryableMethodInfo.MakeGenericMethod(elementType),
QueryableMethods.AsQueryable.MakeGenericMethod(elementType),
ownedExpansion);

return new MaterializeCollectionNavigationExpression(subquery, navigation);
Expand Down Expand Up @@ -220,7 +220,7 @@ protected Expression ExpandNavigation(
// This is intentionally deferred to be applied to innerSource.Source
// Since outerKey's reference could change if a reference navigation is expanded afterwards
var subquery = Expression.Call(
QueryableMethodProvider.WhereMethodInfo.MakeGenericMethod(innerSoureSequenceType),
QueryableMethods.Where.MakeGenericMethod(innerSoureSequenceType),
innerSource,
Expression.Quote(
Expression.Lambda(
Expand Down Expand Up @@ -264,7 +264,7 @@ protected Expression ExpandNavigation(

_source.UpdateSource(Expression.Call(
(innerJoin
? QueryableMethodProvider.JoinMethodInfo
? QueryableMethods.Join
: QueryableExtensions.LeftJoinMethodInfo).MakeGenericMethod(
_source.SourceElementType,
innerSource.SourceElementType,
Expand Down Expand Up @@ -563,7 +563,7 @@ public override Expression Visit(Expression expression)
var selectorLambda = Expression.Lambda(pendingSelector, navigationExpansionExpression.CurrentParameter);

result = Expression.Call(
QueryableMethodProvider.SelectMethodInfo.MakeGenericMethod(
QueryableMethods.Select.MakeGenericMethod(
navigationExpansionExpression.SourceElementType,
selectorLambda.ReturnType),
source,
Expand Down
Loading

0 comments on commit 9186d45

Please sign in to comment.