本文整理匯總了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));
}
示例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();
}
示例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.
}