【问题标题】:Where are types used in Entity Framework T4 templates defined?Entity Framework T4 模板中使用的类型在哪里定义?
【发布时间】:2017-04-12 23:20:58
【问题描述】:

在 Entity Framework 为我的实体和DbContext 生成创建的.tt 文件中,我看到使用了TypeMapperAccessibility 之类的类。这些类型是在哪里定义的,它们是否记录在任何地方?我想自定义我的 t4 模板,但很难不知道这些类的作用或如何使用它们。

【问题讨论】:

    标签: entity-framework entity-framework-6 t4


    【解决方案1】:

    Entity Framework T4 模板在文件顶部有 include 指令。对于 C#,它看起来像:

    <#@ include file="EF6.Utility.CS.ttinclude"#>
    

    此文件可以在 Visual Studio IDE 扩展文件夹中找到。例如。默认情况下,Visual Studio 2017 将是:

    c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Entity 框架工具\模板\包含\

    此文件包含用于实体生成的帮助类。例如。

    /// <summary>
    /// Responsible for encapsulating the retrieval and translation of the CodeGeneration
    /// annotations in the EntityFramework Metadata to form that is useful in code generation.
    /// </summary>
    public static class Accessibility
    

    第二类TypeMapper在上下文生成模板本身中定义。

    【讨论】:

    • 谢谢。对于 Visual Studio 2013,它位于 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    相关资源
    最近更新 更多