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); } } }
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); } }
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); } } }
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); } } }