locked
How to prevent model first from looking for pluralized entity names RRS feed

  • Question

  • I am getting the error invalid object name dbo.JobDefinitions. In my case I know that the issue is that what entity framework is looking for is different than my actual table names (my table name is singular and ef is looking for pluralized).

    I'm using a model first edmx style setup. How can I force ef to use the singular name instead, as I don't want to change my tables in the db? The config in modal viewer "Pluralize New Objects" = false does not work.

    Wednesday, May 1, 2013 11:26 PM

Answers

  • Hello..

    Your OnModelCreating method should be this way..

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

    Thanks.


    Happy Coding, Kishore.

    • Proposed as answer by Chester Hong Wednesday, May 8, 2013 9:03 AM
    • Marked as answer by Chester Hong Monday, May 13, 2013 8:28 PM
    Thursday, May 2, 2013 1:57 AM

All replies

  • Hello..

    Your OnModelCreating method should be this way..

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

    Thanks.


    Happy Coding, Kishore.

    • Proposed as answer by Chester Hong Wednesday, May 8, 2013 9:03 AM
    • Marked as answer by Chester Hong Monday, May 13, 2013 8:28 PM
    Thursday, May 2, 2013 1:57 AM
  • He CLEARLY says model first in his question, the answer is for code first and therefore useless.

    Joe

    Friday, November 22, 2013 4:11 PM
  • Depending upon what version of EF you are using, you can tell EF to not generate the objects with a plural naming convention when using the model first approach on model creation.
    Saturday, November 30, 2013 6:35 PM
  • This doesn't work in all cases. Not sure why but I have singular table in the DB, mapped to its singular name, I have added the code above to the OnModelCreating and it STILL pluralizes during the read. Maybe this is a bug with EF6?
    Saturday, December 7, 2013 6:41 AM
  • I get this to. It creates the tables fine, but trying to read from them it tries the plural name.
    Thursday, April 24, 2014 4:30 PM