问题
CREATE TABLE [dbo].[ContentStatus](
[ContentStatusId] [int] NOT NULL,
[Status] [nvarchar](50) NOT NULL )
Creates:
public partial class ContentStatu
{
public ContentStatu()
{
this.Contents = new List<Content>();
}
public int ContentStatusId { get; set; }
public string Status { get; set; }
}
回答1:
I was unable to solve your same issue of tt singularizing words ending in 's' as well while using VS Power Tools Beta 4 despite the fix for entityframework.codeplex.com/workitem/446 being posted and I did confirm I was on the correct version of EF - 6.1.1.
My solution was to use EntityFramework Reverse POCO Code First Generator and it is an AWESOME tool!! I highly recommend based off being super flexible and easy to use if you are able to start over with a new tt. Source Code Here
Watch Simon Hughes video for an in-depth (30 min) overview for getting started. My quick solution to not removing the trailing 's' was to:
- (Make sure EF is installed)
- Update app.config connection string name = MyDbContext
- "Add New Item" to project
- Select "EntityFramework Reverse POCO Generator" template from the "Online" section (unless you installed it from the link provided above already) and save as "Database.tt"
- Open Database.tt file and at line 36 add each ("singular","plural") override needed as follows:
// Pluralization ********************************************************************************************************************** // To turn off pluralization, use: // Inflector.PluralizationService = null; // Default pluralization, use: // Inflector.PluralizationService = new EnglishPluralizationService(); // For Spanish pluralization: // 1. Intall the "EF6.Contrib" Nuget Package. // 2. Add the following to the top of this file and adjust path, and remove the space between the angle bracket and # at the beginning and end. // < #@ assembly name="your full path to \EntityFramework.Contrib.dll" # > // 3. Change the line below to: Inflector.PluralizationService = new SpanishPluralizationService(); Inflector.PluralizationService = new EnglishPluralizationService(new CustomPluralizationEntry[] { new CustomPluralizationEntry("CustomerStatus","CustomerStatus"), new CustomPluralizationEntry("EmployeeStatus","EmployeeStatus"), });
- Save file and BOOM!! the magic happens and if you expand Database.tt you will now see the Database.cs contains the correct singular form for the words explicitly set. +1 to Simon Hughes
回答2:
Figured that I would put in an updated answer instead of a comment.
How can I stop EF Reverse Engineer changing plural to singular with Table names?
Well as the other person suggest. Use the Reverse POCO generator
Line 61 ( August 2016)
Comment out this line:
Inflector.PluralizationService = new EnglishPluralizationService();
Uncomment this line:
Inflector.PluralizationService = null;
Now instead of it taking a View named vwStatus and it deciding to change to vwStatu it will do a 1:1
However, If you want that complete control per table , view etc... OP answer will work for you.
来源:https://stackoverflow.com/questions/17986755/how-can-i-stop-ef-reverse-engineer-changing-plural-to-singular-with-table-names