Code First Migrations to update the table

1.模型类User

    public class User
    {
        [Key]
        public string Username { get; set; }
        public string DisplayName { get; set; } 
    }

2.修改DbContext

    public class BaseDbContext:DbContext
    {
        private static readonly string Connection = ConfigurationManager.AppSettings["DbConnection"].ToString();
        public BaseDbContext()
            : base(Connection)
        {
            this.Database.CreateIfNotExists();
        }
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }
        //新增
        public DbSet<User> Users { get; set; } 
    }

3.在程序包管理器控制执行指令 Enable-Migrations

4.Add-Migration AddUser

5.Update-Database

posted @ 2018-02-24 09:56  连先森  阅读(93)  评论(0编辑  收藏  举报