How turn off pluralize table creation for Entity Framework 5?

后端 未结 3 1648
有刺的猬
有刺的猬 2020-12-01 12:23

I am trying to use Entity Framework 5. The first problem was that EF creats tables automatically. I tried to fix it by including dbModelBuilder.Conventions.Remove<

相关标签:
3条回答
  • 2020-12-01 12:43

    You can write this code in OnModelCreating method:

    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    
    0 讨论(0)
  • 2020-12-01 12:50

    If you don't want EF to create tables and manage consistency between you model and database just use this at the startup of your application:

    Database.SetInitializer<CountryContext>(null);
    
    0 讨论(0)
  • 2020-12-01 12:58

    Using LINQ in EF 6.0:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        var conventions = new List<PluralizingTableNameConvention>().ToArray();
        modelBuilder.Conventions.Remove(conventions);
    }
    
    0 讨论(0)
提交回复
热议问题