Skip to content

Common Settings Types Explained

Simon Hughes edited this page Sep 8, 2026 · 6 revisions

For help on the various Types used in Database.tt, this page explains the available enumerations.

Settings.DatabaseType

Specifies which database provider to use for reverse engineering.

public enum DatabaseType
{
    SqlServer,   // Microsoft SQL Server
    SQLite,      // SQLite
    PostgreSQL,  // PostgreSQL
    MySql,       // MySQL and MariaDB
    Oracle       // Oracle
}

All five are fully supported. This selects the reader inside the efrpg tool, and therefore what SQL is used to interrogate your schema. Each database has its own page covering connection strings, permissions and dialect quirks: SQL Server, PostgreSQL, MySQL, Oracle, SQLite.

Example:

Settings.DatabaseType = DatabaseType.SqlServer;

Changed in v4: SqlCe (SQL Server Compact) and Plugin have been removed, and MySQL and Oracle are now fully implemented rather than placeholders. See Upgrading from v3 to v4.


Settings.TemplateType

Specifies which code generation template to use. Choose based on your target EF version.

public enum TemplateType
{
    Ef6,              // Entity Framework 6 (.NET Framework)
    EfCore8,          // EF Core 8
    EfCore9,          // EF Core 9
    EfCore10          // EF Core 10 (latest)
}

Example:

Settings.TemplateType = TemplateType.EfCore10;

Settings.FileManagerType (removed in v4)

This chose between driving Visual Studio to add and remove project files, and writing files straight to disk. It no longer exists. v4 always writes files to disk, which is what SDK-style projects want and what almost everybody was already selecting. Delete the line from your .tt when upgrading - see Upgrading from v3 to v4.

If your project is an old-style, non-SDK .csproj that lists every file with <Compile Include="..." />, the generated files will appear on disk but not in the project. Add them once by hand, or migrate the project to the SDK style.


Settings.OnConfiguration

EF Core only — has no effect on EF 6.

Controls what code is generated inside DbContext.OnConfiguring().

public enum OnConfiguration
{
    Configuration,    // IConfiguration is injected via constructor; connection string is read from appsettings.json
    ConnectionString, // Connection string is embedded directly in OnConfiguring
    Omit              // OnConfiguring method is completely removed (use DI registration instead)
}

See Settings.OnConfiguration for full details and examples.


Elements (Settings.ElementsToGenerate)

A flags enum controlling which code elements are generated.

[Flags]
public enum Elements
{
    None              = 0,
    Poco              = 1,   // POCO entity classes
    Context           = 2,   // DbContext class (and FakeDbContext if AddUnitTestingDbContext = true)
    Interface         = 4,   // IDbContext interface
    PocoConfiguration = 8,   // Fluent API configuration mapping classes
    Enum              = 16   // Enumeration classes
}

Example — generate everything:

Settings.ElementsToGenerate = Elements.Poco | Elements.Context | Elements.Interface | Elements.PocoConfiguration | Elements.Enum;

Example — generate only POCO classes (e.g., in a dedicated Entities project):

Settings.ElementsToGenerate = Elements.Poco;

Example — generate only context and interface (e.g., in a dedicated Data project):

Settings.ElementsToGenerate = Elements.Context | Elements.Interface;

CommentsStyle (Settings.IncludeComments / Settings.IncludeExtendedPropertyComments)

public enum CommentsStyle
{
    None,           // No comments generated
    InSummaryBlock, // Comments placed in /// <summary> XML doc blocks
    AtEndOfField    // Comments placed at end of the property line
}

This is not a flags enum - pick exactly one value, do not combine them with |. The two settings are independent, so you can put schema comments at the end of the line and extended properties in summary blocks, which is what the shipped Database.tt does.

Example:

Settings.IncludeComments                = CommentsStyle.AtEndOfField;
Settings.IncludeExtendedPropertyComments = CommentsStyle.InSummaryBlock;

OrderProperties (Settings.OrderProperties)

Controls the order properties appear within generated POCO classes.

public enum OrderProperties
{
    Ordinal,      // Properties appear in database column ordinal order (default)
    Alphabetical  // Properties appear in alphabetical order
}

Example:

Settings.OrderProperties = OrderProperties.Ordinal;

Clone this wiki locally