如何仅为单个表/ DbSet切换此约定PluralizingTableNameConvention?据我所知,我只能为所有的DbSets给定一个DbContext
解决方法
如果您只有一个实体映射到不是multipleizeed的表,那么您可以删除PluralizingTableNameConvention并手动配置实体的表名称.
public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); modelBuilder.Entity<Item>().ToTable("Items"); } }
或者如果是另一边
public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<Item>().ToTable("Item"); } }