EF 种子方法不保存自定义身份用户

EF seed method does not save custom Identity user

使用这个 Tutorial 我尝试在我的网络 API 应用程序中实现身份系统,所以我自定义 UserIdentityUserManager 并在 Seed 方法中EF,尝试像这样生成样本数据:

var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new MedicalContext()));            
        var appUsers = new List<ApplicationUser>
        {
            new ApplicationUser{FirstName="admin",LastName="admin",UserName="admin",Email = "taiseer.joudeh@gmail.com",EmailConfirmed = true,DivisionID=1,Division=divisions[0],PhoneNumber="876543"},
            new ApplicationUser{FirstName="Mahdi",LastName="Mahdavi",UserName="mahdi",Email = "LKJHGF.joudeh@gmail.com",EmailConfirmed = true,DivisionID=0,Division=divisions[1],PhoneNumber="98765434567"}
        };
        var adminresult = manager.Create(appUsers[0], "admin");

如果我使用 admin 密码用户创建失败,因为使用少于 6 个字符的密码和我的 Seed 方法的其余部分 运行。但是,当使用 Correct Pass 时,我的应用程序卡在 Create UserManager 的方法中并且 Seed 的其余部分没有任何异常 运行。(它似乎卡在一个循环或其他东西中)

终于我找到了....我应该替换这个:

var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new MedicalContext()));

用这个:

var store = new UserStore<ApplicationUser>(context);
var manager = new UserManager(store);