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


C# Blog.Refresh方法代码示例

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


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

示例1: RelationsOneToManyWithWhereAndOrder

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

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

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

                post1.Published = false;
                post2.Published = false;
                post3.Published = true;

                post1.Save();
                Thread.Sleep(1000); // Its a smalldatetime (small precision)
                post2.Save();
                Thread.Sleep(1000); // Its a smalldatetime (small precision)
                post3.Save();

                blog = Blog.Find(blog.Id);
                blog.Refresh();

                Assert.IsNotNull(blog);
                Assert.AreEqual(2, blog.UnPublishedPosts.Count);
                Assert.AreEqual(1, blog.PublishedPosts.Count);

                Assert.AreEqual(3, blog.RecentPosts.Count);
                var recentposts = blog.RecentPosts.ToArray();
                Assert.AreEqual(post3.Id, recentposts[2].Id);
                Assert.AreEqual(post2.Id, recentposts[1].Id);
                Assert.AreEqual(post1.Id, recentposts[0].Id);
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:35,代码来源:ActiveRecordTestCase.cs

示例2: RelationsOneToMany

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

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

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

                post1.Save();
                post2.Save();
                blog.Refresh();

                var fromdb = Blog.Peek(blog.Id);

                Assert.IsNotNull(fromdb);
                Assert.IsNotNull(fromdb.Posts, "posts collection is null");
                Assert.AreEqual(2, Post.FindAll().Count());
                Assert.AreEqual(2, fromdb.Posts.Count);

                foreach (var post in fromdb.Posts) {
                    Assert.AreEqual(blog.Id, post.Blog.Id);
                }
            }
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:26,代码来源:ActiveRecordTestCase.cs


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