本文整理匯總了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);
}