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


C# Blog.GetCurrentSession方法代碼示例

本文整理匯總了C#中Blog.GetCurrentSession方法的典型用法代碼示例。如果您正苦於以下問題:C# Blog.GetCurrentSession方法的具體用法?C# Blog.GetCurrentSession怎麽用?C# Blog.GetCurrentSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Blog的用法示例。


在下文中一共展示了Blog.GetCurrentSession方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestBehaviour

        private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
        {
            using (new SessionScope()) {
                Post.DeleteAll();
                Blog.DeleteAll();
            }

            var originalDefaultFlushType = AR.Holder.ConfigurationSource.DefaultFlushType;
            try
            {
                AR.Holder.ConfigurationSource.Flush(flushType);

                var blog = new Blog(); // just for CurrentSession

                using (new SessionScope())
                {
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);

                    using (new TransactionScope())
                    {
                        Blog.FindAll();
                        Assert.AreEqual(transactionScopeMode, blog.GetCurrentSession().FlushMode);
                    }

                    // Properly reset?
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);
                }
            }
            finally
            {
                // Restore Default Flush type we corrupted before.
                AR.Holder.ConfigurationSource.Flush(originalDefaultFlushType);
            }
        }
開發者ID:shosca,項目名稱:ActiveRecord,代碼行數:36,代碼來源:ScopeDefaultFlushingBehaviourTestCase.cs

示例2: NestedTransactionScopesHaveCorrectTransactionContexts

        public void NestedTransactionScopesHaveCorrectTransactionContexts()
        {
            using (new TransactionScope())
            {
                var blog1 = new Blog();
                Blog.FindAll();

                var s1 = blog1.GetCurrentSession();
                var tx1 = s1.Transaction;
                Assert.IsNotNull(tx1);

                using (new TransactionScope())
                {
                    var blog2 = new Blog();
                    Blog.FindAll();
                    var s2 = blog2.GetCurrentSession();
                    var tx2 = s2.Transaction;

                    Assert.IsNotNull(tx2);
                    Assert.AreNotSame(tx1, tx2);

                    // TransactionScope uses a new session!
                    Assert.AreNotSame(s1, s2);
                }

                using (new TransactionScope(TransactionMode.Inherits))
                {
                    var blog3 = new Blog();
                    Blog.FindAll();
                    var tx3 = blog3.GetCurrentSession().Transaction;

                    Assert.IsNotNull(tx3);
                    Assert.AreSame(tx1, tx3);
                }

                Assert.IsTrue(tx1.IsActive);
            }

            using (new SessionScope())
            {
                var blog4 = new Blog();
                Blog.FindAll();

                using (new TransactionScope())
                {
                    var blog5 = new Blog();

                    Assert.AreSame(blog4.GetCurrentSession().Transaction, blog5.GetCurrentSession().Transaction);
                }
            }

            using (new SessionScope())
            {
                var blog6 = new Blog();
                var session = blog6.GetCurrentSession();

                Assert.IsNotNull(session.Transaction);
                var tx4 = session.Transaction;
                using (var tx5 = session.BeginTransaction())
                {
                    Assert.AreSame(tx4, tx5);
                    Blog.FindAll();

                    using (var tx6 = session.BeginTransaction())
                    {
                        Assert.AreSame(tx5, tx6);
                    }
                }
            }
        }
開發者ID:shosca,項目名稱:ActiveRecord,代碼行數:70,代碼來源:TransactionScopeTestCase.cs


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