本文整理汇总了C#中TestDataConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# TestDataConnection.BeginTransaction方法的具体用法?C# TestDataConnection.BeginTransaction怎么用?C# TestDataConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestDataConnection
的用法示例。
在下文中一共展示了TestDataConnection.BeginTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsDbGeneratedTest
public void IsDbGeneratedTest()
{
using (var db = new TestDataConnection())
{
db.BeginTransaction();
var id = db.InsertWithIdentity(new L2SPersons
{
FirstName = "Test",
LastName = "Test",
Gender = "M"
});
db.GetTable<L2SPersons>().Delete(p => p.PersonID == ConvertTo<int>.From(id));
}
}
示例2: AutoRollbackTransaction
public void AutoRollbackTransaction(string context)
{
using (var db = new TestDataConnection(context))
{
db.Insert(new Parent { ParentID = 1010, Value1 = 1010 });
try
{
using (db.BeginTransaction())
{
db.Parent.Update(t => t.ParentID == 1010, t => new Parent { Value1 = 1012 });
}
var p = db.Parent.First(t => t.ParentID == 1010);
Assert.That(p.Value1, Is.Not.EqualTo(1012));
}
finally
{
db.Parent.Delete(t => t.ParentID >= 1000);
}
}
}
示例3: Transaction
public void Transaction(string context)
{
using (var db = new TestDataConnection(context))
{
var list = new[]
{
new Parent { ParentID = 1111, Value1 = 1111 },
new Parent { ParentID = 2111, Value1 = 2111 },
new Parent { ParentID = 3111, Value1 = 3111 },
new Parent { ParentID = 4111, Value1 = 4111 },
};
foreach (var parent in list)
db.Parent.Delete(p => p.ParentID == parent.ParentID);
db.BeginTransaction();
db.BulkCopy(list);
db.CommitTransaction();
foreach (var parent in list)
db.Parent.Delete(p => p.ParentID == parent.ParentID);
}
}
示例4: CommitTransaction
public void CommitTransaction()
{
using (var db = new TestDataConnection())
{
db.Insert(new Parent { ParentID = 1010, Value1 = 1010 });
try
{
using (var tr = db.BeginTransaction())
{
db.Parent.Update(t => t.ParentID == 1010, t => new Parent { Value1 = 1011 });
tr.Commit();
}
var p = db.Parent.First(t => t.ParentID == 1010);
Assert.That(p.Value1, Is.EqualTo(1011));
}
finally
{
db.Parent.Delete(t => t.ParentID >= 1000);
}
}
}