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

原文地址:https://www.cnblogs.com/liandy0906/p/8464220.html