示例#1
0
        public void Init()
        {
            DatabaseSetup(typeof(Blog), typeof(Post));

            using (var session = this.SessionFactory.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    var blog = new Blog { Name = "Stop worrying..." };
                    session.Save(blog);
                    session.Save(new Post { Blog = blog, Title = "... and start programming." });
                    session.Save(new Post { Blog = blog, Title = "... and start testing." });

                    tx.Commit();
                }
            }
        }
示例#2
0
 private Blog CreateBlog(int blogId, int postCount)
 {
     var blog = new Blog { Name = string.Format("Test blog #{0}", blogId) };
     blog.Posts = new HashSet<Post>();
     for (int i = 1; i <= postCount; i++)
     {
         blog.Posts.Add(new Post
         {
             Blog = blog,
             Title = string.Format("Post title #{0}", i),
             Body = string.Format("Post body #{0}", i),
         });
     }
     return blog;
 }