Entity Framework T4 模板中使用的类型在哪里定义?

Where are types used in Entity Framework T4 templates defined?

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

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

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

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

c:\Program Files (x86)\Microsoft Visual Studio17\Community\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\

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

/// <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

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