我正在运行此代码来为我的数据库设定种子,但数据没有被写入。单独添加用户(在ForEach循环之外)时,它可以正常工作。是否有任何理由不起作用
List<String> usersList = GetAllUsers();
foreach (string s in usersList)
{
var newUser = new ApplicationUser();
newUser.UserName = s;
newUser.Email = s;
var userResult = UserManager.Create(newUser, "greenford");
//Add User Role Applicant
if (userResult.Succeeded)
{
var result = UserManager.AddToRole(newUser.Id, "Applicant");
}
}