Skip to content

Commit

Permalink
Remove InMemoryLinqOperatorProvider
Browse files Browse the repository at this point in the history
Make UnwrapLambdaFromQuote internal
  • Loading branch information
AndriySvyryd committed Oct 29, 2019
1 parent f780a3a commit 7adfc58
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 561 deletions.
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

0 comments on commit 7adfc58

Please sign in to comment.