[英]EF code-first PluralizingTableNameConvention for ONE DbSet
How do I toggle this convention PluralizingTableNameConvention
for only a single table/DbSet? 我如何切换此约定
PluralizingTableNameConvention
只对单个表/ DbSet? As far as I can tell, I can only do this to all the DbSets
for a given DbContext
据我所知,我只能对给定
DbContext
所有DbSets
执行此DbContext
If you have only one entity which is mapped to a table that is not pluralizeed then you can remove the PluralizingTableNameConvention
and manually configure the table name of the entity. 如果只有一个实体映射到没有复数的表,则可以删除
PluralizingTableNameConvention
并手动配置该实体的表名。
public class MyContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Item>().ToTable("Items");
}
}
Or if it is the otherway around 或者反之亦然
public class MyContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Item>().ToTable("Item");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.