当前位置: 首页>>代码示例>>C#>>正文


C# Blog.GetCurrentSession方法代码示例

本文整理汇总了C#中Castle.ActiveRecord.Tests.Model.Blog.GetCurrentSession方法的典型用法代码示例。如果您正苦于以下问题:C# Blog.GetCurrentSession方法的具体用法?C# Blog.GetCurrentSession怎么用?C# Blog.GetCurrentSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Castle.ActiveRecord.Tests.Model.Blog的用法示例。


在下文中一共展示了Blog.GetCurrentSession方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SequenceOfTransactions

        public void SequenceOfTransactions()
        {
            var conn = CreateSqlConnection2();
            ISession session1, session2;

            ITransaction trans1, trans2;
            using(new SessionScope())
            {
                using(new TransactionScope())
                {
                    var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                    blog.Save();

                    session1 = blog.GetCurrentSession();
                    Assert.IsNotNull(session1);
                    trans1 = session1.Transaction;
                    Assert.IsNotNull(trans1);
                    Assert.IsFalse(trans1.WasCommitted);
                    Assert.IsFalse(trans1.WasRolledBack);

                    conn.Open();

                    using(new DifferentDatabaseScope(conn))
                    {
                        blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                        blog.Save();

                        session2 = blog.GetCurrentSession();
                        Assert.IsNotNull(session2);
                        trans2 = session2.Transaction;
                        Assert.IsFalse( Object.ReferenceEquals(session1, session2) );

                        Assert.IsNotNull(session2.Transaction);
                        Assert.IsFalse(session2.Transaction.WasCommitted);
                        Assert.IsFalse(session2.Transaction.WasRolledBack);
                    }

                    using(new DifferentDatabaseScope(conn))
                    {
                        blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                        blog.Save();

                        session2 = blog.GetCurrentSession();
                        Assert.IsNotNull(session2);

                        Assert.IsFalse( Object.ReferenceEquals(session1, session2) );

                        Assert.IsNotNull(trans2);
                        Assert.IsFalse(trans2.WasCommitted);
                        Assert.IsFalse(trans2.WasRolledBack);
                    }
                }

                conn.Close();

                using(new TransactionScope())
                {
                    var blog = new Blog {Name = "another blog", Author = "erico verissimo"};
                    blog.Save();
                }
            }

            Assert.IsFalse(session1.IsOpen);
            Assert.IsFalse(session2.IsOpen);
            Assert.IsTrue(trans1.WasCommitted);
            Assert.IsFalse(trans1.WasRolledBack);
            Assert.IsTrue(trans2.WasCommitted);
            Assert.IsFalse(trans2.WasRolledBack);

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.IsNotNull(blogs);
                Assert.AreEqual(2, Blog.Count());

                var blogs2 = OtherDbBlog.FindAll().ToArray();
                Assert.IsNotNull(blogs2);
                Assert.AreEqual(2, OtherDbBlog.Count());
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:79,代码来源:DifferentDatabaseScopeTestCase.cs

示例2: UsingTransactionScopeWithRollback

        public void UsingTransactionScopeWithRollback()
        {
            SqlConnection conn = CreateSqlConnection2();
            ISession session1, session2;
            ITransaction trans1, trans2;

            using(TransactionScope scope = new TransactionScope())
            {
                Blog blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                blog.Save();

                session1 = blog.GetCurrentSession();
                trans1 = blog.GetCurrentSession().Transaction;
                Assert.IsNotNull(session1);
                Assert.IsNotNull(session1.Transaction);
                Assert.IsFalse(session1.Transaction.WasCommitted);
                Assert.IsFalse(session1.Transaction.WasRolledBack);

                blog.Evict();
                conn.Open();

                using(new DifferentDatabaseScope(conn))
                {
                    blog.Create();

                    session2 = blog.GetCurrentSession();
                    trans2 = blog.GetCurrentSession().Transaction;
                    Assert.IsNotNull(session2);

                    Assert.IsFalse( Object.ReferenceEquals(session1, session2) );

                    Assert.IsNotNull(session2.Transaction);
                    Assert.IsFalse(session2.Transaction.WasCommitted);
                    Assert.IsFalse(session2.Transaction.WasRolledBack);

                    scope.VoteRollBack();
                }
            }

            Assert.IsFalse(session1.IsOpen);
            Assert.IsFalse(session2.IsOpen);
            Assert.IsFalse(trans1.WasCommitted);
            Assert.IsTrue(trans1.WasRolledBack);
            Assert.IsFalse(trans2.WasCommitted);
            Assert.IsTrue(trans2.WasRolledBack);

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.IsNotNull( blogs );
                Assert.AreEqual(0, Blog.Count());

                var blogs2 = OtherDbBlog.FindAll().ToArray();
                Assert.IsNotNull( blogs2 );
                Assert.AreEqual(0, OtherDbBlog.Count());
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:56,代码来源:DifferentDatabaseScopeTestCase.cs

示例3: UsingSessionAndTransactionScope

        public void UsingSessionAndTransactionScope()
        {
            ISession session1, session2;
            using (var conn = CreateSqlConnection2()) {
                conn.Open();
                using (new SessionScope()) {
                    using (new TransactionScope()) {
                        var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                        blog.Save();

                        session1 = blog.GetCurrentSession();
                        Assert.IsNotNull(session1);
                        Assert.IsNotNull(session1.Transaction);
                        Assert.IsFalse(session1.Transaction.WasCommitted);
                        Assert.IsFalse(session1.Transaction.WasRolledBack);

                        using (new DifferentDatabaseScope(conn)) {
                            blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                            blog.Save();

                            session2 = blog.GetCurrentSession();
                            Assert.IsNotNull(session2);
                            Assert.IsFalse(Object.ReferenceEquals(session1, session2));

                            Assert.IsNotNull(session2.Transaction);
                            Assert.IsFalse(session2.Transaction.WasCommitted);
                            Assert.IsFalse(session2.Transaction.WasRolledBack);
                        }

                        using (new DifferentDatabaseScope(conn)) {
                            blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                            blog.Save();

                            session2 = blog.GetCurrentSession();
                            Assert.IsNotNull(session2);

                            Assert.IsFalse(Object.ReferenceEquals(session1, session2));

                            Assert.IsNotNull(session2.Transaction);
                            Assert.IsFalse(session2.Transaction.WasCommitted);
                            Assert.IsFalse(session2.Transaction.WasRolledBack);
                        }
                    }
                }
            }

            Assert.IsFalse(session1.IsOpen);
            Assert.IsFalse(session2.IsOpen);

            Assert.IsFalse(session1.Transaction.IsActive);
            Assert.IsFalse(session2.Transaction.IsActive);

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.IsNotNull(blogs);
                Assert.AreEqual(1, Blog.Count());

                var blogs2 = OtherDbBlog.FindAll().ToArray();
                Assert.IsNotNull(blogs2);
                Assert.AreEqual(2, OtherDbBlog.Count());
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:62,代码来源:DifferentDatabaseScopeTestCase.cs

示例4: UsingSessionScope

        public void UsingSessionScope()
        {
            ISession session1, session2;

            using (var conn = CreateSqlConnection2()) {
                conn.Open();

                using (new SessionScope()) {
                    Blog blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                    blog.Save();

                    session1 = blog.GetCurrentSession();
                    Assert.IsNotNull(session1);
                    blog.Evict();

                    using (new DifferentDatabaseScope(conn)) {
                        blog.Create();

                        session2 = blog.GetCurrentSession();
                        Assert.IsNotNull(session2);

                        Assert.IsFalse(Object.ReferenceEquals(session1, session2));
                    }
                }
            }

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.IsNotNull( blogs );
                Assert.AreEqual(1, Blog.Count());

                var blogs2 = OtherDbBlog.FindAll().ToArray();
                Assert.IsNotNull( blogs2 );
                Assert.AreEqual(1, OtherDbBlog.Count());
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:36,代码来源:DifferentDatabaseScopeTestCase.cs

示例5: SessionsAreDifferent

        public void SessionsAreDifferent()
        {
            using (new SessionScope())
            {
                var blog = new Blog();
                var author = new Author();

                AR.FindAll<Blog>();
                AR.FindAll<Author>();

                Assert.AreNotSame(blog.GetCurrentSession(), author.GetCurrentSession());
                Assert.AreNotEqual(
                    blog.GetCurrentSession().Connection.ConnectionString,
                    author.GetCurrentSession().Connection.ConnectionString);
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:16,代码来源:MultipleDBMediatorTest.cs


注:本文中的Castle.ActiveRecord.Tests.Model.Blog.GetCurrentSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。