當前位置: 首頁>>代碼示例>>C#>>正文


C# OrmTestSession.BeginTransaction方法代碼示例

本文整理匯總了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);
            }
        }
開發者ID:mattleibow,項目名稱:Mono.Data.Sqlite.Orm,代碼行數:25,代碼來源:TransactionsTest.cs

示例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);
                }
            }
        }
開發者ID:mattleibow,項目名稱:Mono.Data.Sqlite.Orm,代碼行數:24,代碼來源:TransactionsTest.cs

示例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());
        }
開發者ID:mattleibow,項目名稱:Mono.Data.Sqlite.Orm,代碼行數:17,代碼來源:InsertTest.cs

示例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
            }
        }
開發者ID:mattleibow,項目名稱:Mono.Data.Sqlite.Orm,代碼行數:21,代碼來源:TransactionsTest.cs

示例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);
        }
開發者ID:distributedlife,項目名稱:Mono.Data.Sqlite.Orm,代碼行數:52,代碼來源:InsertTest.cs


注:本文中的Mono.Data.Sqlite.Orm.Tests.OrmTestSession.BeginTransaction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。