-
Notifications
You must be signed in to change notification settings - Fork 226
Settings.TemplateFolder
Three settings about the templates that turn the schema into text, and what the text is called.
| Setting | Type | Default |
|---|---|---|
Settings.TemplateFolder |
string |
Path.Combine(Settings.Root, "Templates") |
Settings.GenerationLanguage |
GenerationLanguage enum |
GenerationLanguage.CSharp |
Settings.FileExtension |
string |
".cs" |
Only read when Settings.TemplateType is one of the FileBased* values. It names
the folder holding the Mustache templates the generator will use instead of its built-in ones.
The folder must contain the .mustache and *Usings.txt files directly. It is not a parent holding
per-version sub-folders. Copy the contents of the _File based templates\Templates.EFCore10 folder (or
whichever matches your TemplateType) into it.
Settings.TemplateType = TemplateType.FileBasedCore10;
Settings.TemplateFolder = Path.Combine(Settings.Root, "Templates"); // relative to the .tt - recommended
Settings.TemplateFolder = @"c:\shared\efrpg-templates"; // or absoluteFile-based templates exist so your changes survive an upgrade. The built-in templates live inside
EF.Reverse.POCO.v4.ttinclude, which is replaced wholesale every time you update the extension; a folder of
your own is not. See Custom File-Based Templates.
public enum GenerationLanguage
{
CSharp,
Javascript
}C# is the only language that is fully supported. Javascript swaps in a JavaScript type map and is SQL
Server only - every other database silently falls back to C#. It changes the property types only; the
templates still emit C# structure around them, so treat it as experimental.
The extension on generated files. ".cs" unless you have changed GenerationLanguage, in which case set it
to match.
TemplateFolder does nothing unless TemplateType is FileBased*. The setting is assigned in the
shipped Database.tt regardless, which makes it look active when it is not.
A missing template file fails at generation time, not with a helpful message about which file. If you
copied only some of the .mustache files, copy the rest.
Templates are version-specific. Templates.EFCore8 and Templates.EFCore10 differ. Point
FileBasedCore10 at an EF Core 8 template folder and you get EF Core 8 output.
Multi-context generation can override the folder per context, through the TemplatePath column of
MultiContext.Context. That takes precedence over this setting for that one context.
GenerationLanguage.Javascript is not a JavaScript code generator. It changes types, nothing else. If you
want TypeScript models, a file-based template is the honest route.
- Custom File-Based Templates - what goes in the folder, and the Mustache syntax
- Settings.DatabaseType, TemplateType and GeneratorType
-
Settings.Runtime-Values - what
Settings.Rootis - Generating Multiple Database Contexts in a Single Go - per-context template folders
- Settings Reference
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets
- Custom File-Based Templates
- Extra entities via partial classes
- INotifyPropertyChanged
- Syntax colour for T4