EntityFrameworkCore.Generator.Core
5.1.1
See the version list below for details.
dotnet add package EntityFrameworkCore.Generator.Core --version 5.1.1
NuGet\Install-Package EntityFrameworkCore.Generator.Core -Version 5.1.1
<PackageReference Include="EntityFrameworkCore.Generator.Core" Version="5.1.1" />
paket add EntityFrameworkCore.Generator.Core --version 5.1.1
#r "nuget: EntityFrameworkCore.Generator.Core, 5.1.1"
// Install EntityFrameworkCore.Generator.Core as a Cake Addin #addin nuget:?package=EntityFrameworkCore.Generator.Core&version=5.1.1 // Install EntityFrameworkCore.Generator.Core as a Cake Tool #tool nuget:?package=EntityFrameworkCore.Generator.Core&version=5.1.1
Overview
.NET Core command-line (CLI) tool to generate Entity Framework Core model from an existing database.
Features
- Entity Framework Core database first model generation
- Safe regeneration via region replacement
- Safe Renaming via mapping file parsing
- Optionally generate read, create and update models from entity
- Optionally generate validation and object mapper classes
Documentation
Entity Framework Core Generator documentation is available via Read the Docs
Installation
To install EntityFrameworkCore.Generator tool, run the following command in the console
dotnet tool install --global EntityFrameworkCore.Generator
After the tool has been install, the efg
command line will be available. Run efg --help
for command line options
Generate Command
Entity Framework Core Generator (efg) creates source code files from a database schema. To generate the files with no configuration, run the following
efg generate -c <ConnectionString>
Replace <ConnectionString>
with a valid database connection string.
Generation Output
The generate
command will create the follow files and directory structure by default. The root directory defaults to the current working directory. Most of the output names and locations can be customized in the configuration file
Data Context Output
The EntityFramework DbContext file will be created in the root directory.
Entities Output
The entities directory will contain the generated source file for entity class representing each table.
Mapping Output
The mapping directory contains a fluent mapping class to map each entity to its table.
Initialize Command
The initialize
command is used to create the configuration yaml file and optionally set the connection string. The configuration file has many options to configure the generated output. See the configuration file documentation for more details.
The following command will create an initial generation.yaml
configuration file as well as setting a user secret to store the connection string.
efg initialize -c <ConnectionString>
When a generation.yaml
configuration file exists, you can run efg generate
in the same directory to generate the source using that configuration file.
Regeneration
Entity Framework Core Generator supports safe regeneration via region replacement and source code parsing. A typical workflow for a project requires many database changes and updates. Being able to regenerate the entities and associated files is a huge time saver.
Region Replacement
All the templates output a region on first generation. On future regeneration, only the regions are replaced. This keeps any other changes you've made to the source file.
Example of a generated entity class
public partial class Status
{
public Status()
{
#region Generated Constructor
Tasks = new HashSet<Task>();
#endregion
}
#region Generated Properties
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsActive { get; set; }
public DateTimeOffset Created { get; set; }
public string CreatedBy { get; set; }
public DateTimeOffset Updated { get; set; }
public string UpdatedBy { get; set; }
public Byte[] RowVersion { get; set; }
#endregion
#region Generated Relationships
public virtual ICollection<Task> Tasks { get; set; }
#endregion
}
When the generate
command is re-run, the Generated Constructor
, Generated Properties
and Generated Relationships
regions will be replace with the current output of the template. Any other changes outside those regions will be safe.
Source Parsing
In order to capture and preserve Entity, Property and DbContext renames, the generate
command parses any existing mapping and DbContext class to capture how things are named. This allows you to use the full extend of Visual Studio's refactoring tools to rename things as you like. Then, when regenerating, those changes won't be lost.
Database Providers
Entity Framework Core Generator supports the following databases.
- SQL Server
- PostgreSQL
- MySQL
- Sqlite
The provider can be set via command line or via the configuration file.
Set via command line
efg generate -c <ConnectionString> -p <Provider>
Set in configuration file
database:
connectionString: 'Data Source=(local);Initial Catalog=Tracker;Integrated Security=True'
provider: SqlServer
Database Schema
The database schema is loaded from the metadata model factory implementation of IDatabaseModelFactory
. Entity Framework Core Generator uses the implemented interface from each of the supported providers similar to how ef dbcontext scaffold
works.
View Models
Entity Framework Core Generator supports generating Read, Create and Update view models from an entity. Many projects rely on view models to shape data. The model templates can be used to quickly get the basic view models created. The model templates also support regeneration so any database change can easily be sync'd to the view models.
Change Log
Version 5.0
- add support for navigation property renames
- update generated query methods to support CancellationToken
- add support for temporal tables
- add regex clean support for table and column names
Version 4.5
- add support for nullable reference types
Version 4.0
- upgrade projects to .net 6
Version 3.1
- Breaking change to generated mapping constants
TableName
is nowTable.Name
TableSchema
is nowTable.Schema
Column{Name}
is nowColumns.{Name}
- add additional automapper for read model to update model
Version 3.0
- Add
Table.Name
andTable.Schema
variable support in yaml configuration. - Add entity name option to control the name of the entity. Leave blank to use previous generate logic. Set under the entity → name yaml settings.
- Add exclude table support. Set under the database → exclude yaml settings.
- Include and Exclude expression can now be
exact
orregex
. When exact, will be direct string match. When regex, will use regular expression to match. Default is regex for legacy support.
Version 2.5
- Add external script template support
- Misc bug fixes
Version 2.0
- Add support for Entity Framework Core 3.0
- Add provider support for PostgreSQL, MySQL and Sqlite
- Add View support
Version 1.1
- Add alias to commands, can use
efg gen
forefg generate
andefg init
forefg initialize
- Fix bug where base class for Entity was placed in wrong location
- Fix misc sorting issue that caused needless source control changes
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.CodeAnalysis.CSharp.Scripting (>= 4.6.0)
- Microsoft.EntityFrameworkCore.Design (>= 7.0.9)
- Microsoft.EntityFrameworkCore.Sqlite (>= 7.0.9)
- Microsoft.EntityFrameworkCore.SqlServer (>= 7.0.9)
- Microsoft.Extensions.Configuration.UserSecrets (>= 7.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 7.0.4)
- Oracle.EntityFrameworkCore (>= 7.21.11)
- Pomelo.EntityFrameworkCore.MySql (>= 7.0.0)
- YamlDotNet (>= 13.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.4.0 | 154 | 7/9/2024 |
6.3.0 | 141 | 5/10/2024 |
6.2.0 | 152 | 3/23/2024 |
6.1.0 | 184 | 2/26/2024 |
6.0.2 | 142 | 2/14/2024 |
6.0.1 | 201 | 1/2/2024 |
6.0.0 | 152 | 1/1/2024 |
5.2.0 | 351 | 8/9/2023 |
5.1.1 | 190 | 7/29/2023 |
5.1.0 | 173 | 7/29/2023 |
4.5.838 | 1,385 | 10/14/2022 |
4.5.726 | 654 | 3/6/2022 |
4.0.682 | 533 | 12/11/2021 |
3.1.0.652 | 523 | 10/21/2021 |
3.1.0.612 | 550 | 7/28/2021 |
3.1.0.599 | 592 | 7/12/2021 |
3.1.0.562 | 521 | 6/3/2021 |
3.1.0.488 | 1,976 | 2/15/2021 |
3.1.0.387 | 722 | 9/13/2020 |
3.1.0.372 | 576 | 8/28/2020 |
3.1.0.346 | 617 | 7/19/2020 |
3.1.0.331 | 679 | 6/27/2020 |
3.1.0.329 | 590 | 6/25/2020 |
3.1.0.328 | 590 | 6/25/2020 |
3.1.0.285 | 694 | 5/14/2020 |
3.0.0.258 | 629 | 4/19/2020 |
2.5.0.253 | 710 | 4/11/2020 |
2.5.0.232 | 590 | 3/17/2020 |
2.5.0.231 | 630 | 3/17/2020 |
2.5.0.226 | 598 | 2/24/2020 |
2.5.0.182 | 706 | 1/23/2020 |
2.5.0.153 | 698 | 12/20/2019 |
2.5.0.152 | 608 | 12/20/2019 |
2.5.0.121 | 670 | 12/3/2019 |
2.5.0.114 | 638 | 11/20/2019 |
2.5.0.59 | 309 | 10/9/2019 |
2.0.0.55 | 665 | 9/24/2019 |
1.1.0.52 | 714 | 9/17/2019 |
1.1.0.49 | 853 | 5/18/2019 |
1.0.0.48 | 706 | 5/16/2019 |
1.0.0.45 | 759 | 4/22/2019 |
1.0.0.41 | 810 | 3/29/2019 |
1.0.0.38 | 771 | 3/20/2019 |
1.0.0.36 | 749 | 2/27/2019 |
1.0.0.34 | 882 | 2/19/2019 |
1.0.0.28 | 840 | 12/6/2018 |
1.0.0.27 | 828 | 11/27/2018 |
1.0.0.26 | 866 | 11/26/2018 |
1.0.0.25 | 859 | 11/26/2018 |
1.0.0.24 | 883 | 11/26/2018 |
1.0.0.22 | 883 | 11/19/2018 |
1.0.0.17 | 858 | 11/14/2018 |
1.0.0.15 | 842 | 11/14/2018 |
1.0.0.14 | 899 | 11/14/2018 |
1.0.0.2 | 878 | 10/24/2018 |