Exemplo n.º 1
0
        public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
        {
            CurrentEvaluationType = selectClause.GetOutputDataInfo();

            switch (_queryMode)
            {
            case QueryMode.Delete:
                VisitDeleteClause(selectClause.Selector);
                return;

            case QueryMode.Update:
            case QueryMode.UpdateVersioned:
                VisitUpdateClause(selectClause.Selector);
                return;

            case QueryMode.Insert:
                VisitInsertClause(selectClause.Selector);
                return;
            }

            //This is a standard select query

            var visitor = new SelectClauseVisitor(typeof(object[]), VisitorParameters);

            visitor.VisitSelector(selectClause.Selector);

            if (visitor.ProjectionExpression != null)
            {
                _hqlTree.AddItemTransformer(visitor.ProjectionExpression);
            }

            _hqlTree.AddSelectClause(_hqlTree.TreeBuilder.Select(visitor.GetHqlNodes()));

            base.VisitSelectClause(selectClause, queryModel);
        }
    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));
    }
Exemplo n.º 3
0
 public void SetUp ()
 {
   _mainFromClause = ExpressionHelper.CreateMainFromClause_Int();
   _selectClause = ExpressionHelper.CreateSelectClause();
   _queryModel = new QueryModel (_mainFromClause, _selectClause);
   _querySourceMapping = new QuerySourceMapping();
 }
    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 QueryModel Apply (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      if (queryModel != null)
        throw new ArgumentException ("QueryModel has to be null because MainSourceExpressionNode marks the start of a query.", "queryModel");

      var mainFromClause = CreateMainFromClause (clauseGenerationContext);
      var defaultSelectClause = new SelectClause (new QuerySourceReferenceExpression (mainFromClause));
      return new QueryModel (mainFromClause, defaultSelectClause) { ResultTypeOverride = QuerySourceType };
    }
Exemplo n.º 6
0
 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 ();
 }
 protected override void ModifyFetchQueryModel(QueryModel fetchQueryModel)
 {
     ArgumentUtility.CheckNotNull<QueryModel>("fetchQueryModel", fetchQueryModel);
     System.Linq.Expressions.MemberExpression fromExpression = System.Linq.Expressions.Expression.MakeMemberAccess(new QuerySourceReferenceExpression(fetchQueryModel.MainFromClause), base.RelationMember);
     AdditionalFromClause additionalFromClause = new AdditionalFromClause(fetchQueryModel.GetNewName("#fetch"), this._relatedObjectType, fromExpression);
     fetchQueryModel.BodyClauses.Add(additionalFromClause);
     QuerySourceReferenceExpression selector = new QuerySourceReferenceExpression(additionalFromClause);
     SelectClause selectClause = new SelectClause(selector);
     fetchQueryModel.SelectClause = selectClause;
 }
Exemplo n.º 8
0
    /// <summary>
    /// Modifies the given query model for fetching, adding an <see cref="AdditionalFromClause"/> and changing the <see cref="SelectClause.Selector"/> to 
    /// retrieve the result of the <see cref="AdditionalFromClause"/>.
    /// For example, a fetch request such as <c>FetchMany (x => x.Orders)</c> will be transformed into a <see cref="AdditionalFromClause"/> selecting
    /// <c>y.Orders</c> (where <c>y</c> is what the query model originally selected) and a <see cref="SelectClause"/> selecting the result of the
    /// <see cref="AdditionalFromClause"/>.
    /// This method is called by <see cref="FetchRequestBase.CreateFetchQueryModel"/> in the process of creating the new fetch query model.
    /// </summary>
    protected override void ModifyFetchQueryModel (QueryModel fetchQueryModel)
    {
      ArgumentUtility.CheckNotNull ("fetchQueryModel", fetchQueryModel);

      var fromExpression = Expression.MakeMemberAccess (new QuerySourceReferenceExpression (fetchQueryModel.MainFromClause), RelationMember);
      var memberFromClause = new AdditionalFromClause (fetchQueryModel.GetNewName ("#fetch"), _relatedObjectType, fromExpression);
      fetchQueryModel.BodyClauses.Add (memberFromClause);

      var newSelector = new QuerySourceReferenceExpression (memberFromClause);
      var newSelectClause = new SelectClause (newSelector);
      fetchQueryModel.SelectClause = newSelectClause;
    }
Exemplo n.º 9
0
    public void TransformExpressions ()
    {
      var oldExpression = ExpressionHelper.CreateExpression ();
      var newExpression = ExpressionHelper.CreateExpression ();
      var clause = new SelectClause (oldExpression);

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

      Assert.That (clause.Selector, Is.SameAs (newExpression));
    }
    public void SetUp ()
    {
      // var query = from c in Customers select null
      _mainFromClause = new MainFromClause ("c", typeof (DataContextTestClass.Customer), Expression.Constant (new DataContextTestClass.Customer[0]));
      _selectClause = new SelectClause (Expression.Constant (null, typeof (DataContextTestClass.Customer)));
      _queryModel = new QueryModel (_mainFromClause, _selectClause);

      _resolverStub = MockRepository.GenerateStub<IMappingResolver> ();
      _resolverStub
          .Stub (stub => stub.ResolveTableInfo (Arg<UnresolvedTableInfo>.Is.Anything, Arg<UniqueIdentifierGenerator>.Is.Anything))
          .Return (new ResolvedSimpleTableInfo (typeof (DataContextTestClass.Customer), "CustomerTable", "t0"));
      _resolverStub
          .Stub (stub => stub.ResolveConstantExpression ((ConstantExpression) _selectClause.Selector))
          .Return (_selectClause.Selector);
    }
Exemplo n.º 11
0
    /// <summary>
    /// Initializes a new instance of <see cref="QueryModel"/>
    /// </summary>
    /// <param name="mainFromClause">The <see cref="Clauses.MainFromClause"/> of the query. This is the starting point of the query, generating items 
    /// that are filtered and projected by the query.</param>
    /// <param name="selectClause">The <see cref="SelectClause"/> of the query. This is the end point of
    /// the query, it defines what is actually returned for each of the items coming from the <see cref="MainFromClause"/> and passing the 
    /// <see cref="BodyClauses"/>. After it, only the <see cref="ResultOperators"/> modify the result of the query.</param>
    public QueryModel (MainFromClause mainFromClause, SelectClause selectClause)
    {
      ArgumentUtility.CheckNotNull ("mainFromClause", mainFromClause);
      ArgumentUtility.CheckNotNull ("selectClause", selectClause);

      _uniqueIdentifierGenerator = new UniqueIdentifierGenerator();

      MainFromClause = mainFromClause;
      SelectClause = selectClause;

      BodyClauses = new ObservableCollection<IBodyClause>();
      BodyClauses.CollectionChanged += BodyClauses_CollectionChanged;

      ResultOperators = new ObservableCollection<ResultOperatorBase>();
      ResultOperators.CollectionChanged += ResultOperators_CollectionChanged;
    }
    public void SetUp ()
    {
      _generator = new UniqueIdentifierGenerator();
      _context = SqlStatementModelObjectMother.CreateSqlPreparationContext();
      _defaultStage = new DefaultSqlPreparationStage (
          CompoundMethodCallTransformerProvider.CreateDefault(), ResultOperatorHandlerRegistry.CreateDefault(), _generator);

      _mainFromClause = ExpressionHelper.CreateMainFromClause<Cook>();
      _selectClause = ExpressionHelper.CreateSelectClause (_mainFromClause);
      _orderByClause = ExpressionHelper.CreateOrderByClause();
      _queryModel = new QueryModel (_mainFromClause, _selectClause);

      _stageMock = MockRepository.GenerateStrictMock<ISqlPreparationStage>();
      _visitor = new TestableSqlPreparationQueryModelVisitor (_context, _stageMock);
      _visitorPartialMock = MockRepository.GeneratePartialMock<TestableSqlPreparationQueryModelVisitor> (_context, _stageMock);
    }
    public void VisitQueryModel ()
    {
      var mainFromClaus = new MainFromClause ("x", typeof (Cook), ExpressionHelper.CreateExpression());
      var selectClause =  new SelectClause (ExpressionHelper.CreateExpression());
      var queryModel = new QueryModel (mainFromClaus, selectClause);

      using (_mockRepository.Ordered())
      {
        _visitorMock.Expect (mock => mock.VisitQueryModel (queryModel)).CallOriginalMethod (OriginalCallOptions.NoExpectation);
        _visitorMock.Expect (mock => mock.VisitMainFromClause (mainFromClaus, queryModel));
        _visitorMock.Expect (mock => mock.InvokeVisitBodyClauses (queryModel.BodyClauses, queryModel));
        _visitorMock.Expect (mock => mock.VisitSelectClause (selectClause, queryModel));
        _visitorMock.Expect (mock => mock.InvokeVisitResultOperators (queryModel.ResultOperators, queryModel));
      }

      _mockRepository.ReplayAll();

      _visitorMock.VisitQueryModel (queryModel);

      _mockRepository.VerifyAll();
    }
        /// <summary>Visits a select clause.</summary>
        /// <param name="selectClause">Select clause to be visited.</param>
        /// <param name="queryModel">Query model containing given select clause.</param>
        public override void VisitSelectClause(SelectClause selectClause, Remotion.Linq.QueryModel queryModel)
        {
            QuerySourceReferenceExpression querySource = FindQuerySource(selectClause.Selector);
            _visitor.VisitExpression(selectClause.Selector);
            QueryComponent component = _visitor.RetrieveComponent();
            _query = _visitor.Query;
            _mainFromComponent = _query.FindAllComponents<StrongEntityAccessor>().Where(item => item.SourceExpression == querySource.ReferencedQuerySource).First();
            if (_query.Subject == null)
            {
                _query.Subject = _mainFromComponent.About;
                UnboundConstrain genericConstrain = new UnboundConstrain(new Identifier("s"), new Identifier("p"), new Identifier("o"), _mainFromComponent.SourceExpression.FromExpression);
                _mainFromComponent.Elements.Insert(0, genericConstrain);
                _query.Select.Add(genericConstrain);
            }

            _subject = _query.Subject;
            queryModel.MainFromClause.Accept(this, queryModel);
            _query.Select.Add(_mainFromComponent);
            VisitBodyClauses(queryModel.BodyClauses, queryModel);
            VisitResultOperators(queryModel.ResultOperators, queryModel);
            OverrideSelector(component, selectClause.Selector);
        }
Exemplo n.º 15
0
		public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
		{
			SelectGeneratorExpressionTreeVisitor.ProcessExpression(selectClause.Selector, QueryParts, queryModel);

			base.VisitSelectClause(selectClause, queryModel);
		}
		public void Transform(SelectClause selectClause)
		{
			_requiresJoinForNonIdentifier = true;
			selectClause.TransformExpressions(VisitExpression);
			_requiresJoinForNonIdentifier = false;
		}
Exemplo n.º 17
0
 public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
 {
     base.VisitSelectClause(selectClause, queryModel);
 }
Exemplo n.º 18
0
        /// <summary>
        /// 解析 select 语句
        /// </summary>
        /// <param name="selectClause"></param>
        /// <param name="queryModel"></param>
        public override void VisitSelectClause( SelectClause selectClause, QueryModel queryModel )
        {
            MySqlSelectClauseVisitor visitor = new MySqlSelectClauseVisitor( this.parameterAggregator );

            string selectParts = visitor.Translate( selectClause.Selector );

            queryPartsAggregator.SelectPart = selectParts;

            base.VisitSelectClause( selectClause, queryModel );
        }
        public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
        {
            var paths = PropertyPathExtractionVisitor.ExtractPaths(selectClause.Selector, _nodeTypeProvider, true, false, _namingScheme, "/");
            if (paths.Count == 0)
            {
                Precedence = 0;
            }
            else if (!paths.SequenceEqual(new[] {"*"}))
            {
                Select = string.Join(",", paths.ToArray());
            }

            base.VisitSelectClause(selectClause, queryModel);
        }
Exemplo n.º 20
0
 public new void ToString ()
 {
   var selectClause = new SelectClause (Expression.Constant (0));
   Assert.That (selectClause.ToString (), Is.EqualTo ("select 0"));
 }
		public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
		{
			_selectJoinDetector.Transform(selectClause);
		}
Exemplo n.º 22
0
 public void SetUp ()
 {
   _selector = Expression.Constant (new Cook ());
   _selectClause = new SelectClause (_selector);
   _cloneContext = new CloneContext (new QuerySourceMapping());
 }
        public virtual void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
        {
            ArgumentUtility.CheckNotNull ("selectClause", selectClause);
              ArgumentUtility.CheckNotNull ("queryModel", queryModel);

              // nothing to do here
        }
		public void Transform(SelectClause selectClause)
		{
			// The select clause typically requires joins for non-Identifier member access
			_requiresJoinForNonIdentifier = true;
			selectClause.TransformExpressions(VisitExpression);
			_requiresJoinForNonIdentifier = false;
		}
Exemplo n.º 25
0
		public void Transform(SelectClause selectClause)
		{
			selectClause.TransformExpressions(VisitExpression);
		}
 /// <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 VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
     => selectClause.TransformExpressions(TransformingVisitor.Visit);
		public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
		{
            selectClause.TransformExpressions(e => MergeAggregatingResultsInExpressionRewriter.Rewrite(e, new NameGenerator(queryModel)));
		}
        public override void VisitSelectClause( SelectClause selectClause, QueryModel queryModel )
        {
            if( queryModel.ResultOperators.FirstOrDefault() is AverageResultOperator )
            {
                var memberExpression = selectClause.Selector as MemberExpression;
                var memberNameResolver = new MemberNameResolver( memberExpression );
                Stack.Push( Stack.Pop().Avg( x => memberNameResolver.Resolve( x ) ) );
                return;
            }

            if( queryModel.ResultOperators.FirstOrDefault() is CountResultOperator )
            {
                Stack.Push( Stack.Pop().Count( ) );
                return;
            }

            var expr = GetSelectReqlAst( selectClause.Selector );
            if( !ReferenceEquals( expr, null ) )
            {
                
            }

            base.VisitSelectClause( selectClause, queryModel );
        }
 public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
 {
     foreach (var parameter in GetSelectParameters(selectClause, queryModel))
     {
         _queryPartsAggregator.AddSelectParts(parameter);
     }
     base.VisitSelectClause(selectClause, queryModel);
 }
        private IEnumerable<string> GetSelectParameters(SelectClause selectClause, QueryModel queryModel)
        {
            var prefix = EscapeIdentifier(queryModel.MainFromClause.ItemName);

            var expression = GetN1QlExpression(selectClause.Selector);

            if (selectClause.Selector.GetType() == typeof (QuerySourceReferenceExpression))
            {
                expression = string.Concat(expression, ".*");
            }

            return expression.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
Exemplo n.º 31
0
		public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
		{
			CurrentEvaluationType = selectClause.GetOutputDataInfo();

			var visitor = new SelectClauseVisitor(typeof(object[]), VisitorParameters);

			visitor.Visit(selectClause.Selector);

			if (visitor.ProjectionExpression != null)
			{
				_hqlTree.AddItemTransformer(visitor.ProjectionExpression);
			}

			_hqlTree.AddSelectClause(_hqlTree.TreeBuilder.Select(visitor.GetHqlNodes()));

			base.VisitSelectClause(selectClause, queryModel);
		}