Exemplo n.º 1
0
        private SqlCommandData GenerateSqlCommand(QueryModel queryModel)
        {
            ISqlPreparationContext    preparationContext       = new SqlPreparationContext(new SqlStatementBuilder());
            IMappingResolutionContext mappingResolutionContext = new MappingResolutionContext();

            var generator         = new UniqueIdentifierGenerator();
            var preparationStage  = new DefaultSqlPreparationStage(_methodCallTransformerProvider, _resultOperatorHandlerRegistry, generator);
            var preparedStatement = preparationStage.PrepareSqlStatement(queryModel, preparationContext);

            var resolutionStage   = new DefaultMappingResolutionStage(_mappingResolver, generator);
            var resolvedStatement = resolutionStage.ResolveSqlStatement(preparedStatement, mappingResolutionContext);

            var builder         = new SqlCommandBuilder();
            var generationStage = new DefaultSqlGenerationStage();

            generationStage.GenerateTextForOuterSqlStatement(builder, resolvedStatement);

            var command = builder.GetCommand();

            if (_showQuery)
            {
                Console.WriteLine(command.CommandText);
                Console.WriteLine(string.Join(", ", command.Parameters.Select(p => p.Name + "=" + p.Value)));
                Console.WriteLine(command.GetInMemoryProjection <object>());
            }
            return(command);
        }
        public void PrepareSqlStatement()
        {
            var queryModel = ExpressionHelper.CreateQueryModel <Cook>();

            var result = _stage.PrepareSqlStatement(queryModel, _context);

            Assert.That(result, Is.Not.Null);
        }
Exemplo n.º 3
0
        protected SqlCommandData GenerateSql(QueryModel queryModel)
        {
            var generator = new UniqueIdentifierGenerator();

            var resultOperatorHandlerRegistry = ResultOperatorHandlerRegistry.CreateDefault();
            var defaultSqlPreparationStage    = new DefaultSqlPreparationStage(CompoundMethodCallTransformerProvider.CreateDefault(), resultOperatorHandlerRegistry, generator);
            var sqlStatement = defaultSqlPreparationStage.PrepareSqlStatement(queryModel, null);

            var resolver = new MappingResolverStub();
            var mappingResolutionStage   = new DefaultMappingResolutionStage(resolver, generator);
            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());
        }