重写OnModelCreating,控制生成表名的单复数

public class MYDbContext : DbContext
{
public DbSet<User> Users { get; set; } public TYDbContext()
: base("name=MYEntities")
{
} protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//按model的名字生成表,而不是DbSet的名字
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder); }
}

  

05-06 17:45