向RegisterViewModel
添加了一个新字段:
[Required]
[Display(Name = "Name ")]
public string Name { get; set; }
在AccountController
中添加:
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
Name = model.Name
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
现在我想使用命令
创建一个迁移文件add-migration newFieldName
VS生成文件,但它是空的。
public partial class newFieldName : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
更新:ApplicationUser
课程
public class ApplicationUser : IdentityUser
{
[Required]
public string Name { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}