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