protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            Expression body = _navigationPropertyPathLambda.Body;

            if (body.NodeType == ExpressionType.Convert)
            {
                body = ((UnaryExpression)body).Operand;
            }

            if (body.NodeType == ExpressionType.Extension)
            {
                var sub         = (SubQueryExpression)body;
                var whereClause = (WhereClause)sub.QueryModel.BodyClauses.First();
                body = sub.QueryModel.MainFromClause.FromExpression;

                var member = body as MemberExpression;
                if (member != null)
                {
                    var name = $"{member.Member.DeclaringType.FullName}-{member.Member.Name}";
                    _expressions.Add(name, new HashSet <Expression>(new[] { whereClause.Predicate }));
                }
            }

            var navigationPropertyPath = Resolve(_navigationPropertyPathLambda.Parameters[0], body, clauseGenerationContext) as MemberExpression;

            if (navigationPropertyPath == null)
            {
                throw new InvalidOperationException(CoreStrings.InvalidComplexPropertyExpression(_navigationPropertyPathLambda));
            }

            var includeResultOperator = new ReplaceIncludeResultOperator(navigationPropertyPath, _expressions);

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);
            return(includeResultOperator);
        }
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var resultOperator = new FetchOneRequest(RelationMember);

            clauseGenerationContext.AddContextInfo(this, resultOperator);
            return(resultOperator);
        }
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var resultOperator = CreateFetchRequest();

            // Store a mapping between this node and the resultOperator so that a later ThenFetch... node may add its request to the resultOperator.
            clauseGenerationContext.AddContextInfo(this, resultOperator);
            return(resultOperator);
        }
        public void GetResolvedResultSelector()
        {
            ClauseGenerationContext.AddContextInfo(_node, _joinClause);

            var resolvedExpression = _node.GetResolvedResultSelector(ClauseGenerationContext);

            var expectedExpression = ExpressionHelper.Resolve <string, string, string> (SourceClause, _joinClause, (o, i) => o.ToString() + i.ToString());

            ExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, resolvedExpression);
        }
        private MainFromClause CreateMainFromClause(ClauseGenerationContext clauseGenerationContext)
        {
            var fromClause = new MainFromClause(
                AssociatedIdentifier,
                QuerySourceElementType,
                ParsedExpression);

            clauseGenerationContext.AddContextInfo(this, fromClause);
            return(fromClause);
        }
Exemple #6
0
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            var queryAnnotationResultOperator
                = (QueryAnnotationResultOperator)clauseGenerationContext.GetContextInfo(Source);

            ((IncludeQueryAnnotation)queryAnnotationResultOperator.Annotation)
            .AppendToNavigationPath(_navigationPropertyPathLambda.GetComplexPropertyAccess());

            clauseGenerationContext.AddContextInfo(this, queryAnnotationResultOperator);
        }
Exemple #7
0
        public override void SetUp()
        {
            base.SetUp();

            _cookSource = new MainSourceExpressionNode("s", Expression.Constant(new[] { new Cook() }));
            _cookClause = ExpressionHelper.CreateMainFromClause <Cook> ();
            ClauseGenerationContext.AddContextInfo(_cookSource, _cookClause);

            _castToChefMethod = ReflectionUtility.GetMethod(() => ((IQueryable <Cook[]>)null).Cast <Chef>());
            _node             = new CastExpressionNode(CreateParseInfo(_cookSource, "s", _castToChefMethod));
        }
        protected override QueryModel ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            var includeResultOperator
                = (IncludeResultOperator)clauseGenerationContext.GetContextInfo(Source);

            includeResultOperator.AppendToNavigationPath(_navigationPropertyPathLambda.GetComplexPropertyAccess());

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);

            return(queryModel);
        }
        public void Resolve()
        {
            ClauseGenerationContext.AddContextInfo(_node, _joinClause);

            var parameter = Expression.Parameter(typeof(string), "s");
            var result    = _node.Resolve(parameter, parameter, ClauseGenerationContext);

            var expectedResult = ExpressionHelper.Resolve <string, string, string> (SourceClause, _joinClause, (o, i) => o.ToString() + i.ToString());

            ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
Exemple #10
0
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            Utils.CheckNotNull("queryModel", queryModel);

            var groupByClause = new GroupByClause(GetResolvedSelector(clauseGenerationContext), Selector, intoIdentifier);

            queryModel.BodyClauses.Add(groupByClause);

            clauseGenerationContext.AddContextInfo(this, groupByClause);

            queryModel.SelectClause.Selector = GetResolvedAdaptedSelector(clauseGenerationContext);
        }
Exemple #11
0
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            LinqUtility.CheckNotNull("queryModel", queryModel);

            var traversalClause = new TraversalClause(StartVertex, identifier);

            queryModel.BodyClauses.Add(traversalClause);

            clauseGenerationContext.AddContextInfo(this, traversalClause);

            //queryModel.SelectClause.Selector = GetResolvedAdaptedSelector(clauseGenerationContext);
        }
Exemple #12
0
        public override void SetUp()
        {
            base.SetUp();

            _sourceFetchRequest     = new TestFetchRequest(typeof(Cook).GetProperty("Substitution"));
            _sourceFetchRequestNode = new MainSourceExpressionNode("x", Expression.Constant(new Cook[0]));
            ClauseGenerationContext.AddContextInfo(_sourceFetchRequestNode, _sourceFetchRequest);

            QueryModel.ResultOperators.Add(_sourceFetchRequest);

            _node = new ThenFetchOneExpressionNode(CreateParseInfo(_sourceFetchRequestNode), ExpressionHelper.CreateLambdaExpression <Cook, Cook> (s => s.Substitution));
        }
        /// <summary>
        ///    Copy from EntityFramework Core source code. Modified to store predict expressions.
        /// </summary>
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            var includeResultOperator = (ReplaceIncludeResultOperator)clauseGenerationContext.GetContextInfo(Source);

            includeResultOperator.AppendToNavigationPath(GetComplexPropertyAccess(_navigationPropertyPathLambda));

            foreach (var expression in _expressions)
            {
                includeResultOperator.Expressions.Add(expression.Key, expression.Value);
            }

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override void ApplyNodeSpecificSemantics(
            QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            var includeResultOperator
                = (IncludeResultOperator)clauseGenerationContext.GetContextInfo(Source);

            includeResultOperator
            .AppendToNavigationPath(
                NavigationPropertyPathLambda.GetComplexPropertyAccess(
                    nameof(EntityFrameworkQueryableExtensions.ThenInclude)));

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);
        }
Exemple #15
0
        public void Resolve_ReplacesParameter_WithQuerySourceReference()
        {
            var expression = ExpressionHelper.CreateLambdaExpression <int, bool> (i => i > 5);
            var clause     = ExpressionHelper.CreateMainFromClause_Int();

            ClauseGenerationContext.AddContextInfo(_node, clause);

            var result = _node.Resolve(expression.Parameters[0], expression.Body, ClauseGenerationContext);

            var expectedResult = Expression.MakeBinary(ExpressionType.GreaterThan, new QuerySourceReferenceExpression(clause), Expression.Constant(5));

            ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
        public void Resolve()
        {
            var querySource = ExpressionHelper.CreateConcatResultOperator();

            ClauseGenerationContext.AddContextInfo(_node, querySource);

            var lambdaExpression = ExpressionHelper.CreateLambdaExpression <int, string> (u => u.ToString());

            var result = _node.Resolve(lambdaExpression.Parameters[0], lambdaExpression.Body, ClauseGenerationContext);

            var expectedResult = ExpressionHelper.Resolve <int, string> (querySource, u => u.ToString());

            ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
Exemple #17
0
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var navigationPropertyPath
                = Source.Resolve(
                      _navigationPropertyPathLambda.Parameters[0],
                      _navigationPropertyPathLambda.Body,
                      clauseGenerationContext);

            var includeResultOperator = new IncludeResultOperator(navigationPropertyPath);

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);

            return(includeResultOperator);
        }
Exemple #18
0
        public void Resolve()
        {
            var querySource = ExpressionHelper.CreateGroupResultOperator();

            ClauseGenerationContext.AddContextInfo(_nodeWithoutElementSelector, querySource);

            var lambdaExpression =
                ExpressionHelper.CreateLambdaExpression <IGrouping <string, string>, Tuple <string, int> > (g => Tuple.Create(g.Key, g.Count()));

            var result = _nodeWithoutElementSelector.Resolve(lambdaExpression.Parameters[0], lambdaExpression.Body, ClauseGenerationContext);

            var expectedResult = ExpressionHelper.Resolve <IGrouping <string, string>, Tuple <string, int> > (querySource, g => Tuple.Create(g.Key, g.Count()));

            ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
        protected override QueryModel ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            var previousFetchRequest = clauseGenerationContext.GetContextInfo(Source) as FetchRequestBase;

            if (previousFetchRequest == null)
            {
                throw new ParserException("ThenFetchMany must directly follow another Fetch request.");
            }

            FetchRequestBase innerFetchRequest = new FetchManyRequest(RelationMember);

            innerFetchRequest = previousFetchRequest.GetOrAddInnerFetchRequest(innerFetchRequest);
            clauseGenerationContext.AddContextInfo(this, innerFetchRequest);

            return(queryModel);
        }
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var navigationPropertyPath
                = Source.Resolve(
                      _navigationPropertyPathLambda.Parameters[0],
                      _navigationPropertyPathLambda.Body,
                      clauseGenerationContext);

            var queryAnnotationResultOperator = new QueryAnnotationResultOperator(
                Expression.Constant(
                    new IncludeQueryAnnotation(navigationPropertyPath)));

            clauseGenerationContext.AddContextInfo(this, queryAnnotationResultOperator);

            return(queryAnnotationResultOperator);
        }
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            ArgumentUtility.CheckNotNull("queryModel", queryModel);

            var previousFetchRequest = clauseGenerationContext.GetContextInfo(Source) as FetchRequestBase;

            if (previousFetchRequest == null)
            {
                throw new NotSupportedException("ThenFetchMany must directly follow another Fetch request.");
            }

            var innerFetchRequest = CreateFetchRequest();

            innerFetchRequest = previousFetchRequest.GetOrAddInnerFetchRequest(innerFetchRequest);
            // Store a mapping between this node and the innerFetchRequest so that a later ThenFetch... node may add its request to the innerFetchRequest.
            clauseGenerationContext.AddContextInfo(this, innerFetchRequest);
        }
Exemple #22
0
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            ArgumentUtility.CheckNotNull("queryModel", queryModel);

            var existingMatchingFetchRequest =
                queryModel.ResultOperators.OfType <FetchRequestBase> ().FirstOrDefault(r => r.RelationMember.Equals(RelationMember));

            if (existingMatchingFetchRequest != null)
            {
                // Store a mapping between this node and the resultOperator so that a later ThenFetch... node may add its request to the resultOperator.
                clauseGenerationContext.AddContextInfo(this, existingMatchingFetchRequest);
            }
            else
            {
                base.ApplyNodeSpecificSemantics(queryModel, clauseGenerationContext);
            }
        }
Exemple #23
0
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel,
                                                           ClauseGenerationContext clauseGenerationContext)
        {
            var nestClause = new NestClause(
                ResultSelector.Parameters[1].Name,
                ResultSelector.Parameters[1].Type,
                InnerSequence,
                GetResolvedKeySelector(clauseGenerationContext),
                IsLeftOuterNest);

            clauseGenerationContext.AddContextInfo(this, nestClause);
            queryModel.BodyClauses.Add(nestClause);

            var selectClause = queryModel.SelectClause;

            selectClause.Selector = GetResolvedResultSelector(clauseGenerationContext);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override void ApplyNodeSpecificSemantics(
            QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            var includeResultOperator
                = (IncludeResultOperator)clauseGenerationContext.GetContextInfo(Source);

            if (!NavigationPropertyPathLambda.TryGetComplexPropertyAccess(out var propertyPath))
            {
                throw new InvalidOperationException(
                          CoreStrings.InvalidIncludeLambdaExpression(
                              nameof(EntityFrameworkQueryableExtensions.ThenInclude),
                              NavigationPropertyPathLambda));
            }

            includeResultOperator.AppendToNavigationPath(propertyPath);

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var prm = Expression.Parameter(typeof(object));
            var pathFromQuerySource = Resolve(prm, prm, clauseGenerationContext);

            if (!(_navigationPropertyPathLambda.Body is MemberExpression))
            {
                throw new InvalidOperationException(CoreStrings.InvalidPropertyExpression(_navigationPropertyPathLambda));
            }

            var includeResultOperator = new IncludeResultOperator(
                _navigationPropertyPathLambda.GetComplexPropertyAccess("?not sure what goes here?").Select(p => p.Name),
                pathFromQuerySource);

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);

            return(includeResultOperator);
        }
        public void Resolve_ReplacesParameter_WithProjection()
        {
            var expression = ExpressionHelper.CreateLambdaExpression <int, Tuple <short, int> > (i => Tuple.Create((short)1, 2));

            var querySource = ExpressionHelper.CreateGroupResultOperator();

            ClauseGenerationContext.AddContextInfo(_nodeWithElementSelector.Source, querySource);

            var result = _nodeWithElementSelector.Resolve(expression.Parameters[0], expression.Body, ClauseGenerationContext);

            var expectedResult = Expression.Call(
                typeof(Tuple),
                "Create",
                new[] { typeof(short), typeof(int) },
                Expression.Constant((short)1),
                Expression.Constant(2));

            ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
Exemple #27
0
        protected override QueryModel ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            Utils.CheckNotNull("queryModel", queryModel);

            if (IsLetNode)
            {
                // For let nodes, we insert a LetClause instance, then adapt the SelectClause to select the data bubbling out of the LetClause.
                var resolvedLetExpression = GetResolvedLetExpression(clauseGenerationContext);
                var letClause             = new LetClause(_letConstruction.Constructor.GetParameters()[1].Name, resolvedLetExpression);
                queryModel.BodyClauses.Add(letClause);

                clauseGenerationContext.AddContextInfo(this, letClause);

                queryModel.SelectClause.Selector = GetResolvedAdaptedSelector(clauseGenerationContext);
                return(queryModel);
            }

            return(base.ApplyNodeSpecificSemantics(queryModel, clauseGenerationContext));
        }
Exemple #28
0
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var navigationPropertyPath
                = Source.Resolve(
                      _navigationPropertyPathLambda.Parameters[0],
                      _navigationPropertyPathLambda.Body,
                      clauseGenerationContext) as MemberExpression;

            if (navigationPropertyPath == null)
            {
                throw new InvalidOperationException(
                          CoreStrings.InvalidComplexPropertyExpression(_navigationPropertyPathLambda));
            }

            var includeResultOperator = new IncludeResultOperator(navigationPropertyPath);

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);

            return(includeResultOperator);
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext)
        {
            var prm = Expression.Parameter(typeof(object));
            var pathFromQuerySource = Resolve(prm, prm, clauseGenerationContext);

            if (!NavigationPropertyPathLambda.TryGetComplexPropertyAccess(out var propertyPath))
            {
                throw new InvalidOperationException(
                          CoreStrings.InvalidIncludeLambdaExpression(
                              nameof(EntityFrameworkQueryableExtensions.Include),
                              NavigationPropertyPathLambda));
            }

            var includeResultOperator = new IncludeResultOperator(
                propertyPath.Select(p => p.Name),
                pathFromQuerySource);

            clauseGenerationContext.AddContextInfo(this, includeResultOperator);

            return(includeResultOperator);
        }
Exemple #30
0
        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
        {
            Utils.CheckNotNull("queryModel", queryModel);

            var resolvedCollectionSelector = GetResolvedCollectionSelector(clauseGenerationContext);
            var resolvedLetSelector        = GetResolvedLetSelector(clauseGenerationContext);

            var clause = new LetClause(CollectionSelector.Parameters[1].Name, resolvedLetSelector, resolvedCollectionSelector);

            queryModel.BodyClauses.Add(clause);

            //var clause = new AdditionalFromClause(ResultSelector.Parameters[1].Name, ResultSelector.Parameters[1].Type, resolvedCollectionSelector);
            //queryModel.BodyClauses.Add(clause);

            clauseGenerationContext.AddContextInfo(this, clause);

            var selectClause = queryModel.SelectClause;

            selectClause.Selector =
                //GetResolvedCollectionSelector(clauseGenerationContext);
                GetResolvedResultSelector(clauseGenerationContext);
        }