Beautifully generated code first code that is fully customisable
- Downloadable VSIX installer from the visual studio gallery.
- Watch the v2 in-depth course at pluralsight I cover everything the v2 generator can do, and show you step-by-step how to reverse engineer your database properly.
- A v3 course will be coming in 2020.
Go to the ReversePOCO website to obtain/purchase your licence key.
Please read the Upgrading documentation
Reverse engineers an existing database and generates Entity Framework Code First Poco classes, Configuration mappings and DbContext.
Please note, this is not the Microsoft reverse generator. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It also allows you to customise the generated code to your liking.
Click here to see what's new in this release.
- SQL Server
- SQL Server Compact 3.5 and 4.0
- Coming soon: Oracle, PostgreSQL, MySQL
This generator was designed to be customisable from the very beginning,
and not fixed and rigid like other generators.
Go and play with the settings in the <database>.tt
file, that's what it's there for.
If your database changes, simply re-save the <database>.tt
file. That's it.
Click here to see a full list of features.
-
Use Nuget and install the relevant nuget package for your database.
- .Net Core:
install-package Microsoft.EntityFrameworkCore.SqlServer
- EF 6:
install-package EntityFramework
- .Net Core:
-
Settings.ConnectionString
is mandatory in v3, so you need to provide the connection string from your app.config/web.config/appsettings.json file. This connection string is used by the generator to reverse engineer your database. It no longer reads your connection strings from *.config files.For example:
Settings.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True";
-
The
Settings.ConnectionString
string you use must have at least these privileges:ddladmin
,datareader
anddatawriter
.ddladmin
is required for reading the default constraints. -
In Visual Studio, right click project and select "add - new item".
-
Select Online, and search for reverse poco.
-
Select EntityFramework Reverse POCO Generator.
-
Give the file a name, such as
Database.tt
and click Add. -
Edit the
Database.tt
file and specify the full connection string inSettings.ConnectionString
. This is used by the generater to read your database schema and reverse engineer it. -
Edit the
Database.tt
file and specify the connection string inSettings.ConnectionStringName
which matches the ConnectionString key as specified in yourappsettings.json
,app.config
orweb.config
. -
Save the
Database.tt
file, which will now generate theDatabase.cs
file. Every time you save yourDatabase.tt
file, the generator will run and reverse engineer your database. -
There are many options you can use to customise the generated code. All of these settings are in the
Database.tt
files.
Settings.ConnectionString
is mandatory in version 3. It is used by the generator to read your database schema. It's also placed into the generated code:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){{#newline}}
{{{#newline}}
if (!optionsBuilder.IsConfigured){{#newline}}
{{{#newline}}
optionsBuilder.UseSqlServer(@""{{ConnectionString}}"");{{#newline}}
}{{#newline}}
}{{#newline}}{{#newline}}
Settings.ConnectionStringName
Not used by the generator, but is placed into the generated DbContext constructor via a call to Settings.DefaultConstructorArgument
.
public {{DbContextName}}(){{#newline}}
{{#if HasDefaultConstructorArgument}}
: base({{DefaultConstructorArgument}}){{#newline}}
{{/if}}
A simple UI for the generator is available at GitHub which helps you to create a regex to filter your tables.
To have full syntax highlighting and intellisense when editing TT files, I use the Resharper plugin ForTea. I can't imagine editing TT files without it.
With the new v3, you no longer have to edit the EF.Reverse.POCO.v3.ttinclude
file as this file is now generated from a C# project. This repository includes the BuildTT file which creates the EF.Reverse.POCO.v3.ttinclude
from the Generator
C# project.
Have a read of [https://github.com/blog/1943-how-to-write-the-perfect-pull-request](How to write the perfect pull request)
My requirements are simple:
- Always keep the changes to a minimum, so I can see exactly what's changed in regard to the pull request. I.e. No whitespace tidy up, etc.
- No tabs, only spaces (4).
- Edit the Generator C# project, as this is what is used to create the
EF.Reverse.POCO.v3.ttinclude
file. This repository includes theBuildTT
project which creates theEF.Reverse.POCO.v3.ttinclude
from theGenerator
C# project. - Don't be tempted to do a few different enhancements in one pull request. Have one pull request for one bug fix / enhancement.
Regards, Simon Hughes