Reverse engineers an existing database into Entity Framework Code First POCO classes, mappings, enumerations, DbContext, FakeDbContext and stored procedure calls. EF Core 8, 9, 10 and EF6. SQL Server, PostgreSQL, MySQL, Oracle and SQLite. Requires the efrpg dotnet tool.
Point this generator at your database and get production-quality Entity Framework code - the kind you'd write yourself if you had all the time in the world.
Reverse-engineers your existing database and generates EF Code First POCO classes, DbContext, configuration mappings, enumerations, a fake DbContext for unit testing, and callers for stored procedures and table-valued functions.
Clean, readable, fully customisable code. Every time.
New in v4: a GUI. Add the template, fill in one dialog, tick the tables you want. You never have to open the .tt file unless you want to.
Supports EF6, EF Core 8, 9 & 10
SQL Server, PostgreSQL, MySQL, MariaDB, Oracle and SQLite
Free for academics (.edu or .ac email address - contact me if yours doesn't qualify)
Commercial use requires a licence - visit Reverse POCO website
See it in action (no audio)
From an empty console app to querying Northwind in 40 seconds:
This generator can create enums from your database data, support HiLo sequences and JSON column mappings.
Three dialogs. No .tt editing.
1. Point it at your database. This opens the moment you add the template. Pick the database and EF version, paste a connection string, name your DbContext, press Test connection.
2. Tick what you want generated. Tables, views, stored procedures and functions, grouped by schema, with a search box. Tick everything, or just the handful a microservice needs. Anything you don't tick becomes a filter in the .tt file that you can read.
3. Everything else lives under All settings. Right-click the .tt file and choose Reverse POCO: All settings... Around a hundred settings, searchable by name, section or description, each linked to its wiki page. Only the lines you change are rewritten; your comments and formatting are left alone.
Enums straight from your lookup tables. Tables that look like lookups - an integer key and a text column - are listed first. Pick the name and value columns and the generator emits a C# enum from the rows, so Region.Northern replaces a magic number.
Prefer the .tt file? Press Skip on any dialog and edit it by hand as before. The dialogs read and write the same file, so you can mix and match.
New in v4
A GUI for the whole workflow. Right-click the .tt file in Solution Explorer and you get:
Reverse POCO: Connection... - database type, EF version, connection string, DbContext name, namespace and output layout.
Reverse POCO: Choose tables and procedures... - tick boxes for every table, view, stored procedure and function, grouped by schema.
Reverse POCO: All settings... - every setting the generator has, searchable, with a wiki link beside each one.
Reverse POCO: Check efrpg tool... - confirms the database reader (below) is installed.
Database reading has moved into a separate command-line tool, efrpg. The template no longer opens a connection itself - it runs the tool, and the tool hands back your schema.
That one change fixes the most common source of frustration with v3:
No more provider assembly hell."Could not load file or assembly Npgsql / MySql.Data / System.Data.SQLite", provider version mismatches between your project and the T4 host, 32-bit/64-bit surprises - all gone. Provider versions are the tool's problem now, not your project's.
MySQL and Oracle are properly supported, not just listed.
No Visual Studio component prerequisite. v3 needed the Entity Framework 6 tools component; v4 doesn't.
Your connection string stays out of the logs. It's passed to the tool over stdin, so it never appears in process listings or command-line audit logging.
Visual Studio 2022 or later, including Visual Studio 2026. v4 does not install on Visual Studio 2017 or 2019; v3 remains available for those.
Works in JetBrains Rider too. Not as an extension: add Database.tt and EF.Reverse.POCO.v4.ttinclude to the project, run the template from Rider's T4 menu, and you get the same output. The dialogs are Visual Studio only; in Rider you edit the .tt file. See JetBrains Rider.
Three rarely used features were retired: generating multiple DbContexts in one go, file-based (Mustache) templates and GeneratorType.Custom. v3 remains available for projects that depend on them.
Already on v3? See Upgrading from v3 to v4. The include file is versioned in its name, so v3 and v4 sit side by side in one project and you can migrate one template at a time.
Supported databases
SQL Server
PostgreSQL
MySQL / MariaDB
Oracle
SQLite
SQL Server Compact was removed in v4 - it reached end of support in July 2021 and has no provider for modern .NET. If you still need it, stay on v3.
Installed once per machine and shared by every project on it. Everyone who regenerates code needs it, including build agents. Upgrade later with dotnet tool update -g Efrpg.
2. Install this extension
You're in the right place - click Download above, or install it from Extensions → Manage Extensions in Visual Studio. Requires Visual Studio 2022 or later.
Using Rider? Skip this step: copy Database.tt and EF.Reverse.POCO.v4.ttinclude from the repository into your project and run the template from Rider's T4 menu. Details on the JetBrains Rider wiki page.
3. Add the template to your project
Right-click your project and choose Add → New Item
Search for reverse poco
Choose EntityFramework Reverse POCO Generator
Name the file (e.g. Northwind.tt) and click Add
4. Point it at your database
The connection dialog opens as soon as the file is added. Choose your database type and EF version, paste the connection string, press Test connection, then OK.
Database
Example connection string
SQL Server
Data Source=(local);Initial Catalog=Northwind;Integrated Security=True;Encrypt=false;TrustServerCertificate=true
User Id=myschema;Password=mypassword;Data Source=localhost:1521/pdb1;
SQLite
Data Source=C:\path\to\Northwind.db
A few dialect quirks worth knowing:
SQL Server - Encrypt=false;TrustServerCertificate=true is usually needed against a local instance, because Microsoft.Data.SqlClient now defaults to encrypting.
Oracle - there is no database name in the connection string. The user is the schema, and one run reads one schema.
MySQL - a database is a schema, so the reader sees only the database you connect to.
Required permissions: the account needs at least ddladmin, datareader and datawriter. ddladmin is needed to read default constraints.
The dialog writes these into the .tt file as Settings.DatabaseType and Settings.ConnectionString, so if you'd rather type them yourself, press Skip and edit the file:
The second dialog lists every table, view, stored procedure and function in the database, all ticked. Leave it as is, or untick what you don't want, then OK. The generator runs immediately and produces Northwind.cs alongside the template (or a file per class in sub-folders, if you chose that in step 4).
6. Add the EF package your project needs
This is for your code to use Entity Framework - the generator no longer needs it to read the database:
# EF Core
install-package Microsoft.EntityFrameworkCore.SqlServer
# EF 6
install-package EntityFramework
7. When your schema changes
Save the .tt file to regenerate in Visual Studio. In Rider, right click on the .tt and select Run Template.
To change the connection, the table selection or any other setting, right-click the .tt file and pick the Reverse POCO: menu item you need.
How connection strings are used
Settings.ConnectionString (mandatory) is used to read your database schema, and is also embedded in the generated OnConfiguring method:
Settings.ConnectionStringName is not used by the generator itself - it's passed as the argument to the generated DbContext constructor via Settings.DefaultConstructorArgument:
public {{DbContextName}}()
: base({{DefaultConstructorArgument}})
Highly customisable output
Every aspect of the generated code is configurable - naming conventions, filtering, output structure, base classes, callbacks and more. Change it in the All settings dialog or directly in your <database>.tt file; both write to the same place. It's designed to adapt to your codebase, not the other way around.
For syntax highlighting and IntelliSense in .tt and .ttinclude files, go to Tools → Options → Text Editor → File Extension and register tt and ttinclude as C# files.
The EF.Reverse.POCO.v4.ttinclude file is generated from the Generator C# project via the BuildTT tool included in the repository - don't edit it directly.