public void TransformQueryModel_EmptyQueryModel()
        {
            var result = SqlPreparationQueryModelVisitor.TransformQueryModel(
                _queryModel, _context, _defaultStage, _generator, ResultOperatorHandlerRegistry.CreateDefault());

            Assert.That(result.SelectProjection, Is.TypeOf(typeof(NamedExpression)));
            Assert.That(result.WhereCondition, Is.Null);
            Assert.That(result.SqlTables.Count, Is.EqualTo(1));
            Assert.That(((SqlTable)result.SqlTables[0]).TableInfo, Is.InstanceOf(typeof(UnresolvedTableInfo)));
            Assert.That(result.TopExpression, Is.Null);
            Assert.That(result.IsDistinctQuery, Is.False);
        }
        public void TransformQueryModel_QueryModel_WithAdditionalClauses()
        {
            var constantExpression   = Expression.Constant(new Cook[0]);
            var additionalFromClause = new AdditionalFromClause("additional", typeof(int), constantExpression);

            _queryModel.BodyClauses.Add(additionalFromClause);
            _queryModel.BodyClauses.Add(ExpressionHelper.CreateWhereClause());
            _queryModel.ResultOperators.Add(new CountResultOperator());

            var result = SqlPreparationQueryModelVisitor.TransformQueryModel(
                _queryModel, _context, _defaultStage, _generator, ResultOperatorHandlerRegistry.CreateDefault());

            Assert.That(result.WhereCondition, Is.Not.Null);
            Assert.That(result.SqlTables.Count, Is.EqualTo(2));
        }
Example #3
0
        protected SqlCommandData GenerateSql(QueryModel queryModel)
        {
            var preparationContext            = SqlStatementModelObjectMother.CreateSqlPreparationContext();
            var uniqueIdentifierGenerator     = new UniqueIdentifierGenerator();
            var resultOperatorHandlerRegistry = ResultOperatorHandlerRegistry.CreateDefault();
            var sqlStatement = SqlPreparationQueryModelVisitor.TransformQueryModel(
                queryModel,
                preparationContext,
                new DefaultSqlPreparationStage(CompoundMethodCallTransformerProvider.CreateDefault(), resultOperatorHandlerRegistry, uniqueIdentifierGenerator),
                _generator,
                resultOperatorHandlerRegistry);

            var resolver = new MappingResolverStub();
            var mappingResolutionStage   = new DefaultMappingResolutionStage(resolver, uniqueIdentifierGenerator);
            var mappingResolutionContext = new MappingResolutionContext();
            var newSqlStatement          = mappingResolutionStage.ResolveSqlStatement(sqlStatement, mappingResolutionContext);

            var commandBuilder     = new SqlCommandBuilder();
            var sqlGenerationStage = new DefaultSqlGenerationStage();

            sqlGenerationStage.GenerateTextForOuterSqlStatement(commandBuilder, newSqlStatement);

            return(commandBuilder.GetCommand());
        }