Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Entity Framework missing the last s in a table that ends with 'Status'

This is a really weird error, I have looked online and can not see any obvious reasons why this is happening.

I am using Database First Entity Framework version 5 and have added 4 tables called:

  • WorkStatus
  • JobStatus
  • SubJobStatus
  • SubJobStageStatus

JobStatus, SubJobStatus and SubJobStageStatus each has a foreign key constraint to WorkStatus.

I have updated my edmx to include these tables but for some reason each table is missing the last s from the word Status. So the tables and their navigation properties are now called:

  • WorkStatu
  • JobStatu
  • SubJobStatu
  • SubJobStageStatu

Does anyone know why this happens?

like image 610
Andy Clark Avatar asked Sep 17 '12 12:09

Andy Clark


1 Answers

"-Status" is being interpreted as a plural, and Entity Framework is being "helpful" by de-pluralizing.

For example, if you have a table called "Customers" EF will generate an entity called "Customer", which is in fact nicer in code:

var customer = new Customer();

It isn't working out so well in your case; your tables are already singular.

You can rename your tables to "-Statuses" or update the names in the designer or disable pluralization:

Under Tools > Options enter image description here

like image 194
Jay Avatar answered Oct 09 '22 18:10

Jay