本文整理汇总了C#中Data.Linq.TestDbManager.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# TestDbManager.BeginTransaction方法的具体用法?C# TestDbManager.BeginTransaction怎么用?C# TestDbManager.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data.Linq.TestDbManager
的用法示例。
在下文中一共展示了TestDbManager.BeginTransaction方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: UserLinqInsert
public void UserLinqInsert()
{
using (var db = new TestDbManager("Oracle"))
{
db.BeginTransaction();
db.GetTable<User>().Insert(() => new User { Name = "user" });
}
}
示例3: UserInsertWithIdentity
public void UserInsertWithIdentity()
{
using (var db = new TestDbManager("Oracle"))
{
db.BeginTransaction();
db.InsertWithIdentity(new User { Name = "user" });
}
}
示例4: UserLinqInsert
public void UserLinqInsert([IncludeDataContexts("Oracle")] string context)
{
using (var db = new TestDbManager(context))
{
db.BeginTransaction();
db.GetTable<User>().Insert(() => new User { Name = "user" });
}
}
示例5: UserInsertWithIdentity
public void UserInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
{
using (var db = new TestDbManager(context))
{
db.BeginTransaction();
db.InsertWithIdentity(new User { Name = "user" });
}
}
示例6: IsDbGeneratedTest
public void IsDbGeneratedTest()
{
using (var db = new TestDbManager("Sql2008"))
{
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));
}
}
示例7: 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);
}
}
示例8: MyType3
public void MyType3()
{
using (var db = new TestDbManager { MappingSchema = _myMappingSchema })
{
db.BeginTransaction();
db.Insert(new MyParent { ParentID = new MyInt { MyValue = 1001 }, Value1 = 1001 });
db.Parent.Delete(p => p.ParentID >= 1000);
}
}
示例9: ContractInsert
public void ContractInsert()
{
using (var db = new TestDbManager("Oracle"))
{
db.BeginTransaction();
var user = new User { Name = "user" };
user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
db.Insert(new Contract { UserId = user.Id, ContractNo = 1, Name = "contract1" });
}
}
示例10: ContractLinqManyInsertWithIdentity
//[Test]
public void ContractLinqManyInsertWithIdentity()
{
using (var db = new TestDbManager("Oracle"))
{
db.BeginTransaction();
var user = new User { Name = "user" };
user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
db.GetTable<User>().InsertWithIdentity(db.GetTable<Contract>(), x => new Contract
{
UserId = x.Id, ContractNo = 1, Name = "contract"
});
}
}
示例11: 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);
}
}
}
示例12: 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);
}
}
}
示例13: ContractLinqInsertWithIdentity
public void ContractLinqInsertWithIdentity([IncludeDataContexts("Oracle")] string context)
{
using (var db = new TestDbManager(context))
{
db.BeginTransaction();
var user = new User { Name = "user" };
user.Id = Convert.ToInt64(db.InsertWithIdentity(user));
db.GetTable<Contract>().InsertWithIdentity(() => new Contract { UserId = user.Id, ContractNo = 1, Name = "contract" });
}
}