public void GetOutputDataInfo() { var info = _selectClause.GetOutputDataInfo(); Assert.That(info.DataType, Is.SameAs(typeof(IQueryable <Cook>))); Assert.That(info.ItemExpression, Is.SameAs(_selectClause.Selector)); }
public override void VisitSelectClause( [NotNull] SelectClause selectClause, [NotNull] QueryModel queryModel) { Check.NotNull(selectClause, "selectClause"); Check.NotNull(queryModel, "queryModel"); if (_streamedSequenceInfo != null) { return; } var selector = ReplaceClauseReferences( CreateProjectionExpressionTreeVisitor() .VisitExpression(selectClause.Selector)); _expression = Expression.Call( LinqOperatorProvider.Select .MakeGenericMethod(typeof(QuerySourceScope), selector.Type), _expression, Expression.Lambda(selector, QuerySourceScopeParameter)); _streamedSequenceInfo = (StreamedSequenceInfo)selectClause.GetOutputDataInfo() .AdjustDataType(typeof(IEnumerable <>)); }
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); }
/// <summary> /// Gets an <see cref="IStreamedDataInfo"/> object describing the data streaming out of this <see cref="QueryModel"/>. If a query ends with /// the <see cref="SelectClause"/>, this corresponds to <see cref="Clauses.SelectClause.GetOutputDataInfo"/>. If a query has /// <see cref="QueryModel.ResultOperators"/>, the data is further modified by those operators. /// </summary> /// <returns>Gets a <see cref="IStreamedDataInfo"/> object describing the data streaming out of this <see cref="QueryModel"/>.</returns> /// <remarks> /// The data streamed from a <see cref="QueryModel"/> is often of type <see cref="IQueryable{T}"/> instantiated /// with a specific item type, unless the /// query ends with a <see cref="ResultOperatorBase"/>. For example, if the query ends with a <see cref="CountResultOperator"/>, the /// result type will be <see cref="int"/>. /// </remarks> /// <exception cref="InvalidOperationException"> /// The <see cref="ResultTypeOverride"/> is not compatible with the calculated <see cref="IStreamedDataInfo"/> calculated from the <see cref="ResultOperators"/>. /// </exception> public IStreamedDataInfo GetOutputDataInfo() { var outputDataInfo = ResultOperators .Aggregate((IStreamedDataInfo)SelectClause.GetOutputDataInfo(), (current, resultOperator) => resultOperator.GetOutputDataInfo(current)); if (ResultTypeOverride == null) { return(outputDataInfo); } try { return(outputDataInfo.AdjustDataType(ResultTypeOverride)); } catch (Exception ex) { var resultTypeOverride = ResultTypeOverride; ResultTypeOverride = null; throw new InvalidOperationException( string.Format( "The query model's result type cannot be changed to '{0}'. The result type may only be overridden and set to values compatible with the ResultOperators' current data type ('{1}').", resultTypeOverride, outputDataInfo.DataType), ex); } }
public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel) { ArgumentUtility.CheckNotNull("selectClause", selectClause); ArgumentUtility.CheckNotNull("queryModel", queryModel); var preparedExpression = _stage.PrepareSelectExpression(selectClause.Selector, _context); SqlStatementBuilder.SelectProjection = preparedExpression; SqlStatementBuilder.DataInfo = selectClause.GetOutputDataInfo(); }
public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel) { //SelectEntityClauseVisitor selectEntityClauseVisitor = new SelectEntityClauseVisitor(selectClause, queryModel); //foreach (var entity in selectEntityClauseVisitor.EntityAttributes.Keys) //{ // _queryMetadata.AddSelectAttributes(entity, selectEntityClauseVisitor.EntityAttributes[entity].ToArray()); //} var selectT = selectClause.GetOutputDataInfo(); _queryMetadata.ReturningType = selectT.ResultItemType; base.VisitSelectClause(selectClause, queryModel); }
/// <summary> /// Gets an <see cref="IStreamedDataInfo"/> object describing the data streaming out of this <see cref="QueryModel"/>. If a query ends with /// the <see cref="SelectClause"/>, this corresponds to <see cref="Clauses.SelectClause.GetOutputDataInfo"/>. If a query has /// <see cref="QueryModel.ResultOperators"/>, the data is further modified by those operators. /// </summary> /// <returns>Gets a <see cref="IStreamedDataInfo"/> object describing the data streaming out of this <see cref="QueryModel"/>.</returns> /// <remarks> /// The data streamed from a <see cref="QueryModel"/> is often of type <see cref="IQueryable{T}"/> instantiated /// with a specific item type, unless the /// query ends with a <see cref="ResultOperatorBase"/>. For example, if the query ends with a <see cref="CountResultOperator"/>, the /// result type will be <see cref="int"/>. /// </remarks> public IStreamedDataInfo GetOutputDataInfo() { var outputDataInfo = ResultOperators .Aggregate((IStreamedDataInfo)SelectClause.GetOutputDataInfo(), (current, resultOperator) => resultOperator.GetOutputDataInfo(current)); if (ResultTypeOverride != null) { return(outputDataInfo.AdjustDataType(ResultTypeOverride)); } else { return(outputDataInfo); } }
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); }
public void VisitSelectClause_CreatesSelectProjection() { var preparedExpression = new SqlTableReferenceExpression(SqlStatementModelObjectMother.CreateSqlTable(typeof(Cook))); _stageMock .Expect( mock => mock.PrepareSelectExpression( Arg <Expression> .Matches(e => e == _selectClause.Selector), Arg <ISqlPreparationContext> .Matches(c => c != _context))) .Return(preparedExpression); _stageMock.Replay(); _visitor.VisitSelectClause(_selectClause, _queryModel); _stageMock.VerifyAllExpectations(); Assert.That(_visitor.SqlStatementBuilder.SelectProjection, Is.SameAs(preparedExpression)); Assert.That(_visitor.SqlStatementBuilder.DataInfo, Is.TypeOf(typeof(StreamedSequenceInfo))); Assert.That(((StreamedSequenceInfo)_visitor.SqlStatementBuilder.DataInfo).DataType, Is.EqualTo(_selectClause.GetOutputDataInfo().DataType)); }
public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel) { model.SelectClause = selectClause.Selector; model.OutputDataInfo = selectClause.GetOutputDataInfo(); base.VisitSelectClause(selectClause, queryModel); }