Exemple #1
0
        private Expression ExtractQueryMetadata(MethodCallExpression methodCallExpression)
        {
            // We visit innerQueryable first so that we can get information in the same order operators are applied.
            var genericMethodDefinition = methodCallExpression.Method.GetGenericMethodDefinition();

            if (genericMethodDefinition == EntityFrameworkQueryableExtensions.AsTrackingMethodInfo ||
                genericMethodDefinition == EntityFrameworkQueryableExtensions.AsNoTrackingMethodInfo)
            {
                var visitedExpression = Visit(methodCallExpression.Arguments[0]);
                _queryCompilationContext.IsTracking
                    = genericMethodDefinition == EntityFrameworkQueryableExtensions.AsTrackingMethodInfo;

                return(visitedExpression);
            }

            if (genericMethodDefinition == EntityFrameworkQueryableExtensions.TagWithMethodInfo)
            {
                var visitedExpression = Visit(methodCallExpression.Arguments[0]);
                _queryCompilationContext.AddTag((string)((ConstantExpression)methodCallExpression.Arguments[1]).Value);

                return(visitedExpression);
            }

            if (genericMethodDefinition == EntityFrameworkQueryableExtensions.IgnoreQueryFiltersMethodInfo)
            {
                var visitedExpression = Visit(methodCallExpression.Arguments[0]);
                _queryCompilationContext.IgnoreQueryFilters = true;

                return(visitedExpression);
            }

            return(null);
        }
Exemple #2
0
        protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
        {
            var method = methodCallExpression.Method;

            if (method.DeclaringType == typeof(EntityFrameworkQueryableExtensions) &&
                method.IsGenericMethod)
            {
                // We visit innerQueryable first so that we can get information in the same order operators are applied.
                var genericMethodDefinition = method.GetGenericMethodDefinition();
                if (genericMethodDefinition == EntityFrameworkQueryableExtensions.AsTrackingMethodInfo ||
                    genericMethodDefinition == EntityFrameworkQueryableExtensions.AsNoTrackingMethodInfo)
                {
                    var innerQueryable = Visit(methodCallExpression.Arguments[0]);
                    _queryCompilationContext.IsTracking
                        = genericMethodDefinition == EntityFrameworkQueryableExtensions.AsTrackingMethodInfo;

                    return(innerQueryable);
                }

                if (genericMethodDefinition == EntityFrameworkQueryableExtensions.TagWithMethodInfo)
                {
                    var innerQueryable = Visit(methodCallExpression.Arguments[0]);
                    _queryCompilationContext.AddTag((string)((ConstantExpression)methodCallExpression.Arguments[1]).Value);

                    return(innerQueryable);
                }
            }

            return(base.VisitMethodCall(methodCallExpression));
        }