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


C# Blog.Save方法代码示例

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


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

示例1: RollbackVote

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

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

			using(TransactionScope transaction = new TransactionScope())
			{
				Blog blog = new Blog();
				blog.Author = "hammett";
				blog.Name = "some name";
				blog.Save();

				Post post = new Post(blog, "title", "post contents", "Castle");
				post.Save();

				// pretend something went wrong

				transaction.VoteRollBack();
			}

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

			Post[] posts = Post.FindAll();
			Assert.AreEqual(0, posts.Length);
		}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:29,代码来源:TransactionScopeTestCase.cs

示例2: Prepare

		// overrides the setup in the base class
		public void Prepare()
		{
			ActiveRecordStarter.ResetInitializationFlag();
			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog), typeof(Post));

			ActiveRecordStarter.CreateSchema();

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

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

			blog.Save();

			Post p;

			p = new Post(blog, "a", "b", "c");
			p.Save();

			p = new Post(blog, "d", "e", "c");
			p.Save();

			p = new Post(blog, "f", "g", "h");
			p.Save();
		}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:28,代码来源:CountQueryTestCase.cs

示例3: SimpleOperations

		public void SimpleOperations()
		{
			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.Save();

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

			Blog retrieved = blogs[0];
			Assert.IsNotNull(retrieved);

			Assert.AreEqual(blog.Name, retrieved.Name);
			Assert.AreEqual(blog.Author, retrieved.Author);
		}
开发者ID:ralescano,项目名称:castle,代码行数:28,代码来源:ActiveRecordTestCase.cs

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

示例5: JoinedTable

		public void JoinedTable()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), 
				typeof(Post), 
				typeof(Blog), 
				typeof(Company), 
				typeof(Person));

			Recreate();

			Post.DeleteAll();
			Blog.DeleteAll();
			Company.DeleteAll();
			Person.DeleteAll();

			Blog blog = new Blog();
			blog.Name = "Ronalodo's blog";
			blog.Author = "Christiano Ronalodo";
			blog.Save();

			Person person = new Person();
			person.Name = "Ronaldo";
			person.FullName = new FullName();
			person.FullName.First = "Christiano";
			person.FullName.Last = "Ronaldo";
			person.Address = "123 Nutmeg";
			person.City = "Lisbon";
			person.Blog = blog;
			person.Save();

			Person[] people = Person.FindAll();
			Assert.AreEqual( 1, people.Length );

			Person personLoaded = people[0];

			Assert.AreEqual(person.Name, personLoaded.Name);
			Assert.AreEqual(person.FullName.First, personLoaded.FullName.First);
			Assert.AreEqual(person.FullName.Last, personLoaded.FullName.Last);
			Assert.AreEqual(person.Address, personLoaded.Address);
			Assert.AreEqual(person.City, personLoaded.City);
			Assert.AreEqual(blog.Id, personLoaded.Blog.Id);
			Assert.AreEqual(blog.Name, personLoaded.Blog.Name);

			personLoaded.FullName.Middle = "Goal";
			personLoaded.Address = "200 Hatrick";
			personLoaded.Update();

			people = Person.FindAll();
			Assert.AreEqual(1, people.Length);

			Person personUpdated = people[0];
			Assert.AreEqual(personLoaded.FullName.Middle, personUpdated.FullName.Middle);
			Assert.AreEqual(personLoaded.Address, personUpdated.Address);
		}
开发者ID:ralescano,项目名称:castle,代码行数:54,代码来源:JoinedTableTestCase.cs

示例6: AnExceptionInvalidatesTheScopeAndPreventItsFlushing

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

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

            Blog blog;
            Post post;

            // Prepare
            using(new SessionScope())
            {
                blog = new Blog();
                blog.Author = "hammett";
                blog.Name = "some name";
                blog.Save();

                post = new Post(blog, "title", "contents", "castle");
                post.Save();
            }

            using(SessionScope session = new SessionScope())
            {
                Assert.IsFalse(session.HasSessionError);

                try
                {
                    // Forcing an exception
                    post = new Post(new Blog(100), "title", "contents", "castle");
                    post.SaveAndFlush();
                    Assert.Fail("Expecting exception as this operation violates a FK constraint");
                }
                catch(ActiveRecordException)
                {
                    // Exception expected
                }

                Assert.IsTrue(session.HasSessionError);
            }
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:42,代码来源:SessionScopeTestCase.cs

示例7: 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:ralescano,项目名称:castle,代码行数:40,代码来源:DifferentDatabaseScopeTestCase.cs

示例8: ExecuteAndCallback

		public void ExecuteAndCallback()
		{
			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.Save();

			blogs = Blog.FindAll();

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

			blog.CustomAction();

			blogs = Blog.FindAll();

			Assert.IsNotNull(blogs);
			Assert.AreEqual(0, blogs.Length);
		}
开发者ID:ralescano,项目名称:castle,代码行数:30,代码来源:ActiveRecordTestCase.cs

示例9: DeleteAll

		public void DeleteAll()
		{
			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 blog1 = new Blog();
			blog1.Name = "hammett's blog";
			blog1.Author = "hamilton verissimo";
			blog1.Save();

			Blog blog2 = new Blog();
			blog2.Name = "richard's blog";
			blog2.Author = "g. richard bellamy";
			blog2.Save();

			blogs = Blog.FindAll();

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

			Blog.DeleteAll("Author = 'g. richard bellamy'");

			blogs = Blog.FindAll();

			Assert.IsNotNull(blogs);
			Assert.AreEqual(1, blogs.Length);
			Assert.AreEqual("hamilton verissimo", blogs[0].Author);

			blog1.Delete();

			blogs = Blog.FindAll();

			Assert.IsNotNull(blogs);
			Assert.AreEqual(0, blogs.Length);
		}
开发者ID:ralescano,项目名称:castle,代码行数:43,代码来源:ActiveRecordTestCase.cs

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

示例11: CreateBlog

        private static void CreateBlog()
        {
            var blog = new Blog {Author = "Henry", Name = "Senseless"};

            blog.Save();
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:6,代码来源:MultipleDatabasesTestCase.cs

示例12: SessionScopeFlushModeNever

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

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

			using(new SessionScope(FlushAction.Never))
			{
				Blog blog = new Blog();					
				blog.Author = "hammett";
				blog.Name = "some name";
				
				//This gets flushed automatically because of the identity field
				blog.Save();

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

				//This change won't be saved to the db
				blog.Author = "A New Author";
				blog.Save();

				//The change should not be in the db
				blogs = Blog.FindByProperty("Author", "A New Author");
				Assert.AreEqual(0, blogs.Length);
								
				SessionScope.Current.Flush();

				//The change should now be in the db
				blogs = Blog.FindByProperty("Author", "A New Author");
				Assert.AreEqual(1, blogs.Length);

				//This change will be save to the db because it uses the SaveNow method
				blog.Name = "A New Name";
				blog.SaveAndFlush();

				//The change should now be in the db
				blogs = Blog.FindByProperty("Name", "A New Name");
				Assert.AreEqual(1, blogs.Length);

				//This deletion should not get to the db
				blog.Delete();

				blogs = Blog.FindAll();
				Assert.AreEqual(1, blogs.Length);
				
				SessionScope.Current.Flush();

				//The deletion should now be in the db
				blogs = Blog.FindAll();
				Assert.AreEqual(0, blogs.Length);
			}
		}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:55,代码来源:SessionScopeTestCase.cs

示例13: ExistsByCriterion

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

			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.Save();

			Assert.IsTrue(blog.Id > 0);
			Assert.IsTrue(Blog.Exists(
			              	Expression.Eq("Name", blog.Name),
			              	Expression.Eq("Author", blog.Author)));

			blog = new Blog();
			blog.Name = "chad's blog";
			blog.Author = "chad humphries";
			blog.Save();

			Assert.IsTrue(Blog.Exists(
			              	Expression.Eq("Name", blog.Name),
			              	Expression.Eq("Author", blog.Author)));

			Assert.IsFalse(Blog.Exists(
			               	Expression.Eq("Name", "/\ndrew's Blog"),
			               	Expression.Eq("Author", "Andrew Peters")));
		}
开发者ID:ralescano,项目名称:castle,代码行数:34,代码来源:ActiveRecordTestCase.cs

示例14: TestName

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

			Blog blog = new Blog();
			blog.Name = null;
			blog.Author = "hamilton verissimo";
			blog.Save();

			Blog[] blogs = Blog.FindByProperty("Name", null);

			Assert.IsTrue(blogs.Length == 1);

			using(new SessionScope())
			{
				blog.Name = "Hammetts blog";
				blog.Save();
			}

			blogs = Blog.FindByProperty("Name", null);

			Assert.IsTrue(blogs.Length == 0);

			blogs = Blog.FindByProperty("Name", "Hammetts blog");

			Assert.IsTrue(blogs.Length == 1);
		}
开发者ID:ralescano,项目名称:castle,代码行数:29,代码来源:ActiveRecordTestCase.cs

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


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