本文整理汇总了C#中Mono.Data.Sqlite.Orm.Tests.OrmTestSession.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# OrmTestSession.BeginTransaction方法的具体用法?C# OrmTestSession.BeginTransaction怎么用?C# OrmTestSession.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.Orm.Tests.OrmTestSession
的用法示例。
在下文中一共展示了OrmTestSession.BeginTransaction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertUsingSavePoints
public void InsertUsingSavePoints()
{
var obj = new TestObj { Text = "Matthew" };
using (var db = new OrmTestSession())
{
db.CreateTable<TestObj>();
using (var trans = db.BeginTransaction())
{
db.Insert(obj);
Assert.AreEqual(db.Table<TestObj>().Count(), 1);
trans.CreateSavepoint("First");
db.Insert(obj);
Assert.AreEqual(db.Table<TestObj>().Count(), 2);
trans.RollbackSavepoint("First");
trans.Commit();
}
Assert.AreEqual(db.Table<TestObj>().Count(), 1);
}
}
示例2: NestedTransactionsTest
public void NestedTransactionsTest()
{
var obj = new TestObj { Text = "Matthew" };
using (var db = new OrmTestSession())
{
db.CreateTable<TestObj>();
using (var trans1 = db.BeginTransaction())
{
trans1.CreateSavepoint("First");
db.Insert(obj);
using (var trans2 = db.BeginTransaction())
{
// rollback on the second trans affects the first as
// it is the same transaction
trans2.RollbackSavepoint("First");
}
Assert.AreEqual(db.Table<TestObj>().Count(), 0);
}
}
}
示例3: InsertAllWithinATransactionSucceeds
public void InsertAllWithinATransactionSucceeds()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
var first = new TestObj { Text = "First" };
var second = new TestObj { Text = "Second" };
var third = new TestObj { Text = "Third" };
using (var trans = db.BeginTransaction())
{
var inObjs = db.InsertAll(new[] { first, second, third }, false);
trans.Commit();
}
Assert.AreEqual(3, db.Table<TestObj>().Count());
}
示例4: InsertUsingSavePointsOnACommittedTransaction
public void InsertUsingSavePointsOnACommittedTransaction()
{
var obj = new TestObj { Text = "Matthew" };
using (var db = new OrmTestSession())
{
db.CreateTable<TestObj>();
var trans = db.BeginTransaction();
trans.CreateSavepoint("First");
trans.Commit();
#if SILVERLIGHT || MS_TEST
ExceptionAssert.Throws<SqliteException>(() => trans.RollbackSavepoint("First"));
#elif NETFX_CORE
Assert.ThrowsException<SqliteException>(() => trans.RollbackSavepoint("First"));
#else
Assert.Catch<SqliteException>(() => trans.RollbackSavepoint("First"));
#endif
}
}
示例5: NestedTransactionsTest
public void NestedTransactionsTest()
{
int oneTrans;
int nestedTrans;
// one transaction
using (var db = new OrmTestSession())
{
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
var start = Environment.TickCount;
const int n = 500*500;
IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {Text = "I am"});
TestObj[] objs = q.ToArray();
int numIn = db.InsertAll(objs);
oneTrans = Environment.TickCount - start;
}
// nested transactions
using (var db = new OrmTestSession())
{
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
var start = Environment.TickCount;
using (var trans = db.BeginTransaction())
{
for (var i = 0; i < 500; ++i)
{
const int n = 500;
IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {Text = "I am"});
TestObj[] objs = q.ToArray();
int numIn = db.InsertAll(objs);
}
trans.Commit();
}
nestedTrans = Environment.TickCount - start;
}
System.Diagnostics.Debug.WriteLine("Single tranasction: " + oneTrans);
System.Diagnostics.Debug.WriteLine("Nested tranasction: " + nestedTrans);
System.Diagnostics.Debug.WriteLine("Difference: " + Math.Abs(nestedTrans - oneTrans));
// this is a really dodgy test to use the execution time...
Assert.IsTrue(Math.Abs(oneTrans - nestedTrans) <= 100);
}