【问题标题】:Adding properties to IdentityUser doesn't create the correct migration向 IdentityUser 添加属性不会创建正确的迁移
【发布时间】:2015-02-24 21:43:57
【问题描述】:

我已经按照这里的教程进行操作:Customizing profile information in ASP.NET Identity in VS 2013 templates

并且完全按照那里的内容进行操作,除了我的新属性是一个名为“TaxId”的字符串。令人惊讶的是,当我执行“添加迁移”部分时,迁移文件出现了空:

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的吗?
  • @Ofiris 我刚刚编辑了问题以显示我扩展IdentityUser的方式

标签: asp.net-mvc entity-framework asp.net-mvc-5 entity-framework-migrations


【解决方案1】:

问题是我已经有了自己的数据库上下文。 使用了这个解决方案,取自here

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

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

}

【讨论】:

  • 非常感谢您。我花了 3 个小时在谷歌上搜索解决这个问题的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
  • 1970-01-01
  • 2018-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多