2
  1. これと同じ質問があり、12 日経っても回答がありません...

  2. 質問の更新として「ToTable」を使用するこれを見てきました。

  3. 私は古くなっているように見えるこれを見てきました。

ID 3.0 テーブル - ASP.NET Core のテーブル名を変更したい。

これまでのところ、「ToTable」オプション (上記 2 番) の更新を使用して、ロックファイルを破損し、結果としてプロジェクトを破損しました。3 番目のオプションは時代遅れです。

バニラ プロジェクトを作成しました - ID 3.0 で VS2015 を介して作成された変更はありません

次に、これを試しました:

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);

        builder.Entity<IdentityUser>().ToTable("MyUsers").Property(p => p.Id).HasColumnName("UserId");
        builder.Entity<ApplicationUser>().ToTable("MyUsers").Property(p => p.Id).HasColumnName("UserId");
        builder.Entity<IdentityRole>().ToTable("MyRoles");
    }

次に、更新された移行をチェックして、テーブル名が変更されたかどうかを確認しました。

現在、1.0.0-rc1-update2 を使用しています。

これらのテーブルの名前をどのように変更しますか?

4

2 に答える 2

4

機能させるには、すべてのジェネリック型引数を含める必要があります。また、ユーザーとロールを変更して、ジェネリック型引数も含める必要があります

public class BlahDbContext : IdentityDbContext<User, Role, long, UserClaim, UserRole, UserLogin, RoleClaim, UserToken>
{
    public BlahDbContext(DbContextOptions<BlahDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);

        builder.Entity<User>().ToTable("Users");
        builder.Entity<Role>().ToTable("Roles");
        builder.Entity<UserRole>().ToTable("UserRoles");
        builder.Entity<UserLogin>().ToTable("UserLogins");
        builder.Entity<UserClaim>().ToTable("UserClaims");

        builder.Entity<RoleClaim>().ToTable("RoleClaims");
        builder.Entity<UserToken>().ToTable("UserTokens");            
    }
}

public class User : IdentityUser<long, UserClaim, UserRole, UserLogin>
public class Role : IdentityRole<long, UserRole, RoleClaim>
于 2017-01-23T15:10:46.297 に答える