如何使用IdentityUser忽略AspNetUserClaims表?

时间:2017-01-13 15:15:56

标签: asp.net ef-code-first asp.net-identity

我想使用IdentityUser,但我不想使用声明或登录。 所以,我想从我的数据库中删除这些表。 根据一些搜索,我实现了我的数据库上下文(Code First),如下所示:

public class MainDb : IdentityDbContext
{
    (...)

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<IdentityUser>().ToTable("User")
            .Ignore(x => x.AccessFailedCount)
            .Ignore(x => x.Claims)
            .Ignore(x => x.EmailConfirmed)
            .Ignore(x => x.LockoutEnabled)
            .Ignore(x => x.LockoutEndDateUtc)
            .Ignore(x => x.Logins)
            .Ignore(x => x.PhoneNumberConfirmed)
            .Ignore(x => x.TwoFactorEnabled);

        modelBuilder.Ignore<IdentityUserLogin>();
        modelBuilder.Ignore<IdentityUserClaim>();
    }
}

当我尝试创建迁移(&#34; Add-Migration Users&#34;在Package Manager控制台中)时,出现以下错误:

The navigation property 'Claims' is not a declared property on type 'IdentityUser'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.

如果删除引用声明和登录的行,则会创建迁移,忽略其他属性:

public class MainDb : IdentityDbContext
{
    (...)

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<IdentityUser>().ToTable("User")
            .Ignore(x => x.AccessFailedCount)
            .Ignore(x => x.EmailConfirmed)
            .Ignore(x => x.LockoutEnabled)
            .Ignore(x => x.LockoutEndDateUtc)
            .Ignore(x => x.PhoneNumberConfirmed)
            .Ignore(x => x.TwoFactorEnabled);
    }
}

我还试图在我的User类(IdentityUser的子代)中覆盖添加set访问器的声明,但是无法在覆盖时添加新的访问器。

根据this,这是一个回答相似的问题,似乎这是可能的,但现在我无法找到解决方案。

我错过了什么吗?

0 个答案:

没有答案