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


C# Blog.Create方法代码示例

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


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

示例1: MoreThanOneConnectionWithinTheSessionScope

        public void MoreThanOneConnectionWithinTheSessionScope()
        {
            using(var conn = CreateSqlConnection())
            using(var conn2 = CreateSqlConnection2())
            using(new SessionScope())
            {
                foreach(var connection in new [] { conn, conn2 })
                {
                    connection.Open();

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

            using (new SessionScope()) {
                var blogs2 = OtherDbBlog.FindAll().ToArray();
                Assert.IsNotNull( blogs2 );
                Assert.AreEqual( 1, blogs2.Length );

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

示例2: MoreThanOneConnectionWithinTheSessionScope

        public void MoreThanOneConnectionWithinTheSessionScope()
        {
            SqlConnection conn = CreateSqlConnection();
            SqlConnection conn2 = CreateSqlConnection2();

            using(new SessionScope())
            {
                foreach(SqlConnection connection in new SqlConnection[] { conn, conn2 })
                {
                    connection.Open();

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

            OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
            Assert.IsNotNull( blogs2 );
            Assert.AreEqual( 1, blogs2.Length );

            Blog[] blogs = Blog.FindAll();
            Assert.IsNotNull( blogs );
            Assert.AreEqual( 1, blogs.Length );
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:29,代码来源:DifferentDatabaseScopeTestCase.cs

示例3: SimpleCase

		public void SimpleCase()
		{
			Blog blog = new Blog();
			blog.Name = "hammett's blog";
			blog.Author = "hamilton verissimo";
			blog.Save();

			SqlConnection conn = CreateSqlConnection();

			using(conn)
			{
				conn.Open();

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

			Blog[] blogs = Blog.FindAll();
			Assert.IsNotNull( blogs );
			Assert.AreEqual( 1, blogs.Length );

			OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
			Assert.IsNotNull( blogs2 );
			Assert.AreEqual( 1, blogs2.Length );
		}
开发者ID:ralescano,项目名称:castle,代码行数:27,代码来源:DifferentDatabaseScopeTestCase.cs

示例4: FillData

        public void FillData()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog),typeof(Post));
            Recreate();

            for (int i = 1; i <= 10; i++)
            {
                var blog = new Blog(i) { Name = "n" + i };
                blog.Create();
            }
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:11,代码来源:ActiveRecordDetachedQueryTestCase.cs

示例5: SimpleOperations2

		public void SimpleOperations2()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
			Recreate();

			Post.DeleteAll();
			Blog.DeleteAll();

			Blog[] blogs = Blog.FindAll();

			Assert.IsNotNull(blogs);
			Assert.AreEqual(0, blogs.Length);

			Blog blog = new Blog();
			blog.Name = "hammett's blog";
			blog.Author = "hamilton verissimo";
			blog.Create();

			blogs = Blog.FindAll();
			Assert.AreEqual(blog.Name, blogs[0].Name);
			Assert.AreEqual(blog.Author, blogs[0].Author);

			Assert.IsNotNull(blogs);
			Assert.AreEqual(1, blogs.Length);

			blog.Name = "something else1";
			blog.Author = "something else2";
			blog.Update();

			blogs = Blog.FindAll();

			Assert.IsNotNull(blogs);
			Assert.AreEqual(1, blogs.Length);
			Assert.AreEqual(blog.Name, blogs[0].Name);
			Assert.AreEqual(blog.Author, blogs[0].Author);
		}
开发者ID:ralescano,项目名称:castle,代码行数:36,代码来源:ActiveRecordTestCase.cs

示例6: Query_by_example

        public void Query_by_example()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
            Recreate();

            Post.DeleteAll();
            Blog.DeleteAll();

            Blog[] blogs = Blog.FindAll();

            Assert.IsNotNull(blogs);
            Assert.AreEqual(0, blogs.Length);

            var blog = new Blog { Name = "hammett's blog", Author = "hamilton verissimo" };
            blog.Create();

            var count = Blog.FetchCount(Example.Create(new Blog { Name = "hammett" })
                                 				.EnableLike(MatchMode.Start)
                                 				.ExcludeNulls()
                                 				.ExcludeZeroes());
            Assert.AreEqual(1, count);
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:22,代码来源:ActiveRecordTestCase.cs

示例7: UsingTransactionScopeWithRollback

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

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

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

                conn.Open();

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

                    session2 = blog.CurrentSession;
                    trans2 = blog.CurrentSession.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);

            Blog[] blogs = Blog.FindAll();
            Assert.IsNotNull( blogs );
            Assert.AreEqual( 0, blogs.Length );

            OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
            Assert.IsNotNull( blogs2 );
            Assert.AreEqual( 0, blogs2.Length );
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:55,代码来源:DifferentDatabaseScopeTestCase.cs

示例8: UsingSessionScope

        public void UsingSessionScope()
        {
            ISession session1, session2;

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

                session1 = blog.CurrentSession;
                Assert.IsNotNull(session1);

                SqlConnection conn = CreateSqlConnection();

                using(conn)
                {
                    conn.Open();

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

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

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

            Blog[] blogs = Blog.FindAll();
            Assert.IsNotNull( blogs );
            Assert.AreEqual( 1, blogs.Length );

            OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
            Assert.IsNotNull( blogs2 );
            Assert.AreEqual( 1, blogs2.Length );
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:40,代码来源:DifferentDatabaseScopeTestCase.cs

示例9: UsingTransactionScope

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

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

                session1 = blog.GetCurrentSession();
                trans1 = blog.GetCurrentSession().Transaction;

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

                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);
                }
            }

            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( 1, Blog.Count());

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

示例10: 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

示例11: SimpleCase

        public void SimpleCase()
        {
            var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};

            using (new SessionScope()) {
                blog.Save();
            }

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

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

            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,代码行数:28,代码来源:DifferentDatabaseScopeTestCase.cs


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