locked
EF6 Invalid Object Name Code First Plural RRS feed

  • Question

  • I am getting the invalid object name due to the table is being pluralized by EF when calling the DB. I have read a lot of posts and tried everything such as modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); but it still pluralizes my table. I have searched the entire solution multiple times to ensure that it is not indicated as plural, and I have verified the table exists on the DB server as singular, any ideas? 

    Saturday, December 7, 2013 6:18 AM

Answers

  • Yes I just figured it out today, it was because I had multiple contexts and the code below was not in the context that was causing the error, so that code does truly work. Thanks for the response

    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 

    • Marked as answer by Fred Bao Tuesday, December 17, 2013 7:32 AM
    Monday, December 9, 2013 2:13 AM

All replies

  • Hello,

    >>I am getting the invalid object name

    Could you please share the detail error information and how have you defined your entity class and the YourContext class?

    >> and I have verified the table exists on the DB server as singular, any ideas?

    Is it that you want to use code first with existing database? If it is, I suggest using the EF Power Tools.

    For details, please refer to link below:

    http://msdn.microsoft.com/en-us/data/jj200620.aspx

    There is a similar thread regarding it:

    http://stackoverflow.com/questions/20457187/ef6-code-first-pluralizing-tables-invalid-object-name

    It is caused by multiple contexts, so please check whether you have defined multiple contexts.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 9, 2013 2:06 AM
  • Yes I just figured it out today, it was because I had multiple contexts and the code below was not in the context that was causing the error, so that code does truly work. Thanks for the response

    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 

    • Marked as answer by Fred Bao Tuesday, December 17, 2013 7:32 AM
    Monday, December 9, 2013 2:13 AM