如何阻止EF逆向工程师使用表名变更复数为单数? [英] How can I stop EF Reverse Engineer changing plural to singular with Table names?

查看:93
本文介绍了如何阻止EF逆向工程师使用表名变更复数为单数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 尽管修复了 entityframework.codeplex.com/workitem/446 被发布,我确认我是正确版本的EF - 6.1.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.

我的解决方案是使用 EntityFramework反向POCO代码第一代生成器,它是一个AWESOME工具!我强烈推荐基于超级灵活和易于使用,如果你能够重新开始一个新的tt。 源代码在这里

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

观看Simon Hughes video 进行深入(30分钟)的入门概述。我没有删除尾随'的快速解决方案是:

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:


  • (确保安装了EF)

  • 更新app.config连接字符串name = MyDbContext

  • 添加新项目到项目

  • 选择EntityFramework Reverse POCO Generator模板从在线部分(除非您已经从上面提供的链接安装它),并另存为Database.tt

  • 打开Database.tt文件,并在第36行添加每个(单数,复数)覆盖需要如下:

  • (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"),
        });





  • 保存文件和BOOM!魔法发生,如果您展开Database.tt,您将看到Database.cs包含明确设置的单词的正确单数形式。 +1给Simon Hughes

  • 这篇关于如何阻止EF逆向工程师使用表名变更复数为单数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆