当前位置: 首页>>代码示例>>C#>>正文


C# SqlServerProcessor.CommitTransaction方法代码示例

本文整理汇总了C#中FluentMigrator.Runner.Processors.SqlServer.SqlServerProcessor.CommitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqlServerProcessor.CommitTransaction方法的具体用法?C# SqlServerProcessor.CommitTransaction怎么用?C# SqlServerProcessor.CommitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FluentMigrator.Runner.Processors.SqlServer.SqlServerProcessor的用法示例。


在下文中一共展示了SqlServerProcessor.CommitTransaction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanReadLongViewDefinition

        public void CanReadLongViewDefinition()
        {
            // Arrange
             var create = new CreateTableExpression
             {
            TableName = "Foo",
            Columns =
               new List<ColumnDefinition> { new ColumnDefinition { Name = "Id", Type = DbType.Int32 } }
             };

             IList<ViewDefinition> views;

             var createSql = new StringBuilder();
             createSql.Append("CREATE VIEW FooView As SELECT Id,");
             createSql.Append("'");
             createSql.Append(new string('A', 3000));
             createSql.Append("'");
             createSql.Append(" As LongText1,");
             createSql.Append("'");
             createSql.Append(new string('B', 3000));
             createSql.Append("'");
             createSql.Append(" As LongText2");
             createSql.Append(" FROM Foo");

             // Act
             using (var connection = new SqlConnection(ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            processor.Process(create);

            Assert.IsTrue(processor.TableExists(string.Empty, create.TableName), "SqlServer");

            processor.Execute(createSql.ToString());

            var dumper = new SqlServerSchemaDumper(processor, new DebugAnnouncer());
            views = dumper.ReadViewSchema();

            processor.CommitTransaction();
             }

             // Assert

             Assert.AreEqual(1, views.Count);
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:45,代码来源:SchemaDumpViewTests.cs

示例2: VersionInfoCreationScriptsOnlyGeneratedOnceInPreviewMode

        public void VersionInfoCreationScriptsOnlyGeneratedOnceInPreviewMode()
        {
            if (!IntegrationTestOptions.SqlServer2008.IsEnabled)
                return;

            var connection = new SqlConnection(IntegrationTestOptions.SqlServer2008.ConnectionString);
            var processorOptions = new ProcessorOptions { PreviewOnly = true };

            var outputSql = new StringWriter();
            var announcer = new TextWriterAnnouncer(outputSql){ ShowSql = true };

            var processor = new SqlServerProcessor(connection, new SqlServer2008Generator(), announcer, processorOptions, new SqlServerDbFactory());

            try
            {
                var asm = typeof(MigrationRunnerTests).Assembly;
                var runnerContext = new RunnerContext(announcer)
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations",
                    PreviewOnly = true
                };

                var runner = new MigrationRunner(asm, runnerContext, processor);
                runner.MigrateUp(1, false);

                processor.CommitTransaction();

                string schemaName = new TestVersionTableMetaData().SchemaName;
                var schemaAndTableName = string.Format("\\[{0}\\]\\.\\[{1}\\]", schemaName, TestVersionTableMetaData.TABLENAME);

                var outputSqlString = outputSql.ToString();

                var createSchemaMatches = new Regex(string.Format("CREATE SCHEMA \\[{0}\\]", schemaName)).Matches(outputSqlString).Count;
                var createTableMatches = new Regex("CREATE TABLE " + schemaAndTableName).Matches(outputSqlString).Count;
                var createIndexMatches = new Regex("CREATE UNIQUE CLUSTERED INDEX \\[" + TestVersionTableMetaData.UNIQUEINDEXNAME + "\\] ON " + schemaAndTableName).Matches(outputSqlString).Count;
                var alterTableMatches = new Regex("ALTER TABLE " + schemaAndTableName).Matches(outputSqlString).Count;

                System.Console.WriteLine(outputSqlString);

                createSchemaMatches.ShouldBe(1);
                createTableMatches.ShouldBe(1);
                alterTableMatches.ShouldBe(2);
                createIndexMatches.ShouldBe(1);

            }
            finally
            {
                CleanupTestSqlServerDatabase(connection, processor);
            }
        }
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:50,代码来源:MigrationRunnerTests.cs

示例3: ExecuteMigrations

        /// <summary>
        /// Creates tables in source oracle database and asserts that they exist
        /// </summary>
        /// <param name="expressions">The tables to be created</param>
        private void ExecuteMigrations(params IMigrationExpression[] expressions)
        {
            if (expressions == null)
            return;

             using (var connection = new SqlConnection(_source.ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            foreach (var expression in expressions)
            {
                if (expression is CreateTableExpression)
                {
                    var create = (CreateTableExpression)expression;
                    processor.Process(create);
                    Assert.IsTrue(processor.TableExists(string.Empty, create.TableName), "Source " + create.TableName);
                }

                if (expression is CreateForeignKeyExpression)
                {
                    processor.Process((CreateForeignKeyExpression)expression);
                }

                if (expression is InsertDataExpression)
                {
                    processor.Process((InsertDataExpression)expression);
                }
            }

            processor.CommitTransaction();
             }
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:36,代码来源:SqlServerMigrationTests.cs

示例4: CreateViews

        /// <summary>
        /// Creates views in Oracle using the <see cref="ViewDefinition.CreateViewSql"/>
        /// </summary>
        /// <param name="view">The views to be created</param>
        private void CreateViews(params ViewDefinition[] view)
        {
            using (var connection = new SqlConnection(_source.ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            foreach (var viewDefinition in view)
            {
               processor.Execute(viewDefinition.CreateViewSql);
            }

            processor.CommitTransaction();
             }
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:18,代码来源:SqlServerMigrationTests.cs

示例5: GetTableColumnColumns

        /// <summary>
        /// Creates a single column table using the spplied type and retruns its <see cref="ColumnDefinition"/>
        /// </summary>
        /// <param name="type">The Sql Server data type to apply to the column</param>
        /// <returns>The translated <see cref="ColumnDefinition"/></returns>
        private TableDefinition GetTableColumnColumns(string createSql, string name, params IMigrationExpression[] expresions)
        {
            IList<TableDefinition> tables;

              // Act
              using (var connection = new SqlConnection(ConnectionString))
              {
              var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

              if (!string.IsNullOrEmpty(createSql))
                  processor.Execute(createSql);

              foreach (var expresion in expresions)
              {
                  if (expresion is CreateTableExpression)
                      processor.Process((CreateTableExpression)expresion);
                  if (expresion is CreateIndexExpression)
                      processor.Process((CreateIndexExpression)expresion);
                  if (expresion is CreateForeignKeyExpression)
                      processor.Process((CreateForeignKeyExpression)expresion);
              }

              Assert.IsTrue(processor.TableExists(string.Empty, name), "SqlServer");

              var dumper = new SqlServerSchemaDumper(processor, new DebugAnnouncer());
              tables = dumper.ReadDbSchema();

              processor.CommitTransaction();
              }

              if (!string.IsNullOrEmpty(createSql))
              tables.Count.ShouldBe(1);

              return tables.Where(t => t.Name == name).FirstOrDefault();
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:40,代码来源:SchemaDumpTableTests.cs

示例6: CreateTables

        /// <summary>
        /// Creates tables in SQL Server and asserts that they exist
        /// </summary>
        /// <param name="createTables">The tables to be created</param>
        private void CreateTables(params CreateTableExpression[] createTables)
        {
            if (createTables == null)
            return;

             using (var connection = new SqlConnection(_sqlContext.ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            foreach (var create in createTables)
            {
               processor.Process(create);
               Assert.IsTrue(processor.TableExists(string.Empty, create.TableName), "SqlServer " + create.TableName);
            }

            processor.CommitTransaction();
             }
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:22,代码来源:SqlServerToOracleMigrationTests.cs

示例7: CreateIndexes

        /// <summary>
        /// Migrates a set of tables using the provided context
        /// </summary>
        /// <param name="indexes">The indexes to be created in SQL Server and migrated to Oracle</param>
        private void CreateIndexes(params CreateIndexExpression[] indexes)
        {
            using (var connection = new SqlConnection(_sqlContext.ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            foreach (var index in indexes)
            {
               processor.Process(index);
            }

            processor.CommitTransaction();
             }
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:18,代码来源:SqlServerToOracleMigrationTests.cs

示例8: MigrateToOracleWithData

        /// <summary>
        /// Migrates tables from SQL Server to Oracle and queries the data in the new Oracle table
        /// </summary>
        /// <param name="expressions">The expressions to execute as part of the migration</param>
        /// <param name="expectedMigrations">The number of migrations that should be created</param>
        /// <param name="contextAction">Delegates that alter the context before the migration is executed</param>
        /// <returns>The data in the new Oracle table</returns>
        private DataSet MigrateToOracleWithData(IEnumerable<IMigrationExpression> expressions, int expectedMigrations, params Action<SchemaMigrationContext>[] contextAction)
        {
            var context = GetDefaultContext();
             context.GenerateAlternateMigrationsFor.Add(DatabaseType.Oracle);
             context.Type = context.Type | MigrationType.Data;

             if (contextAction != null)
             {
            foreach (var action in contextAction)
            {
               action(context);
            }
             }

             CreateTableExpression create = null;

             using (var connection = new SqlConnection(_sqlContext.ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            foreach (var action in expressions)
            {
               if (action is CreateTableExpression)
               {
                  create = (CreateTableExpression) action;
                  processor.Process(create);
                  Assert.IsTrue(processor.TableExists(string.Empty, create.TableName), "SqlServer " + create.TableName);
                  continue;
               }

               if (action is InsertDataExpression)
               {
                  var insert = (InsertDataExpression)action;
                  processor.Process(insert);
                  continue;
               }

               if (action is CreateIndexExpression)
               {
                  var index = (CreateIndexExpression)action;
                  processor.Process(index);
                  continue;
               }

               if (action is CreateForeignKeyExpression)
               {
                   var index = (CreateForeignKeyExpression)action;
                   processor.Process(index);
                   continue;
               }
            }

            processor.CommitTransaction();
             }

             MigrateTable(context);

             if (create != null)
            AssertOracleTablesExist(create);

             context.MigrationIndex.ShouldBe(expectedMigrations);

             return create != null ? GetOracleTableData(create.TableName) : null;
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:71,代码来源:SqlServerToOracleMigrationTests.cs

示例9: CanReadMultipleViews

        public void CanReadMultipleViews()
        {
            // Arrange
             var create = new CreateTableExpression
             {
            TableName = "Foo",
            Columns =
               new List<ColumnDefinition> { new ColumnDefinition { Name = "Id", Type = DbType.Int32 } }
             };

             IList<ViewDefinition> views;

             // Act
             using (var connection = new SqlConnection(ConnectionString))
             {
            var processor = new SqlServerProcessor(connection, new SqlServer2005Generator(), new DebugAnnouncer(), new ProcessorOptions());

            processor.Process(create);

            Assert.IsTrue(processor.TableExists(string.Empty, create.TableName), "SqlServer");

            processor.Execute("CREATE VIEW FooViewC AS SELECT Id FROM Foo");
            processor.Execute("CREATE VIEW FooViewB AS SELECT Id FROM Foo");
            processor.Execute("CREATE VIEW FooViewA AS SELECT Id FROM Foo");

            var dumper = new SqlServerSchemaDumper(processor, new DebugAnnouncer());
            views = dumper.ReadViewSchema();

            processor.CommitTransaction();
             }

             // Assert

             Assert.AreEqual(3, views.Count);

             Assert.AreEqual("FooViewA", views[0].Name);
             Assert.AreEqual("FooViewB", views[1].Name);
             Assert.AreEqual("FooViewC", views[2].Name);
        }
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:39,代码来源:SchemaDumpViewTests.cs


注:本文中的FluentMigrator.Runner.Processors.SqlServer.SqlServerProcessor.CommitTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。