Skip to content

Settings.DatabaseType

Simon Hughes edited this page Aug 30, 2026 · 1 revision

Settings.DatabaseType, Settings.TemplateType and Settings.GeneratorType

The three settings you must get right before anything else works.

Setting Type Default
Settings.DatabaseType DatabaseType enum DatabaseType.SqlServer
Settings.TemplateType TemplateType enum TemplateType.EfCore10
Settings.GeneratorType GeneratorType enum GeneratorType.EfCore

All three are in Database.tt at the very top, and all three apply everywhere.

What they do

They answer three separate questions, and the mistake is assuming one answer settles the others.

DatabaseType - what am I reading from? It selects the reader inside the efrpg tool, and therefore which SQL is used to interrogate your schema and which type map turns database types into C# types.

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

TemplateType - what am I writing for? It selects the code templates, and must match the EF version your project references, not your .NET version.

public enum TemplateType
{
    Ef6, EfCore8, EfCore9, EfCore10,
    FileBasedEf6, FileBasedCore8, FileBasedCore9, FileBasedCore10
}

GeneratorType - which generation engine runs. It has to be paired correctly with TemplateType:

TemplateType GeneratorType
Ef6, FileBasedEf6 GeneratorType.Ef6
EfCore8/9/10, FileBasedCore8/9/10 GeneratorType.EfCore

GeneratorType.Custom exists for supplying your own GeneratorCustom implementation, and is rarely used.

Getting the pair right

This is the part that bites. TemplateType and GeneratorType are two settings describing one decision, and mismatching them produces code that does not compile rather than an error saying so.

// EF Core 10 - the default
Settings.TemplateType  = TemplateType.EfCore10;
Settings.GeneratorType = GeneratorType.EfCore;

// EF 6
Settings.TemplateType  = TemplateType.Ef6;
Settings.GeneratorType = GeneratorType.Ef6;

Choosing TemplateType

Match the EF Core version in your .csproj, not the .NET version:

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.0" />

That is TemplateType.EfCore10. A project on .NET 10 referencing EF Core 8 wants EfCore8.

Using a template newer than your EF Core package generates calls that do not exist yet. Using an older one is safe but leaves newer features unused.

Gotchas

DatabaseType does not imply TemplateType. You can read PostgreSQL and generate EF 6 code - it simply will not run, because there is no EF 6 PostgreSQL provider worth using. The generator does not stop you.

MySQL needs Settings.OnConfiguration = OnConfiguration.Omit. Pomelo's UseMySql() takes a mandatory ServerVersion argument the generator does not emit, so any other mode produces code that does not compile. See MySQL.

SqlCe and Plugin were removed in v4. SQL Server Compact reached end of support in 2021 and has no modern .NET provider. See Upgrading from v3 to v4.

There is no EF Core 7 or earlier template in v4. Stay on v3 if you need one - see Support Planning.

Your project needs the matching EF provider package, which the generator does not install:

Database EF Core package
SQL Server Microsoft.EntityFrameworkCore.SqlServer
PostgreSQL Npgsql.EntityFrameworkCore.PostgreSQL
MySQL Pomelo.EntityFrameworkCore.MySql
Oracle Oracle.EntityFrameworkCore
SQLite Microsoft.EntityFrameworkCore.Sqlite

The efrpg tool has its own separate drivers for reading the schema; these are for your application at run time.

FileBased* needs Settings.TemplateFolder pointing at a folder of .mustache files. See Custom File-Based Templates.

See also

Clone this wiki locally