Updated on

EF Core Power Tools is a Visual Studio extension that reverse engineers an existing database into a DbContext and entity classes through a graphical interface, so we don’t have to write that boilerplate code by hand.

It’s a popular toolbox for database-first work with Entity Framework Core, and its standout feature is that interface. Let’s see how it works, from installing and updating it to customizing the code it generates.

To download the source code for this article, you can visit our GitHub repository.

Let’s get started!

Which Visual Studio and EF Core Versions Does EF Core Power Tools Support?

EF Core Power Tools runs in Visual Studio 2022 and Visual Studio 2026, and it generates code for EF Core 8, 9 and 10.

The current extension, version 2.6.1777 from October 16, 2026, installs into Visual Studio versions 17.0 up to, but not including, 19.0. Visual Studio 2022 is version 17 and Visual Studio 2026 is version 18, so the same download covers both, on x64 and Arm64 machines.

For reverse engineering, the extension also needs the .NET 8 or the .NET 10 runtime on our machine.

Older EF Core versions are out. Microsoft Learn’s tools page lists the extension “For EF Core: 8-10”, and the maintainer kept the last builds for EF Core 6 and EF Core 7 as separate GitHub releases.

If we don’t use Visual Studio at all, the same reverse engineering runs from the efcpt command-line tool on Windows, Linux and macOS.

EF Core Power Tools provides two usage options. The first one is the Visual Studio extension, and the second one is efcpt, a cross-platform .NET tool that is no longer in preview. In this article, we’ll analyze the first option, because the graphical interface is what the toolbox does best.

To download the extension, we can either get it from Microsoft’s Visual Studio Marketplace or, inside Visual Studio, open Extensions > Manage Extensions and search for it. From there, a VSIX installer will finish the job and the extension will be available the next time we open Visual Studio.

How Do We Update EF Core Power Tools?

We update the Visual Studio extension from the same place we installed it. In Visual Studio, we open Extensions > Manage Extensions, find EF Core Power Tools under the available updates and update it. The VSIX installer runs when we close Visual Studio, and the new version is ready the next time we start it.

Updating the extension doesn’t upgrade a project that already uses it, though. Two things in the project stay behind.

The first one is the EF Core version. We pick it in the Choose Your Data Connection dialog, and the tool stores it in efpt.config.json.

The second one is the T4 templates. Each template carries a Template version comment, 1000 for EF Core 10, and the tool warns us when it finds an older one. It only copies fresh templates into a missing or empty CodeTemplates folder.

For the command-line tool, dotnet tool update ErikEJ.EFCorePowerTools.Cli -g --version 10.* does the update.

The extension’s own warning tells us what to do with old templates: “update your T4 templates, for example by renaming the CodeTemplates folder.” Our sample would hit exactly this. Its templates came from EF Core 7 and carry Template version: 703, and its config files still hold "CodeGenerationMode": 3, a value the current tool no longer has. The updated sample uses the EF Core 10 templates and "CodeGenerationMode": 6.

Create a Database and the Tables

Let’s create a simple database with a few tables:

CREATE DATABASE DatabaseFirstDevelopmentUsingEFCorePowerToolsDB
GO

USE DatabaseFirstDevelopmentUsingEFCorePowerToolsDB

CREATE TABLE Authors (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    FirstName VARCHAR(255) NOT NULL,
    LastName VARCHAR(255) NOT NULL
);

CREATE TABLE Categories (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    Name VARCHAR(255) NOT NULL
);

CREATE TABLE Books (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    Name VARCHAR(255) NOT NULL,
    AuthorID INT,
    YearPublished INT,
    FOREIGN KEY (AuthorID) REFERENCES Authors(ID)
);

CREATE TABLE Books_Categories (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    BookID INT,
    CategoryID INT,
    FOREIGN KEY (BookID) REFERENCES Books(ID),
    FOREIGN KEY (CategoryID) REFERENCES Categories(ID)
);
GO

CREATE SCHEMA dbo2;
GO

CREATE TABLE dbo2.Movies (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    Name VARCHAR(255) NOT NULL
);

For the dbo schema we create four tables Books, Authors, Categories, and Books_Categories with relationships:

  • Authors have a one-to-many relationship with Books
  • Books have a many-to-many relationship with Categories by using the Books_Categories table as a join table

If these two relationships are new to us, our article on EF Core relationships shows how each one looks in code.

For the dbo2 schema we create the table Movies.

Next, let’s create a view that will show the details of every book with an author from the dbo schema tables:

USE DatabaseFirstDevelopmentUsingEFCorePowerToolsDB
GO

CREATE VIEW BookDetails AS
SELECT
    B.ID AS BookID,
    B.Name AS BookName,
    B.YearPublished,
    A.FirstName AS AuthorFirstName,
    A.LastName AS AuthorLastName,
    C.ID AS CategoryID,
    C.Name AS CategoryName
FROM
    Books B
JOIN
    Authors A ON B.AuthorID = A.ID
LEFT JOIN
    Books_Categories BC ON B.ID = BC.BookID
LEFT JOIN
    Categories C ON BC.CategoryID = C.ID;

Last but not least we will create a function and a stored procedure. Both will receive a category’s ID and return the book number of this category:

CREATE FUNCTION dbo.CountBooksInCategory_FN
(
    @CategoryID INT
)
RETURNS INT
AS
BEGIN
    DECLARE @Count INT;

    SELECT @Count = COUNT(*)
    FROM Books B
    LEFT JOIN Books_Categories BC ON B.ID = BC.BookID
    WHERE BC.CategoryID = @CategoryID;

    RETURN @Count;
END;
GO

CREATE PROCEDURE CountBooksInCategory_SP
(
    @CategoryID INT,
    @BookCount INT OUTPUT
)
AS
BEGIN
    SELECT @BookCount = COUNT(*)
    FROM Books B
    LEFT JOIN Books_Categories BC ON B.ID = BC.BookID
    WHERE BC.CategoryID = @CategoryID;
END;

Reverse Engineer a Database

At this point, after creating our database, it’s time to start reverse engineering it to create the entities and the contexts.

EF Core has its own command for this job, Scaffold-DbContext, and our database-first approach with Scaffold-DbContext article uses it. EF Core Power Tools does the same job through a dialog and saves every choice we make in a config file.

Setup a Datasource

To set a data source, we right-click our project and select EF Core Power Tools. When we select Reverse Engineer, we can see a new window:

EF Core Power Tools' window that let us select the datasource.

Here, we can select a database connection, a SQL Database project, or a Data-tier Application Package (.dacpac) as the data source. This is also where we choose the EF Core version our code targets.

Our screenshots come from an older version of EF Core Power Tools, so today’s dialogs can look a little different, and the one above shows EF Core 7 while our updated sample targets EF Core 10. When they differ, we follow the settings in the text.

Map Database Objects

After selecting a data source EF Core Power Tools detects all custom-created database objects and lets us select which ones we want to map:

Select of database objects in EF Core Power Tools.

In this window, we can change the objects and attributes’ names as well as include or exclude columns from a view or a table. The last step before the objects are created is to select through a large variety of mapping settings:

Basic mapping setting EF Core Power Tools

Advance mapping settings EF Core Power Tools.

From these two windows, we can set all the mapping settings, some of which determine:

  • Whether we want to map only the Entities, the Context, or both
  • The paths and namespaces of the produced classes
  • Naming of the objects (pluralizer)
  • Whether we want to use DataAnnotations or Fluent API
  • The customization of code using Handlebars/ T4

This procedure will produce the DbContext class, the Entities classes along with a efpt.config.json file which includes all the mapping settings.

For our stored procedure and function, it also generates the code to call them. The context gets a Procedures property with a CountBooksInCategory_SPAsync() method, and the function becomes a static CountBooksInCategory_FN() method marked with [DbFunction], so we can use it inside LINQ queries. For the calls themselves, our article on executing stored procedures with EF Core goes into more detail.

Modify Generated Mapping

By selecting the Always include all database objects option, we have the flexibility to effortlessly add or remove database objects. This choice enables us to implement any alterations to the entities and the context with a simple right-click on the configuration file and selecting EF Core Power Tools – Refresh. If for any reason we want to apply the changes manually each time, we can do that by right-clicking the configuration file and selecting the EF Core Power Tools – Edit. Following this, we proceed with the steps from the initial setup.

Use Multiple Database Contexts

To enable the presence of multiple contexts within our project using EF Core Power Tools, we can create a second configuration file adhering to the format efpt.*.config.json. Additionally, the second DBContext class should be located in a distinct path from the first one to prevent file overlap and potential overwriting.

Let’s see an example of how we can do that for the dbo2 schema we created earlier. First, we select the database objects we want to map:

Select database objects of a second schema.

Then we can choose the mapping settings for this context and its entities but keep in mind the location limitation of the context class we mentioned before:

Mapping settings for the second schema.Advanced mapping settings for second schema.

Customize Created Code

As we can see in the screenshots, when we select the mapping setting there is the option of code customization using a template (either Handlebars or T4).

Handlebars Customization

When we select the C# – Handlebars option, EF Core Power Tools will automatically generate a CodeTemplates folder. It includes CSharpDbContext and CSharpEntityType folders:

Handlebars generated files.

These subfolders serve as containers for Handlebars templates that enable extensive customization of various aspects of code generation. They allow us to tailor Entity and DbContext classes’ constructors, import statements, and properties according to our specific requirements. Each of these templates is stored as a partial .hbs (Handlebars) file and is used inside the main files (DbContext.hbs or Class.hbs).

For example, let’s say that we want to add an import statement for the EFCorePowerToolsExample.Data namespace that will be inside every entity class. We can do this by adding the using EFCorePowerToolsExample.Data; inside Imports.hbs file:

using EFCorePowerToolsExample.Data;
using System;
using System.Collections.Generic;
{{#if use-data-annotations}}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
{{/if}}
{{#each imports}}
using {{import}};
{{/each}}

T4 Customization

When we select the C# – T4 option, EF Core Power Tools will automatically generate a CodeTemplates folder with the EFCore folder inside, unless the project already has a non-empty CodeTemplates folder, like the one from the Handlebars step:

Generated T4 files.

To use this feature, we need at least EF Core 8.0. Inside the two .t4 files, we can customize the generated classes by using the T4 template.

The same dropdown also offers C# – T4 (Split DbContext), which moves the configuration of each entity into its own class, and C# – T4 (POCO) for plain classes we can use with micro ORMs.

Benefits of Using EF Core Power Tools

EF Core Power Tools offer a range of benefits that significantly help us streamline and enhance the development process when working with Entity Framework Core.

This tool also gives us a visual representation of the database schema, making it easier for us to understand the underlying data structure. Visualize Database Schema draws the database as a DGML graph, ER Diagram writes it as a Mermaid entity relationship diagram, and Add DbContext Diagram draws our model as a DGML graph.

In addition, EF Core Power Tools automates the code generation process based on the database schema. This automation drastically reduces the need for manual coding and ensures consistency between the application’s data model and the database structure. It also speeds up development and lowers the chance of errors we’d make writing these classes by hand.

Limitations of Using EF Core Power Tools

Even though EF Core Power Tools help us simplify the process of database reverse engineering, it comes with some limitations as well.

We cannot use the current version in older projects, as it requires EF Core 8 or newer. For a project still on EF Core 6 or 7, the maintainer keeps the last compatible builds as separate GitHub releases. Furthermore, some of its features are still in preview or experimental, like the automatic schema folder separation. As a result, some operations may need to be reviewed by us to ensure that the result is the wanted one.

Migrations are also no longer part of the toolbox. The Migrations tool was removed in July 2024, and the project’s wiki now points us to the migrations tooling built into Visual Studio.

Another problem that may occur with EF Core Power Tools is the over-reliance on it. Using it without a good understanding of underlying EF Core concepts can lead us to rely on the tools for tasks that are better handled manually. This could result in less efficient database designs or difficulty troubleshooting complex issues.

Conclusion

In this article, we discussed EF Core Power Tools and its application in the context of database-first development. We began by outlining the prerequisites for using this tool and delved into the process of reverse engineering a database. Additionally, we explored some noteworthy functionalities this tool offers, including the ability to customize code through T4 templates or Handlebars. Finally, we concluded by summarizing the advantages and drawbacks of EF Core Power Tools.

Tested with .NET SDK 10.0.302 and EF Core 10.0.13.