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


C# NpgsqlConnection.EnlistTransaction方法代码示例

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


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

示例1: ExplicitEnlist

 public void ExplicitEnlist()
 {
     using (var conn = new NpgsqlConnection(ConnectionString))
     using (var scope = new TransactionScope())
     {
         conn.Open();
         conn.EnlistTransaction(Transaction.Current);
         Assert.That(conn.ExecuteNonQuery(@"INSERT INTO data (name) VALUES('test')"), Is.EqualTo(1));
         scope.Complete();
     }
     AssertNoPreparedTransactions();
     using (var conn = OpenConnection())
         Assert.That(conn.ExecuteScalar(@"SELECT COUNT(*) FROM data"), Is.EqualTo(1));
 }
开发者ID:npgsql,项目名称:npgsql,代码行数:14,代码来源:SystemTransactionTests.cs

示例2: SimpleTransactionScopeWithExplicitEnlist

 public void SimpleTransactionScopeWithExplicitEnlist()
 {
     string connectionString = TheConnectionString;
     using (var connection = new NpgsqlConnection(connectionString)) {
         using (var scope = new TransactionScope()) {
             connection.Open();
             connection.EnlistTransaction(Transaction.Current);
             var command = new NpgsqlCommand("insert into tablea(field_text) values (:p0)", connection);
             command.Parameters.Add(new NpgsqlParameter("p0", "test"));
             Assert.AreEqual(1, command.ExecuteNonQuery());
             scope.Complete();
         }
     }
     AssertNoTransactions();
 }
开发者ID:pdonald,项目名称:Npgsql2,代码行数:15,代码来源:SystemTransactionsTest.cs

示例3: SimpleTransactionScopeWithExplicitEnlist

        public void SimpleTransactionScopeWithExplicitEnlist()
        {
            try
            {
                string connectionString = TheConnectionString;
                using (var connection = new NpgsqlConnection(connectionString))
                {
                    using (var scope = new TransactionScope())
                    {
                        connection.Open();
                        connection.EnlistTransaction(Transaction.Current);
                        var command = new NpgsqlCommand("insert into tablea(field_text) values (:p0)", connection);
                        command.Parameters.Add(new NpgsqlParameter("p0", "test"));
                        Assert.AreEqual(1, command.ExecuteNonQuery());
                        scope.Complete();
                    }
                }
                AssertNoTransactions();

                // Clean up data left in the last transaction.
                var cleanCommand = new NpgsqlCommand("delete from tablea where field_text = (:p0)", TheConnection);
                cleanCommand.Parameters.Add(new NpgsqlParameter("p0", "test"));
                Assert.AreEqual(1, cleanCommand.ExecuteNonQuery());

                // This transaction should commit.
                CommitTransaction = true;
            }
            catch (System.NotImplementedException) {}
            // Mono version below 3.0 doesn't implement transaction methods. So just ignore.
        }
开发者ID:jasonabi,项目名称:Npgsql2,代码行数:30,代码来源:SystemTransactionsTest.cs


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