Create POCOs based on actual table name - do not singularize or pluralize when reverse engineering.
-
Tuesday, August 14, 2012 4:10 PM
Many of us name tables singular. i.e. Order is a table that holds Orders, Customer is a table that holds Customers, etc.
This post by Julie L [http://thedatafarm.com/blog/data-access/quick-look-at-reverse-engineer-db-into-code-first-classes/] shows a set of tables named plurally and produces singular object names. I dont want that. I want my table name left alone when I use the EF reverse engineer from code "second".
My table called Customer comes out fine, my table called CustomerStatus comes out CustomerStatu
Not acceptable and makes no sense. Can we turn off plural/single, or force the reverse engineering call to leave table names alone? I have tried tt edits from a number of good sources and nothing seems to stop this. I was able to turn on pluralization which gave me Customers and CustomerStatus, but I dont want that.
Thoughts?
-MBowles
All Replies
-
Tuesday, August 14, 2012 4:33 PMModerator
Hi,
The ability to switch off pluralization is something we are planning to add and is tracked by this work item - http://entityframework.codeplex.com/workitem/446
In the meantime you can just use F2 to refactor the class names in VS - because a complete table mapping is generated you won't need to change the mapping code at all.
~Rowan
We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.
- Proposed As Answer by Rowan MillerMicrosoft Employee, Moderator Tuesday, August 14, 2012 4:33 PM
- Edited by Rowan MillerMicrosoft Employee, Moderator Tuesday, August 14, 2012 4:45 PM
- Marked As Answer by Allen Li - AI3Microsoft Contingent Staff, Moderator Monday, August 20, 2012 2:11 AM
-
Tuesday, August 14, 2012 4:37 PMSo you are saying to rename the physical files and refactor class names to our preference? Subsequent reverse engineerings will not overwrite these changes?
-MBowles
Tried this and it left my newly named file and class alone, but it added an additional call. Renamed/refactored CustomerStatu to CustomerStatus and then ran the reverse engineer again. Left my edited class file alone, but added a new CustomerStatu.- Edited by Mbowles Tuesday, August 14, 2012 4:43 PM
-
Tuesday, August 14, 2012 4:46 PMModerator
Hi,
I was suggesting just changing the name of the class. However, if you reverse engineer it will always re-generate everything - so any changes will be lost.
~Rowan
We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.
-
Tuesday, August 14, 2012 4:53 PMOk, thanks. Not going to work for us then as we will want to do so when the db changes via a db ssdt project. I have up voted the workitem. Always interested in better suggestions.
-MBowles
-
Wednesday, August 15, 2012 1:33 PMI found that we can change the
navProperty.ToEndMember.GetEntityType() to navProperty.ToEndMember.Name and get the true table name so I am able to clean up the Entity.tt and Mappings.tt file. THe Context file is a little more challenging. Any suggestions on getting the true table name in there for build out the context DbSets?
-MBowles
-
Friday, August 17, 2012 2:19 AMAFAIK, the only way to get the exact table names is through metadata in .edmx file.
-
Friday, August 17, 2012 2:22 AMHave no edmx as we are reverse engineering. Thanks though.
-MBowles

