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


C# Blog.Save方法代码示例

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


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

示例1: FetchEnum_Join_on_a_HasMany_property_should_not_return_duplicate_records

        public void FetchEnum_Join_on_a_HasMany_property_should_not_return_duplicate_records()
        {
            Blog[] blogs = Blog.FindAll();

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

            var blog = new Blog() { Name = "Test blog", Author = "Eric Bowen" };

            blog.Save();

            var post = new Post(blog, "Post1", "Content1", "Category1");
            post.Save();

            blog.Posts.Add(post);

            var post2 = new Post(blog, "Post2", "Content2", "Category2");
            post2.Save();

            blog.Posts.Add(post2);

            blog.Save();

            blogs = Blog.FindAll();

            Assert.IsNotNull(blogs);
            Assert.AreEqual(1, blogs.Length);
        }
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:28,代码来源:FetchTestCase.cs

示例2: SimpleOperations

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

			Recreate();


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

			var blogs = from b in Blog.Queryable select b;

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

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


			blogs = from b in Blog.Queryable select b;
			Assert.IsNotNull(blogs);
			Assert.AreEqual(1, blogs.Count());

			var retrieved = Blog.Queryable.First();
			Assert.IsNotNull(retrieved);

			Assert.AreEqual(blog.Name, retrieved.Name);
			Assert.AreEqual(blog.Author, retrieved.Author);

		}
开发者ID:oillio,项目名称:Castle.ActiveRecord,代码行数:34,代码来源:ActiveRecordLinqTestCase.cs

示例3: SimpleOperations

		public void SimpleOperations()
		{
			Assert.IsTrue(NHibernate.Cfg.Environment.UseReflectionOptimizer);

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

示例4: AnExceptionInvalidatesTheScopeAndPreventItsFlushing

        public void AnExceptionInvalidatesTheScopeAndPreventItsFlushing()
        {
            using (new SessionScope()) {
                Post.DeleteAll();
                Blog.DeleteAll();
            }

            Post post;

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

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

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

                Assert.Throws<ActiveRecordException>(() => {
                    post = new Post(new Blog(100), "title", "contents", "castle");
                    post.Save();
                    session.Flush();
                });

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

示例5: ModifyAndThrowException

		public virtual void ModifyAndThrowException(Blog blog, String newName)
		{
			blog.Name = newName;
			
			blog.Save();

			throw new Exception("Doh!");
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:8,代码来源:BlogService.cs

示例6: Create

		public virtual Blog Create(String name, String author)
		{
			Blog blog = new Blog();
			blog.Name = name;
			blog.Author = author;
			blog.Save();
			return blog;
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:8,代码来源:BlogService.cs

示例7: CreateAndThrowException

		public virtual Blog CreateAndThrowException(String name, String author)
		{
			Blog blog = new Blog();
			blog.Name = name;
			blog.Author = author;
			blog.Save();

			throw new Exception("Doh!");
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:9,代码来源:BlogService.cs

示例8: Init

		public new void Init()
		{
			ActiveRecordStarter.ResetInitializationFlag();

			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog), typeof(Post));

			Recreate();

			var blog = new Blog() { Author = "Horatio", Name = "Murmurs" };
			blog.Save();

			var post = new Post(blog, "To Be Or Not To Be", "Nonsense", "monologues");
			post.Save();
		}
开发者ID:ralescano,项目名称:castle,代码行数:14,代码来源:ScalarQueryTestCase.cs

示例9: BlogExistsCriterionOverload

        public void BlogExistsCriterionOverload()
        {
            using (new SessionScope()) {

                var blog = new Blog {Author = "Dr. Who", Name = "Exaggerated Murmuring"};
                blog.Save();

                Assert.IsTrue(
                    Blog.Exists(
                        Restrictions.Like("Author", "Who", MatchMode.Anywhere)
                        )
                    );
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:14,代码来源:ActiveRecordTestCase.cs

示例10: Back_To_Basics

        public void Back_To_Basics()
        {
            // first we have a blog
            var blog = new Blog();

            // then we write up a blog post
            var post = new Post
            {
                Author = "bling",
                Content = "All your base are belong to us."
            };

            // finally we have to save it
            blog.Save(post);
        }
开发者ID:bling,项目名称:AdvancedIocTechniques,代码行数:15,代码来源:01.cs

示例11: CreateNewBlog

        /// <summary>
        /// Creates new blog
        /// </summary>
        /// <param name="blogName">Name of the blog</param>
        /// <param name="userName">Name of the first user which will be set up as blog admin</param>
        /// <param name="email">Email address</param>
        /// <param name="password">Password</param>
        /// <param name="message">Return message</param>
        /// <returns>New blog object</returns>
        public static Blog CreateNewBlog(string blogName, string userName, string email, string password, out string message)
        {
            message = null;
            blogName = blogName.Trim();

            if (!ValidateProperties(blogName, userName, email, out message))
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    message = "Validation for new blog failed.";
                }
                return null;
            }

            Blog newBlog = new Blog()
            {
                Name = blogName,
                StorageContainerName = blogName.ToLower(),
                Hostname = "",
                IsAnyTextBeforeHostnameAccepted = true,
                VirtualPath = "~/" + blogName.ToLower(),
                IsActive = true,
                IsSiteAggregation = false
            };

            bool setupResult = false;
            try
            {
                setupResult = BlogService.SetupNewBlog(newBlog, userName, email, password);
            }
            catch (Exception ex)
            {
                Utils.Log("BlogGenerator.CreateNewBlog", ex);
                message = "Failed to create new blog. Error: " + ex.Message;
                return null;
            }

            if (!setupResult)
            {
                message = "Failed during process of setting up new blog instance.";
                return null;
            }

            // save the blog for the first time.
            newBlog.Save();

            return newBlog;
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:57,代码来源:BlogGenerator.cs

示例12: SlicedOperation

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

			Post post1 = new Post(blog, "title1", "contents", "category1");
			Post post2 = new Post(blog, "title2", "contents", "category2");
			Post post3 = new Post(blog, "title3", "contents", "category3");

			post1.Save();
			post2.Save();
			post3.Published = true;
			post3.Save();
            Post[] posts = Post.CustomSlicedFind(Expression.Eq("Blog", blog), 1, 2);
			Assert.AreEqual(2, posts.Length);
		}
开发者ID:ralescano,项目名称:castle,代码行数:18,代码来源:ActiveRecordBaseGenericsTestCase.cs

示例13: DifferentSessionScopesUseDifferentCaches

        public void DifferentSessionScopesUseDifferentCaches()
        {
            using (new SessionScope()) {
                Post.DeleteAll();
                Blog.DeleteAll();
            }

            var blogId = 0;

            using (new SessionScope())
            {
                var blog = new Blog {Author = "MZY", Name = "FooBar"};
                blog.Save(); // Flushes due to IDENTITY
                blogId = blog.Id;
            }

            using (new SessionScope())
            {
                var blog = Blog.Find(blogId);
                blog.Name = "FooBarBaz";

                //Assert.AreEqual(FlushMode.Auto, blog.CurrentSession.FlushMode);
                //Assert.IsTrue(blog.CurrentSession.Transaction.IsActive);
                Assert.AreEqual(DefaultFlushType.Auto, AR.Holder.ConfigurationSource.DefaultFlushType);

                // Flushes automatically
                Assert.AreEqual(1, Blog.FindAllByProperty("Name", "FooBarBaz").Count());
            }

            using (new SessionScope())
            {
                var blog = Blog.Find(blogId);
                blog.Name = "FooBar";

                using (new SessionScope())
                {
                    // Will use parent's sessions
                    Assert.AreEqual(1, Blog.FindAllByProperty("Name", "FooBar").Count());
                }
            }
            // Here it is flushed
            using (new SessionScope())
                Assert.AreEqual(1, Blog.FindAllByProperty("Name", "FooBar").Count());
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:44,代码来源:SessionScopeTestCase.cs

示例14: CommitVote

        public void CommitVote()
        {
            using(new TransactionScope())
            {
                var blog = new Blog {Author = "hammett", Name = "some name"};
                blog.Save();

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

                // Default to VoteCommit
            }

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

                var posts = Post.FindAll().ToArray();
                Assert.AreEqual(1, posts.Length);
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:21,代码来源:TransactionScopeTestCase.cs

示例15: DoesGeneratedCodeWork

        public void DoesGeneratedCodeWork()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), 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();

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

            Post post = new Post();
            post.Category = "Castle";
            post.Content = "The content.";
            post.Title = "The title.";
            post.Blog = retrieved;
            post.Save();
            retrieved.Posts.Add(post);
            retrieved.Save();

            Blog retrievedHasMany = Blog.FindAll()[0];
            Assert.AreEqual(retrievedHasMany.Posts.Count, 1);
            Assert.AreEqual(retrievedHasMany.Posts[0].Id, post.Id);
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:38,代码来源:GeneratedCodeRuntimeTest.cs


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