當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。