我有一个包含IdentityDbContext的应用程序,我想使用ServiceStack.OrmLite选择数据,我想知道如何更改别名
public class ApplicationDbContext : IdentityDbContext<User>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<User>().ToTable("User");
builder.Entity<IdentityRole>().ToTable("Role");
builder.Entity<IdentityUserRole<string>>().ToTable("UserRole");
builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim");
builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin");
}
}
我在下面尝试了代码,但它无效:
ModelDefinition<User>.Definition.Alias = "Users";
ModelDefinition<IdentityRole>.Definition.Alias = "Roles";
ModelDefinition<IdentityUserRole<string>>.Definition.Alias = "UserRoles";
ModelDefinition<IdentityUserClaim<string>>.Definition.Alias = "UserClaims";
ModelDefinition<IdentityUserLogin<string>>.Definition.Alias = "UserLogins";
答案 0 :(得分:1)
您可以使用GetModelMetadata()
扩展方法更改OrmLite为每个类型使用的表元数据,例如:
var tableMeta = type.GetModelMetadata();
tableMeta.Alias = "NewTableName";