代码首先使用MVC标识2.0进行初始创建

时间:2016-04-18 15:01:49

标签: asp.net-mvc entity-framework ef-code-first asp.net-identity

我正在使用

创建初始迁移
Add-Migration InitialCreate

但是当我从IdentityDbContext更新我的数据库表时,我没有创建异常。

那么如何从IdentityDbContext为AspNetUser表创建迁移?

关心teamol

1 个答案:

答案 0 :(得分:0)

您可以在IdentityModels.cs文件中的AspNetUser表中添加自定义字段。

首先在IdentityModels中将自定义值添加到ApplicationUser类:

namespace YourProjectName.Models
{
   public class ApplicationUser : IdentityUser
   {
       public string Email { get; set; }
       public string NameSurname { get; set; }
       public string ProfilePhotoRoute { get; set; }
       public string Title { get; set; }
   }

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

之后,在包管理器控制台中输入“Add-Migration NewMigration”命令。

最后,在包管理器控制台中输入“Update-Database”命令。

如果您在web.config中声明的连接字符串为true,则可以使用这种方式成功更新数据库。