Adding properties to IdentityUser doesn't create the correct migration

流过昼夜 提交于 2020-01-05 07:45:21

问题


I've followed the tutorial here: Customizing profile information in ASP.NET Identity in VS 2013 templates

And did exactly what's written there, except for that my new property is a string named 'TaxId'. Surprisingly, when I did the "Add-Migration" part, the migration file came up empty:

namespace Mvc5Test.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class TaxId : DbMigration
    {
        public override void Up()
        {
        }

        public override void Down()
        { 
        }
    }
}

Any idea why did it happen and what's the right way to fix it? (I'd like to avoid updating the migration file manually...)

EDIT:

public class ApplicationUser : IdentityUser
{
    public string TaxId { get; set; }
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }
}

回答1:


Problem was that I've already had my own DB context. Used this solution, taken from here.

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

    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }

}


来源:https://stackoverflow.com/questions/27676437/adding-properties-to-identityuser-doesnt-create-the-correct-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!