public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
 {
     var visitor = new QueryBuildingExpressionTreeVisitor(context, fieldMappingInfoProvider);
     visitor.VisitExpression(whereClause.Predicate);
     
     model.AddQuery(visitor.Query);
 }
Beispiel #2
0
    public void InitializeWithboolExpression()
    {
      var predicate = Expression.Constant (false);
      var whereClause = new WhereClause(predicate);

      Assert.That (whereClause.Predicate, Is.SameAs (predicate));
    }
    protected override void ApplyNodeSpecificSemantics (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      var clause = new WhereClause (GetResolvedPredicate (clauseGenerationContext));
      queryModel.BodyClauses.Add (clause);
    }
    public void SetUp ()
    {
      _detailSource = ExpressionHelper.CreateQueryable<Kitchen>();
      _sectorSource = ExpressionHelper.CreateQueryable<Restaurant>();

      var query = from s1 in ExpressionHelper.CreateQueryable<Cook>()
                  from sd in
                      (from sector in _sectorSource
                       where sector.ID > 10
                       select sector.SubKitchen)
                  from s2 in s1.Assistants
                  where sd.Name == "Maths"
                  select new NonTransformedTuple<Cook, Kitchen> (s1, sd);
      _queryModel = ExpressionHelper.ParseQuery (query);

      _mainFromClause = _queryModel.MainFromClause;
      _additionalFromClause1 = (AdditionalFromClause) _queryModel.BodyClauses[0];
      _additionalFromClause2 = (AdditionalFromClause) _queryModel.BodyClauses[1];
      _whereClause = (WhereClause) _queryModel.BodyClauses[2];
      _selectClause = _queryModel.SelectClause;

      var subQueryExpressionA = (SubQueryExpression) _additionalFromClause1.FromExpression;
      _innerMainFromClauseA = subQueryExpressionA.QueryModel.MainFromClause;
      _innerWhereClauseA = (WhereClause) subQueryExpressionA.QueryModel.BodyClauses[0];

      _visitor = new SubQueryFromClauseFlattener();
    }
    public void NamedEntity ()
    {
      // from c in Cooks select c [with name = "inner"]
      var subMainFromClause = new MainFromClause ("c", typeof(Cook), Expression.Constant (Cooks));
      var subSelectClause = new SelectClause (new NamedExpression ("inner", new QuerySourceReferenceExpression (subMainFromClause)));
      var subQuery = new QueryModel (subMainFromClause, subSelectClause);

      // from x in (subQuery) where x.ID == null select x
      var outerMainFromClause = new MainFromClause ("x", typeof(Cook), new SubQueryExpression (subQuery));
      var outerWhereClause = new WhereClause(Expression.Equal(Expression.MakeMemberAccess (new QuerySourceReferenceExpression (outerMainFromClause), typeof (Cook).GetProperty ("ID")), Expression.Constant (1)));
      var outerSelectClause = new SelectClause (new QuerySourceReferenceExpression (outerMainFromClause));
      var outerQuery = new QueryModel (outerMainFromClause, outerSelectClause);
      outerQuery.BodyClauses.Add (outerWhereClause);

      CheckQuery (
          outerQuery, 
          "SELECT [q0].[inner_ID] AS [ID],[q0].[inner_FirstName] AS [FirstName],[q0].[inner_Name] AS [Name],"
          + "[q0].[inner_IsStarredCook] AS [IsStarredCook],[q0].[inner_IsFullTimeCook] AS [IsFullTimeCook],"
          + "[q0].[inner_SubstitutedID] AS [SubstitutedID],[q0].[inner_KitchenID] AS [KitchenID],"
          + "[q0].[inner_KnifeID] AS [KnifeID],[q0].[inner_KnifeClassID] AS [KnifeClassID] " 
          + "FROM (SELECT [t1].[ID] AS [inner_ID],"
          + "[t1].[FirstName] AS [inner_FirstName],[t1].[Name] AS [inner_Name],[t1].[IsStarredCook] AS [inner_IsStarredCook],"
          + "[t1].[IsFullTimeCook] AS [inner_IsFullTimeCook],[t1].[SubstitutedID] AS [inner_SubstitutedID],"
          + "[t1].[KitchenID] AS [inner_KitchenID],[t1].[KnifeID] AS [inner_KnifeID],[t1].[KnifeClassID] AS [inner_KnifeClassID] "
          + "FROM [CookTable] AS [t1]) AS [q0] WHERE ([q0].[inner_ID] = @1)",
          new CommandParameter("@1", 1));
    }
 public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
 {
     WhereJoinDetector.Find(whereClause.Predicate,_nameGenerator,
                                       this,
                                       _joins,
                                       _expressionMap);
 }
        public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            foreach (var visitor in _whereClauseVisitors)
            {
                whereClause.TransformExpressions(visitor.VisitExpression);
            }

            base.VisitWhereClause(whereClause, queryModel, index);
        }
 public void SetUp ()
 {
   _builder = new QueryModelBuilder();
   _mainFromClause = ExpressionHelper.CreateMainFromClause_Int ();
   _whereClause1 = ExpressionHelper.CreateWhereClause ();
   _whereClause2 = ExpressionHelper.CreateWhereClause ();
   _selectClause = ExpressionHelper.CreateSelectClause ();
   _resultOperator1 = ExpressionHelper.CreateResultOperator ();
   _resultOperator2 = ExpressionHelper.CreateResultOperator ();
 }
        public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            Log.Trace(m => m("Original QueryModel:     {0}", queryModel));

            foreach (var visitor in whereSelectClauseVisitors)
            {
                whereClause.TransformExpressions(visitor.VisitExpression);
                Log.Trace(m => m("Transformed QueryModel after {0}: {1}", visitor.GetType().Name, queryModel));
            }

            base.VisitWhereClause(whereClause, queryModel, index);
        }
Beispiel #10
0
        public override void VisitWhereClause(Remotion.Linq.Clauses.WhereClause whereClause, QueryModel queryModel, int index)
        {
            bool alreadyHasQuery = false;

            var query = new StringBuilder();

            queries.Add(query);

            ExpressionTreeVisitor visitor = new ExpressionTreeVisitor(query);

            visitor.VisitExpression(whereClause.Predicate);

            base.VisitWhereClause(whereClause, queryModel, index);
        }
Beispiel #11
0
    public void TransformExpressions ()
    {
      var oldExpression = ExpressionHelper.CreateExpression ();
      var newExpression = ExpressionHelper.CreateExpression ();
      var clause = new WhereClause (oldExpression);

      clause.TransformExpressions (ex =>
          {
            Assert.That (ex, Is.SameAs (oldExpression));
            return newExpression;
          });

      Assert.That (clause.Predicate, Is.SameAs (newExpression));
    }
		public void Transform(WhereClause whereClause)
		{
			whereClause.TransformExpressions(VisitExpression);

			var values = _values.Pop();

			foreach (var memberExpression in values.MemberExpressions)
			{
				// If outer join can never produce true, we can safely inner join.
				if (!values.GetValues(memberExpression).Contains(true))
				{
					_joiner.MakeInnerIfJoined(memberExpression);
				}
			}
		}
    public void SetUp ()
    {
      _mockRepository = new MockRepository();
      _visitorMock = _mockRepository.StrictMock<QueryModelVisitorBase>();
      _testVisitor = new TestQueryModelVisitor ();

      _bodyClauseMock1 = _mockRepository.StrictMock<WhereClause> (ExpressionHelper.CreateExpression());
      _bodyClauseMock2 = _mockRepository.StrictMock<WhereClause> (ExpressionHelper.CreateExpression());

      _orderingMock1 = _mockRepository.StrictMock<Ordering> (ExpressionHelper.CreateExpression(), OrderingDirection.Asc);
      _orderingMock2 = _mockRepository.StrictMock<Ordering> (ExpressionHelper.CreateExpression(), OrderingDirection.Asc);

      _resultOperatorMock1 = _mockRepository.StrictMock<ResultOperatorBase> ();
      _resultOperatorMock2 = _mockRepository.StrictMock<ResultOperatorBase> ();

      _queryModel = ExpressionHelper.CreateQueryModel<Cook> ();
      _orderByClause = ExpressionHelper.CreateOrderByClause ();
      _groupJoinClause = ExpressionHelper.CreateGroupJoinClause<Cook> ();
    }
		private static void FlattenSubQuery(SubQueryExpression subQueryExpression, QueryModel queryModel)
		{
			// we can not flattern subquery if outer query has body clauses.
			var subQueryModel = subQueryExpression.QueryModel;
			var subQueryMainFromClause = subQueryModel.MainFromClause;
			if (queryModel.BodyClauses.Count == 0)
			{
				foreach (var resultOperator in subQueryModel.ResultOperators)
					queryModel.ResultOperators.Add(resultOperator);

				foreach (var bodyClause in subQueryModel.BodyClauses)
					queryModel.BodyClauses.Add(bodyClause);
			}
			else
			{
				var cro = new ContainsResultOperator(new QuerySourceReferenceExpression(subQueryMainFromClause));

				var newSubQueryModel = subQueryModel.Clone();
				newSubQueryModel.ResultOperators.Add(cro);
				newSubQueryModel.ResultTypeOverride = typeof (bool);

				var where = new WhereClause(new SubQueryExpression(newSubQueryModel));
				queryModel.BodyClauses.Add(where);

				if (!queryModel.BodyClauses.OfType<OrderByClause>().Any())
				{
					var orderByClauses = subQueryModel.BodyClauses.OfType<OrderByClause>();
					foreach (var orderByClause in orderByClauses)
						queryModel.BodyClauses.Add(orderByClause);
				}
			}

			var visitor1 = new PagingRewriterSelectClauseVisitor();
			queryModel.SelectClause.TransformExpressions(visitor1.Swap);

			// Point all query source references to the outer from clause
			var visitor2 = new SwapQuerySourceVisitor(queryModel.MainFromClause, subQueryMainFromClause);
			queryModel.TransformExpressions(visitor2.Swap);

			// Replace the outer query source
			queryModel.MainFromClause = subQueryMainFromClause;
		}
        public override void VisitWhereClause( WhereClause whereClause, QueryModel queryModel, int index )
        {
            var expressions = SplitWhereClause( whereClause.Predicate );

            foreach( var expression in expressions.ToList() )
            {
                var whereClauseParsers = new List<IWhereClauseParser>
                {
                    new GroupItemsParser(),
                    new PrimaryIndexParser(),
                    new SecondaryIndexParser(),
                    new DefaultParser()
                };

                var reql = Stack.Pop();
                var matchingParser = whereClauseParsers.FirstOrDefault( x => x.IsAppropriate( reql, expression, queryModel.ResultTypeOverride ) );
                if( matchingParser != null )
                    Stack.Push( matchingParser.Parse( reql, queryModel, expression ) );
                else
                    throw new NotSupportedException( "Unable to vist Where clause" );
            }
        }
        /// <summary>
        /// 解析 Where 语句
        /// </summary>
        /// <param name="whereClause"></param>
        /// <param name="queryModel"></param>
        /// <param name="index"></param>
        public override void VisitWhereClause( WhereClause whereClause, QueryModel queryModel, int index )
        {
            MySqlWhereClauseVisitor visitor = new MySqlWhereClauseVisitor( this.parameterAggregator );

            string whereParts = visitor.Translate( whereClause.Predicate );

            queryPartsAggregator.WhereParts.Add( whereParts );

            base.VisitWhereClause( whereClause, queryModel, index );
        }
        public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            var predicate = whereClause.Predicate;

            var visitor = new EnigmaExpressionTreeVisitor(_objectExpression);
            visitor.VisitExpression(predicate);

            base.VisitWhereClause(whereClause, queryModel, index);
        }
		public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
		{
			_whereJoinDetector.Transform(whereClause);
		}
        public virtual void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            ArgumentUtility.CheckNotNull ("whereClause", whereClause);
              ArgumentUtility.CheckNotNull ("queryModel", queryModel);

              // nothing to do here
        }
        public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            if (_groupingStatus != GroupingStatus.AfterGroupSubquery)
            {
                _queryPartsAggregator.AddWherePart(GetN1QlExpression(whereClause.Predicate));
            }
            else
            {
                _queryPartsAggregator.AddHavingPart(GetN1QlExpression(whereClause.Predicate));
            }

            base.VisitWhereClause(whereClause, queryModel, index);
        }
 /// <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>
 public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
     => whereClause.TransformExpressions(TransformingVisitor.Visit);
Beispiel #22
0
 /// <summary>
 /// Look for the expression associated with a Where clause, and run the parser on that.
 /// </summary>
 /// <param name="whereClause"></param>
 /// <param name="queryModel"></param>
 /// <param name="index"></param>
 public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
 {
     _exprVisitor.Visit(whereClause.Predicate);
 }
 public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
 {
     whereClause.TransformExpressions(e => MergeAggregatingResultsInExpressionRewriter.Rewrite(e, new NameGenerator(queryModel)));
 }
		public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
		{
			// Visit the predicate to build the query
			var expression = HqlGeneratorExpressionTreeVisitor.Visit(whereClause.Predicate, VisitorParameters).AsBooleanExpression();
			if (whereClause is NhHavingClause)
			{
				_hqlTree.AddHavingClause(expression);
			}
			else
			{
				_hqlTree.AddWhereClause(expression);
			}
		}
        public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            var where = SDataExpressionBuilderVisitor.BuildExpression(whereClause.Predicate, _namingScheme);
            if (Where != null)
            {
                where = string.Format("({0} and {1})", Where, where);
            }

            Where = where;
            base.VisitWhereClause(whereClause, queryModel, index);
        }
        /// <summary>
        /// Visits the where clause.
        /// </summary>
        /// <param name="whereClause">The where clause.</param>
        /// <param name="queryModel">The query model.</param>
        /// <param name="index">The index.</param>
        /// <remarks></remarks>
        public override void VisitWhereClause(WhereClause whereClause, Remotion.Linq.QueryModel queryModel, int index)
        {
            var wherePredicate = whereClause.Predicate;

            var criteriaExpression = this.GetCriteriaExpression(queryModel, wherePredicate);

            _queryDescription.SetCriteria(criteriaExpression);
            base.VisitWhereClause(whereClause, queryModel, index);
        }
        public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
        {
            QueryBuildResult result = QueryBuildingVisitor.Build(whereClause.Predicate);
            _exprTreeAggregator.Add(result.Expression);
            _returnProperties.AddRange(result.PropertiesUsed);

            base.VisitWhereClause(whereClause, queryModel, index);
        }
		public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
		{
			QueryParts.AddCondition(whereClause.Predicate);

			base.VisitWhereClause(whereClause, queryModel, index);
		}
Beispiel #29
0
    /// <summary>
    /// Clones this clause.
    /// </summary>
    /// <param name="cloneContext">The clones of all query source clauses are registered with this <see cref="CloneContext"/>.</param>
    /// <returns></returns>
    public virtual WhereClause Clone (CloneContext cloneContext)
    {
      ArgumentUtility.CheckNotNull ("cloneContext", cloneContext);

      var clone = new WhereClause (Predicate);
      return clone;
    }
 public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
 {
     _queryPartsAggregator.AddWherePart(GetN1QlExpression(whereClause.Predicate));
     base.VisitWhereClause(whereClause, queryModel, index);
 }
        /// <summary>
        /// 解析 Where 语句
        /// </summary>
        /// <param name="whereClause"></param>
        /// <param name="queryModel"></param>
        /// <param name="index"></param>
        public override void VisitWhereClause( WhereClause whereClause, QueryModel queryModel, int index )
        {
            OracleWherePartsCommandBuilder whereBuilder = new OracleWherePartsCommandBuilder( this.commandBuilder.Parameters );

            OracleWhereClauseVisitor visitor = new OracleWhereClauseVisitor();

            visitor.Translate( whereClause.Predicate, whereBuilder );

            commandBuilder.WhereParts.Add( whereBuilder.ToString() );

            base.VisitWhereClause( whereClause, queryModel, index );
        }