【问题标题】:Change name of generated Context file with EF PowerTools Reverse Engineer Code First使用 EF PowerTools Reverse Engineer Code First 更改生成的上下文文件的名称
【发布时间】:2016-02-19 23:48:59
【问题描述】:

我一直在试图弄清楚如何让 EF Power Tools - Reverse Engineer Code First为生成的上下文文件使用不同的名称,而不是它现在使用。

示例

我有一个名为 My_Awesome_Dev_Database 的数据库。当我对此运行逆向工程时,生成的文件将被调用:

My_Awesome_Dev_DatabaseContext.cs

它想要做的是指定要调用的文件,例如:

MyAwesomeDatabaseContext.cs

目前的尝试

我已尝试查看 EF.Utilities.CS.ttinclude 文件,以了解文件名是如何生成的 - 但到目前为止我没有成功。

有人知道吗?

提前致谢!

【问题讨论】:

    标签: entity-framework ef-power-tools


    【解决方案1】:

    目前生成的上下文文件命名约定是硬编码且不可配置的。

    所有逻辑都在 ReverseEngineerCodeFirstHandler 类 (the source is on CodePlex) 中。

    它设置上下文文件名和路径

    var contextFilePath = Path.Combine(modelsDirectory, 
         modelGenerator.EntityContainer.Name + contextHost.FileExtension);
    var contextItem = project.AddNewFile(contextFilePath, contextContents);
    

    所以文件名来自modelGenerator.EntityContainer.Name,它在方法的上部创建:

    var contextName = 
        connection.Database.Replace(" ", string.Empty)
                           .Replace(".", string.Empty) + "Context";
    var modelGenerator = 
        new EntityModelSchemaGenerator(storeGenerator.EntityContainer, 
            "DefaultNamespace", contextName);
    

    如您所见,该工具只使用数据库名称删除空格和点并将其用作最终作为生成文件名的上下文名称。

    您可以打开 issue 或 - 因为 Entity Framework 是开源的 - 获取代码,添加此配置选项,然后发回拉取请求。

    【讨论】:

    • 虽然它不能解决问题,但我认为它与我们将要得到的答案一样接近。我们已经找到了几种解决问题的方法——当然最好的解决方案是创建拉取请求。会调查的。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多