Entity Framework - CTP4 - Code First - How to turn off the automatic pluralization?

前端 未结 5 731
慢半拍i
慢半拍i 2021-01-01 00:20

My entity name is \"Contact\" and my table name is \"Contact\". However, the default pluralization support is making EF4 to look for a table named \"Contacts\". Anybody has

5条回答
  •  抹茶落季
    2021-01-01 00:46

    I'm adding yet a third answer as my understanding of the question changes... is that bad of me? ;)

    Like I said in my comment, I'm still learning and I haven't attempted this with an existing database yet. That said, hopefully one of these will help:

    The post I mentioned by Scott Guthrie (http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx) has a comment by a certain Jeff that says this can help (I recommend reading the full comment as he explains in more detail):

    Database.SetInitializer(null); //AddressBook being the context
    

    I've also happened across a comment by Rowan Miller underneath this post (http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4announcement.aspx?PageIndex=2) in the recent past. He suggests this may be an option:

    public class ProductContext : DbContext
    {
       protected override void OnModelCreating(ModelBuilder modelBuilder)
       {
           modelBuilder.IncludeMetadataInDatabase = false;
       }
       ...
    }
    

    Hopefully one of these gets you on the right track.

提交回复
热议问题