Asp.net mvc 将属性添加到IdentityUser不会';t创建正确的迁移
我在这里遵循了教程: 并且完全按照上面写的做了,除了我的新属性是一个名为“TaxId”的字符串。令人惊讶的是,当我执行“添加迁移”部分时,迁移文件显示为空:Asp.net mvc 将属性添加到IdentityUser不会';t创建正确的迁移,asp.net-mvc,entity-framework,asp.net-mvc-5,entity-framework-migrations,Asp.net Mvc,Entity Framework,Asp.net Mvc 5,Entity Framework Migrations,我在这里遵循了教程: 并且完全按照上面写的做了,除了我的新属性是一个名为“TaxId”的字符串。令人惊讶的是,当我执行“添加迁移”部分时,迁移文件显示为空: namespace Mvc5Test.Migrations { using System; using System.Data.Entity.Migrations; public partial class TaxId : DbMigration { public override void
namespace Mvc5Test.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class TaxId : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
}
你知道为什么会发生这种情况吗?正确的解决方法是什么?(我希望避免手动更新迁移文件…)
编辑:
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;
}
}
公共类应用程序用户:IdentityUser
{
公共字符串TaxId{get;set;}
公共异步任务GenerateUserIdentityAsync(用户管理器)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
返回用户身份;
}
}
问题是我已经有了自己的数据库上下文。
使用此解决方案,取自
public类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“默认连接”)
{
}
公共数据库集博客{get;set;}
公共DbSet Posts{get;set;}
}
你能展示一下你是如何扩展IdentityUser
的吗?@Ofiris我刚刚编辑了这个问题来展示我扩展IdentityUser
的方式,非常感谢你。我花了3个小时的时间在谷歌上搜索解决方案。
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}