在我的应用程序中,我使用代码优先方法,并且仅通过将实体添加到DbContext中IEntityTypeConfiguration<>。我的目标是实现多元化的表名,即Models for Model。
在阅读了文档,文章之后,
我的疑问是我的复数器应该被注册并IPluralizer在创建迁移时使用,但是不是。
当然,我可以隐式使用DbSet<Model> Models {get;set;}或use builder.ToTable("Models");,但是在我的通用方案中,我想避免这种情况,尤其是因为我希望某些模型不要覆盖抽象的通用方案。
问题是,我是在做错什么,还是我误解了它的行为方式
AppDesignService.cs
public class AppDesignService : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
{
Debugger.Launch();
services.AddSingleton<IPluralizer, InflectorPluralizer>();
}
}
Run Code Online (Sandbox Code Playgroud)
MyDbContext.cs
public class AppDbContext : IdentityDbContext<AppUser,AppRole,Guid>
{
public EmsDbContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ApplyConfigurationsFromAssembly(Assembly.GetAssembly(typeof(AppDbContext)));
}
}
Run Code Online (Sandbox Code Playgroud)
启动文件
public void ConfigureServices(IServiceCollection services)
{
var connectionString = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<DbContext, AppDbContext>(opt =>
{ …Run Code Online (Sandbox Code Playgroud)