-
Notifications
You must be signed in to change notification settings - Fork 226
Home
The generator creates Entity Framework Code First classes by reverse-engineering existing databases. It produces code as if an expert reverse-engineered your database and wrote it for you.
- Generates POCO classes, configuration mappings, and enumerations
- Creates DbContext and FakeDbContext for unit testing
- Supports stored procedures and table-valued functions
- Fully customisable output via callbacks and delegates
- Available as a VSIX installer from the Visual Studio Marketplace
- Supports multiple output file organisation strategies (sub-folders, namespaces)
If you like or are using this project, please give it a star. Thanks!
v4 moves all database reading out of the T4 template and into a separate dotnet tool, efrpg. The template
runs the tool; the tool hands back the schema as XML.
The reason that matters to you:
- MySQL and Oracle are now fully supported, joining SQL Server, PostgreSQL and SQLite.
-
No more GAC installs, no more
machine.configedits. Database drivers are ordinary NuGet dependencies of the tool. If you followed the old PostgreSQL, Oracle, MySQL or SQLite setup instructions, you can undo all of it. - Your connection string is passed to the tool over stdin, so it stays out of process listings and command-line audit logs.
You must install the tool, or nothing will generate. See step 2 below, and Upgrading from v3 to v4 for the full upgrade.
Gone in v4: DatabaseType.SqlCe, DatabaseType.Plugin, Settings.DatabaseReaderPlugin and
Settings.FileManagerType.
| Database | Status | Notes |
|---|---|---|
| SQL Server | Fully supported | The most complete implementation |
| PostgreSQL | Fully supported | |
| MySQL / MariaDB | Fully supported | New in v4. One database = one schema |
| Oracle | Fully supported | New in v4. One schema per run |
| SQLite | Fully supported | No stored procedures in SQLite |
SQL Server Compact was removed in v4. It reached end of support in July 2021 and has no provider for modern .NET. Stay on v3 until you have migrated the database, typically to SQLite or LocalDB.
| EF Version | Template Type | Generator Type |
|---|---|---|
| EF 6 | TemplateType.Ef6 |
GeneratorType.Ef6 |
| EF Core 8 | TemplateType.EfCore8 |
GeneratorType.EfCore |
| EF Core 9 | TemplateType.EfCore9 |
GeneratorType.EfCore |
| EF Core 10 | TemplateType.EfCore10 |
GeneratorType.EfCore |
Match TemplateType to the EF Core version your project references, not your .NET version. See
Support Planning.
-
Visual Studio 2022 or later
-
The .NET 10 runtime, for the
efrpgtool -
The EF provider NuGet package for your database, in your project:
Database EF Core package EF 6 package SQL Server Microsoft.EntityFrameworkCore.SqlServerEntityFrameworkPostgreSQL Npgsql.EntityFrameworkCore.PostgreSQLn/a MySQL Pomelo.EntityFrameworkCore.MySqln/a Oracle Oracle.EntityFrameworkCoren/a SQLite Microsoft.EntityFrameworkCore.Sqliten/a -
A connection string pointing at your database, with read access to the schema. See Connection strings for the exact permissions per database.
-
Install the VSIX extension from the Visual Studio Marketplace.
-
Install the
efrpgtool. Once per machine, shared by every project on it:dotnet tool install -g EfrpgCheck it is on your
PATHwithefrpg --help. Restart Visual Studio afterwards - it caches the environment it was started with, so aPATHchange made while it was running is invisible to it. -
Right-click your project → Add New Item
-
Search for "reverse poco" in online templates
-
Name the file (e.g.
Database.tt) and click Add -
Edit the connection string and settings
-
Save the file —
Database.cs(and related files) are generated automatically
Every time your database changes, re-save the .tt file. Building does not re-run the generator; only saving
does.
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.EfCore10;
Settings.GeneratorType = GeneratorType.EfCore;
Settings.UseMappingTables = false;Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.EfCore9;
Settings.GeneratorType = GeneratorType.EfCore;
Settings.UseMappingTables = false;Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.EfCore8;
Settings.GeneratorType = GeneratorType.EfCore;
Settings.UseMappingTables = false;Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.Ef6;
Settings.GeneratorType = GeneratorType.Ef6;
Settings.UseMappingTables = true;Settings.FileManagerType no longer exists in v4 - output is always written the same way. Delete the line when
upgrading.
Getting it working
- Connection strings - working examples for all five databases, permissions, and keeping secrets out of source control
-
Upgrading from v3 to v4 - including the
efrpgtool command line and troubleshooting - Saving .tt does nothing
Shaping the output
- Common Settings Types Explained - the settings you must get right
- Settings Reference - every setting
- Settings Callbacks - the delegates that let you rename and reshape anything
- Filtering - generate only the tables you need
- Full Control Over the Generated Code
- Custom File-Based Templates
Modelling features
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Spatial Types | HierarchyId | RowVersion and TimeStamp columns
- Data Annotations | Lazy Loading | Settings.OnConfiguration
Bigger jobs
- Generating Multiple Database Contexts in a Single Go
- Migrations
- FakeDbContext - unit testing
- Stored Procedure Return Model Errors
- Speed up Reverse generating
- Free for academic use (.edu or .ac email addresses)
- Commercial license required for commercial use — purchase at reversepoco.co.uk
- Generated code remains usable indefinitely even if the licence expires
- With an expired licence, generation is limited to 10 tables/views and 10 stored procedures
See Licencing & expires licence and ReversePOCO.txt licence file.
See How to Get Your Pull Request Accepted for contribution guidelines.
Contact: simon@reversepoco.co.uk
- Common Settings Types Explained
- Settings Reference
- Settings Callbacks
- Settings.OnConfiguration
- 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
