问题
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