当前位置: 首页>>代码示例>>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;未经允许,请勿转载。