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(); } } }
public Repository(BlogEngineContext context) : base(context) { }
public ODataRepository(BlogEngineContext context) : base(context) { context.Configuration.ProxyCreationEnabled = false; }