EF - 种子功能不更新表

时间:2014-08-26 13:12:56

标签: asp.net entity-framework

在asp.net webform应用程序中,尝试在UPDATE-DATABASE命令之后将用户保存到AspNetUsers。以下代码不会这样做。解决方案?

        public Configuration()
        {
           AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(MyApp.Models.ApplicationDbContext context)
        {
            if (!context.Users.Any(u => u.Email == "some@mail"))
            {
                var store = new UserStore<ApplicationUser>(context);
                var manager = new UserManager<ApplicationUser>(store);
                var user = new ApplicationUser { Email = "some@mail" };

                manager.Create(user, "password");
            }
        }

1 个答案:

答案 0 :(得分:1)

要添加ApplicationUser,您必须初始化属性Username