2013-08-01 44 views
2
CREATE TABLE [dbo].[ContentStatus](
    [ContentStatusId] [int] NOT NULL, 
    [Status] [nvarchar](50) NOT NULL) 

创建:如何停止EF Reverse Engineer将单数复数变为表名?

public partial class ContentStatu 
{ 
    public ContentStatu() 
    { 
     this.Contents = new List<Content>(); 
    } 

    public int ContentStatusId { get; set; } 
    public string Status { get; set; } 

} 
+0

这是因为天真的单数化规则 - 而EF试图单化每个实体的类名。据我所知,你不能在EF Power Tools中关闭单数化,所以你可以做的最好的是反向工程+重构重命名。 –

+0

他们正在为此进行修复。详细信息http://entityframework.codeplex.com/workitem/446 –

+0

我看到此修复已发布,但在使用EF 6.1.1时,我仍然遇到与上述完全相同的问题。任何建议/代码的帮助? – AdventurGurl

回答

5

我无法为您解决相同的结尾中的“TT单个化的话问题以及在使用VS Power Tools Beta 4尽管修为entityframework.codeplex.com/workitem/446公布和我确认我是EF - 6.1.1的正确版本。

我的解决方案是使用EntityFramework Reverse POCO Code First Generator,它是一个了不起的工具!如果你能够重新开始新的tt,我强烈建议你的灵活性和易用性都非常高。 Source Code Here

观看Simon Hughes video了解详情(30分钟)概述。我快速的解决方案不删除尾部的“是:

  • (确保已安装EF)
  • 更新app.config中的连接字符串名称= MyDbContext
  • “添加新项”项目
  • 从“在线”部分中选择“EntityFramework Reverse POCO Generator”模板(除非您从上面提供的链接中安装它)并另存为“Database.tt”
  • 打开Database.tt文件并在第36行添加每个(“单数”,“复数”)覆盖需要如下:
// 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"), 
     }); 
  • 保存文件并BOOM!神奇的事情发生了,如果你展开Database.tt,你现在将看到Database.cs包含明确设置的单词的正确单数形式。 +1给Simon Hughes
2

想象一下,我会放入更新的答案而不是评论。

如何停止EF反向工程师更改复数单数与表名?

以及其他人的建议。使用反向POCO发电机

线61(八月2016)

注释掉该行:

Inflector.PluralizationService = new EnglishPluralizationService(); 

取消注释该行:

Inflector.PluralizationService = null; 

,而不是它现在采取查看命名vwStatus它决定更改为vwStatu它将执行1:1

但是,如果您希望完全控制每个表格,查看等... OP答案将适用于您。