xr280xr
xr280xr

Reputation: 13302

Where are types used in Entity Framework T4 templates defined?

In the .tt files created by Entity Framework for my entities and DbContext generation, I see classes like TypeMapper and Accessibility used. Where are these types defined and are they documented anywhere? I want to customize my t4 templates, but it's difficult not knowing what any of these classes do or how to use them.

Upvotes: 2

Views: 676

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236228

Entity Framework T4 template has include directive at the top of the file. For C# it will look like:

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

This file can be found in Visual Studio IDE extensions folder. E.g. by default for Visual Studio 2017 it will be:

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

This file contains helper classes which are used for entities generation. E.g.

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

Second class TypeMapper is defined in the context generation template itself.

Upvotes: 3

Related Questions