Ejemplo n.º 1
0
        public void Run()
        {
            //若Model发生改变,则自动更新数据库.
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<BlogEngineContext, Configuration>());

            using (var context = new BlogEngineContext())
            {
                if (!context.Database.Exists())
                {
                    //初始化数据
                    var user = CreateUser();
                    var channel = CreateChannel();
                    var group = CreateGroup(channel);
                    var post = CreatePost(user, group);
                    var comment = CreateComment(post);
                    var board = CreateBoard();

                    //保存数据
                    context.Set<User>().Add(user);
                    context.Set<Channel>().Add(channel);
                    context.Set<Group>().Add(group);
                    context.Set<Post>().Add(post);
                    context.Set<Comment>().Add(comment);
                    context.Set<Board>().Add(board);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
 public Repository(BlogEngineContext context)
     : base(context)
 {
 }
Ejemplo n.º 3
0
 public ODataRepository(BlogEngineContext context)
     : base(context)
 {
     context.Configuration.ProxyCreationEnabled = false;
 }