本文整理汇总了C#中Data.Linq.TestDbManager.CommitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# TestDbManager.CommitTransaction方法的具体用法?C# TestDbManager.CommitTransaction怎么用?C# TestDbManager.CommitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data.Linq.TestDbManager
的用法示例。
在下文中一共展示了TestDbManager.CommitTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transaction
public void Transaction()
{
foreach (var provider in Providers)
{
using (var db = new TestDbManager(provider.Name))
{
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.InsertBatch(list);
db.CommitTransaction();
foreach (var parent in list)
db.Parent.Delete(p => p.ParentID == parent.ParentID);
}
}
}
示例2: Transaction
public void Transaction([DataContexts(ExcludeLinqService = true)] string context, [Values(Int32.MaxValue, 1)]int batchSize)
{
using (var db = new TestDbManager(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.InsertBatch(batchSize, list);
db.CommitTransaction();
foreach (var parent in list)
db.Parent.Delete(p => p.ParentID == parent.ParentID);
}
}
示例3: TransactionWithIdentity1
public void TransactionWithIdentity1([DataContexts(ExcludeLinqService = true)] string context)
{
using (var db = new TestDbManager(context))
{
try
{
var list = new[]
{
new Table {IntValue = 1111, StringValue = "1111"},
new Table {IntValue = 2111, StringValue = "2111"},
new Table {IntValue = 3111, StringValue = "3111"},
new Table {IntValue = 4111, StringValue = "4111"},
};
db.GetTable<Table>().Delete(_ => _.Id > 2);
var c1 = db.GetTable<Table>().Count();
db.BeginTransaction();
db.InsertBatch(list);
db.CommitTransaction();
var c2 = db.GetTable<Table>().Count();
Assert.AreEqual(c1+4, c2);
}
finally
{
db.GetTable<Table>().Delete(_ => _.Id > 2);
}
}
}
示例4: TransactionWithIdentity2
public void TransactionWithIdentity2([DataContexts(ExcludeLinqService = true)] string context)
{
using (var db = new TestDbManager(context))
{
try
{
var list = new[]
{
new Table2 {IntValue = 1111, Object = new TestObject{Value = 1111}},
new Table2 {IntValue = 1111, Object = new TestObject{Value = 1111}},
new Table2 {IntValue = 1111, Object = new TestObject{Value = 1111}},
new Table2 {IntValue = 1111, Object = new TestObject{Value = 1111}},
};
db.GetTable<Table2>().Delete(_ => _.IntValue == 1111);
var c1 = db.GetTable<Table2>().Count();
db.BeginTransaction();
db.InsertBatch(list);
db.CommitTransaction();
var c2 = db.GetTable<Table2>().Count();
Assert.AreEqual(c1+4, c2);
var result = db.GetTable<Table2>().Where(_ => _.IntValue == 1111).ToList();
foreach (var e in result)
{
Assert.AreEqual(1111, e.Object.Value);
}
}
finally
{
db.GetTable<Table2>().Delete(_ => _.IntValue == 1111);
}
}
}