我想更改身份表名称。我用Google搜索并找到了以下方法:
第一个:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationUser>(entity =>
{
entity.ToTable(name: "Users");
});
builder.Entity<ApplicationRole>(entity =>
{
entity.ToTable(name: "Roles");
});
builder.Entity<ApplicationRoleClaim>(entity =>
{
entity.ToTable(name: "RoleClaims");
});
builder.Entity<ApplicationUserRole>(entity =>
{
entity.ToTable(name: "UserRoles");
});
builder.Entity<ApplicationUserLogin>(entity =>
{
entity.ToTable(name: "UserLogins");
});
builder.Entity<ApplicationUserClaim>(entity =>
{
entity.ToTable(name: "UserClaims");
});
builder.Entity<ApplicationUserToken>(entity =>
{
entity.ToTable(name: "UserTokens");
});
}
第二个:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationUser>().ToTable("Users");
builder.Entity<ApplicationRole>().ToTable("Roles");
builder.Entity<ApplicationRoleClaim>().ToTable("RoleClaims");
builder.Entity<ApplicationUserRole>().ToTable("UserRoles");
builder.Entity<ApplicationUserClaim>().ToTable("UserClaims");
builder.Entity<ApplicationUserToken>().ToTable("UserTokens");
builder.Entity<ApplicationUserLogin>().ToTable("UserLogins");
}
所有通用名称,如ApplicationUser,ApplicationRole ......都有 int 作为主键。
ApplicationDbContext 和 StartUp 如下所示
ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int>
启动课程
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("MySQLConnection")));
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
如果您注意到,在启动课程中,我没有在AddEntityFrameworkStores<ApplicationDbContext>().
上添加 int 因为,编译器错误一直显示&#34 ;不支持....&#34;。
我执行了以下操作来删除旧数据库和迁移
$ drop-database
$ remove-migration
添加新配置
$ add-migration Initial
$ update-database
我发现的结果是,只有用户和角色表被更改,而其他人没有(AspUserRoles,AspUserClaim .....)。
供参考:
我正在使用 Visual Studio 2017 。我的项目使用默认的Web应用程序,选择个人用户帐户和 .NET Core 2。我也使用 Pomela.EntityFramework.MySql 进行数据库提供商。
我的问题是:我做错了什么?或者改变了什么?
答案 0 :(得分:4)
您需要告诉IdentityDbContext
所有自定义类型。为了做到这一点,您需要将传递给IdentityDbContext
的泛型扩展到public class ApplicationDbContext : IdentityDbContext<ApplicationUser,
ApplicationRole, int, ApplicationUserClaim, ApplicationUserRole,
ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>
,如下所示:
PdfReader reader = new PdfReader(SRC);
PdfStamper stamper = new PdfStamper(reader, outputStream);
AcroFields fields = stamper.getAcroFields();
AcroFields.Item item = fields.getFieldItem(FIELDNAME);
PdfDictionary merged = item.getMerged(0);
TextField textField = new TextField(null, null, null);
fields.decodeGenericDictionary(merged, textField);
float fontSize = textField.getFontSize();