本文整理汇总了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.
}