EF6 is pluralizing my Code First table names no matter what I do. I am getting the error that it can't find the pluralized table {"Invalid object name 'dbo.TestStats'."}. The table is singular in the DB as dbo.TestStat
I tried removing the convention by
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
I have also mapped it to the singular table name
public TestStatMap()
{
// Primary Key
this.HasKey(t => t.TestStatId);
this.ToTable("TestStat");
I have even tried adding this to the OnModelCreating override
modelBuilder.Entity<TestStat>().ToTable("TestStat");
Here is the table that I am trying to map it to, which was generated by the EF power tools. What else can I try or what am I missing?
CREATE TABLE [dbo].[TestStat] (
[TestStatId] [int] NOT NULL IDENTITY,
[SeasonID] [int],
[TeamID] [int],
CONSTRAINT [PK_dbo.TestStat] PRIMARY KEY ([TestStatId])
)
Figured out my own mistake. I have two Context classes, one inheriting from the other for the repository, and I had the code below in the base context, when I moved it to the derived it now works. modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();