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

Remove InMemoryLinqOperatorProvider #18642

Merged
merged 1 commit into from
Oct 29, 2019
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 @@ -9,7 +9,6 @@
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -361,8 +360,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (_clientEval)
{
var method = methodCallExpression.Method;
if (method.DeclaringType == typeof(Queryable)
|| method.DeclaringType == typeof(QueryableExtensions))
if (method.DeclaringType == typeof(Queryable))
{
var genericMethod = method.IsGenericMethod ? method.GetGenericMethodDefinition() : null;
var visitedSource = Visit(methodCallExpression.Arguments[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Reflection;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -142,15 +141,10 @@ protected override Expression VisitMember(MemberExpression memberExpression)
return result;
}

static bool shouldApplyNullProtectionForMemberAccess(Type callerType, string memberName)
=> !(callerType.IsGenericType
&& callerType.GetGenericTypeDefinition() == typeof(Nullable<>)
&& (memberName == nameof(Nullable<int>.Value) || memberName == nameof(Nullable<int>.HasValue)));

var updatedMemberExpression = (Expression)memberExpression.Update(innerExpression);
if (innerExpression != null
&& innerExpression.Type.IsNullableType()
&& shouldApplyNullProtectionForMemberAccess(innerExpression.Type, memberExpression.Member.Name))
&& ShouldApplyNullProtectionForMemberAccess(innerExpression.Type, memberExpression.Member.Name))
{
updatedMemberExpression = ConvertToNullable(updatedMemberExpression);

Expand All @@ -161,6 +155,11 @@ static bool shouldApplyNullProtectionForMemberAccess(Type callerType, string mem
}

return updatedMemberExpression;

static bool ShouldApplyNullProtectionForMemberAccess(Type callerType, string memberName)
=> !(callerType.IsGenericType
&& callerType.GetGenericTypeDefinition() == typeof(Nullable<>)
&& (memberName == nameof(Nullable<int>.Value) || memberName == nameof(Nullable<int>.HasValue)));
}

private bool TryBindMember(Expression source, MemberIdentity memberIdentity, Type type, out Expression result)
Expand Down Expand Up @@ -327,10 +326,10 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
MethodInfo GetMethod()
=> methodName switch
{
nameof(Enumerable.Average) => InMemoryLinqOperatorProvider.GetAverageWithSelector(selector.ReturnType),
nameof(Enumerable.Max) => InMemoryLinqOperatorProvider.GetMaxWithSelector(selector.ReturnType),
nameof(Enumerable.Min) => InMemoryLinqOperatorProvider.GetMinWithSelector(selector.ReturnType),
nameof(Enumerable.Sum) => InMemoryLinqOperatorProvider.GetSumWithSelector(selector.ReturnType),
nameof(Enumerable.Average) => EnumerableMethods.GetAverageWithSelector(selector.ReturnType),
nameof(Enumerable.Max) => EnumerableMethods.GetMaxWithSelector(selector.ReturnType),
nameof(Enumerable.Min) => EnumerableMethods.GetMinWithSelector(selector.ReturnType),
nameof(Enumerable.Sum) => EnumerableMethods.GetSumWithSelector(selector.ReturnType),
_ => throw new InvalidOperationException("Invalid Aggregate Operator encountered."),
};
}
Expand All @@ -344,8 +343,8 @@ MethodInfo GetMethod()
{
return Expression.Call(
(countMethod
? InMemoryLinqOperatorProvider.CountWithoutPredicate
: InMemoryLinqOperatorProvider.LongCountWithoutPredicate)
? EnumerableMethods.CountWithoutPredicate
: EnumerableMethods.LongCountWithoutPredicate)
.MakeGenericMethod(typeof(ValueBuffer)),
groupByShaperExpression.GroupingParameter);
}
Expand All @@ -360,8 +359,8 @@ MethodInfo GetMethod()

return Expression.Call(
(countMethod
? InMemoryLinqOperatorProvider.CountWithPredicate
: InMemoryLinqOperatorProvider.LongCountWithPredicate)
? EnumerableMethods.CountWithPredicate
: EnumerableMethods.LongCountWithPredicate)
.MakeGenericMethod(typeof(ValueBuffer)),
groupByShaperExpression.GroupingParameter,
predicate);
Expand Down Expand Up @@ -473,7 +472,7 @@ MethodInfo GetMethod()
// we special-case Nullable<>.GetValueOrDefault, which doesn't need the safeguard
if (methodCallExpression.Object != null
&& @object.Type.IsNullableType()
&& !(methodCallExpression.Method.Name == nameof(Nullable<int>.GetValueOrDefault)))
&& methodCallExpression.Method.Name != nameof(Nullable<int>.GetValueOrDefault))
{
var result = (Expression)methodCallExpression.Update(
Expression.Convert(@object, methodCallExpression.Object.Type),
Expand Down Expand Up @@ -616,7 +615,6 @@ protected override Expression VisitExtension(Expression extensionExpression)
case NullConditionalExpression nullConditionalExpression:
{
var translation = Visit(nullConditionalExpression.AccessOperation);

return translation.Type == nullConditionalExpression.Type
? translation
: Expression.Convert(translation, nullConditionalExpression.Type);
Expand Down
Loading