gpt4 book ai didi

c# - 如何阻止 EF 逆向工程师将表名称的复数更改为单数?

转载 作者:行者123 更新时间:2023-11-30 13:47:16 25 4
gpt4 key购买 nike

CREATE TABLE [dbo].[ContentStatus](
[ContentStatusId] [int] NOT NULL,
[Status] [nvarchar](50) NOT NULL )

创建:

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

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

}

最佳答案

在使用 VS Power Tools Beta 4 时,我也无法解决您同样的 tt 单数化以“s”结尾的单词的问题。尽管修复了 entityframework.codeplex.com/workitem/446正在发布,我确实确认我使用的是正确版本的 EF - 6.1.1。

我的解决方案是使用 EntityFramework Reverse POCO Code First Generator这是一个很棒的工具!!如果您能够使用新的 tt 重新开始,我强烈建议您 super 灵活且易于使用。 Source Code Here

观看西蒙休斯 video了解入门的深入(30 分钟)概述。我不删除尾随 's' 的快速解决方案是:

  • (确保安装了 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 给西蒙·休斯

关于c# - 如何阻止 EF 逆向工程师将表名称的复数更改为单数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17986755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com