Entity Framework creates a plural table name, but the view expects a singular table name?

So I gave up on trying to do it the way I felt it should be done and removed pluralization all together. I don't really know for certain, but I assume the problem has to do with the mysql .net connector's support of EF. Here is what I did.

First, there was a bug in my ApplicationStart method:

//WRONG
//Database.SetInitializer(new DropCreateDatabaseAlways<myDB>());
Database.SetInitializer(new myDBInitializer());

Second, I stopped calling the OnModelCreating base implementation which is not listed in the original code since I only implemented it as per jgauffin's suggestion:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    //DONT DO THIS ANYMORE
    //base.OnModelCreating(modelBuilder);
    //modelBuilder.Entity<Vote>().ToTable("Votes")
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}

Third, I read in some posts that the MySQL .net Connector doesn't let EF actually CREATE a database, so I had initially created the blank DB. This seems to no longer be the case with connector 6.4.4+, and as long as your connection string's user has the ability to create new databases, it works better if one is not existing initially.

Once, I did all of the above, it seemed to work. So now I can at least move forward. Hopefully we can figure out the cause of the plural / singular discrepancy in the future.

Thanks to everyone for their time and effort.


In your myDB context class, override the following method

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    base.OnModelCreating(modelBuilder);
}

to have it not pluralize the generated table names.


Open the DbContext class related to the tables you want to keep a singular table name.

If you are using EF 6, add a reference to:

using System.Data.Entity.ModelConfiguration.Conventions;

If it is an older version, add a reference to:

using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db;

At last create a method that overrides the OnModelCreating and remove the convention to pluralize table names:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}