EntityFrameworkRuler 1.0.22

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global EntityFrameworkRuler --version 1.0.22
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local EntityFrameworkRuler --version 1.0.22
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=EntityFrameworkRuler&version=1.0.22
nuke :add-package EntityFrameworkRuler --version 1.0.22

Entity Framework Ruler - CLI

Automate the customization of the EF Core Reverse Engineered model. Supported changes include:

  • Class renaming
  • Property renaming (including both primitives and navigations)
  • Type changing (useful for enum mapping)
  • Skipping non-mapped columns.
  • Forcing inclusion of simple many-to-many entities into the model.

EF Ruler applies customizations from a rule document stored in the project folder. Rules can be fully generated from an EDMX (from old Entity Framework) such that the scaffolding output will align with the old EF6 EDMX-based model.

"EF Ruler provides a smooth upgrade path from EF6 to EF Core by ensuring that the Reverse Engineered model maps perfectly from the old EDMX structure."

Upgrading from EF6 couldn't be simpler:

  1. The the CLI tool to analyze the EDMX for all customizations and generate the rules.
  2. Reference EntityFrameworkRuler.Design from the EF Core project.
  3. Run the ef dbcontext scaffold command and the design-time service will do the rest.

Done.

Applying Model Customizations:

There are two options for applying the rules to a DB context model:

  1. Simply reference EntityFrameworkRuler.Design from the EF Core project. Proceed with CLI scaffolding (as mentioned above). EntityFrameworkRuler.Design is a Design-Time reference package, meaning EF Core can use it during the scaffolding process to customize the generated model, but the assembly will NOT appear in the project build output. It can't get more automated than this.
  2. Use the CLI tool to apply changes to an already generated EF Core model. This approach uses Roslyn to apply code changes. The code analysis is reliable, but for very large models this option can take a minute.

Road Map:

  • EF Power Tools built-in support.
  • Editor library to manage the rules and edit the EF Core model structure with a UI.

This project is under development! Check back often, and leave comments here.

Installation of the CLI tool:

There are 2 ways to use the CLI tool:

  1. Command line:
    > dotnet tool install --global EntityFrameworkRuler 
    
  2. API:
    > dotnet add package EntityFrameworkRuler   
    PM> NuGet\Install-Package EntityFrameworkRuler
    

See the NuGet page for details.

CLI Usage:

To generate rules from an EDMX, run the following:

> efruler -g <edmxFilePath> <efCoreProjectBasePath>

If both paths are the same, i.e. the EDMX is in the EF Core project folder, it is acceptable to run:

> efruler -g <projectFolderWithEdmx>

Structure rules will be extracted from the EDMX and saved in the EF Core project folder.

To Apply rules to an already generated EF Core model:

> efruler -a <efCoreProjectBasePath>

This assumes that you have executed the ef dbcontext scaffold command to generate the model previously.

API Usage

To generate rules from an EDMX, use the following class:

EntityFrameworkRuler.Generator.RuleGenerator

To Apply rules to an EF Core model, use the following class:

EntityFrameworkRuler.Applicator.RuleApplicator

Examples

Generate and save rules:
var generator = new RuleGenerator(edmxPath);  
var rules = generator.TryGenerateRules();  
await generator.TrySaveRules(projectBasePath);
Apply rules already in project path:
var applicator = new RuleApplicator(projectBasePath);  
var response = await applicator.ApplyRulesInProjectPath();
More control over which rules are applied:
var applicator = new RuleApplicator(projectBasePath);  
var loadResponse = await applicator.LoadRulesInProjectPath();  
var rules = loadResponse.Rules.OfType<DbContextRule>().First();
var applyResponse = await applicator.ApplyRules(rules);
Customize rule file names:
var generator = new RuleGenerator(edmxPath);  
var rules = generator.TryGenerateRules();  
await generator.TrySaveRules(projectBasePath,  
    new RuleFileNameOptions() {  
        DbContextRulesFile = "DbContextRules.json" 
  }  
);
Handle log activity:
var applicator = new RuleApplicator(projectBasePath);  
applicator.OnLog += (sender, message) => Console.WriteLine(message);
var response = await applicator.ApplyRulesInProjectPath();
Product 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.3.45 61 5/2/2024
1.3.44 56 5/2/2024
1.3.43 47 5/2/2024
1.3.42 30 5/2/2024
1.3.40 160 4/4/2024
1.3.9-alpha.0.1 52 4/4/2024
1.3.8 152 3/21/2024
1.3.7 103 3/21/2024
1.3.6 249 12/19/2023
1.3.5 131 11/29/2023
1.3.4 116 11/18/2023
1.2.40 223 10/26/2023
1.2.39 204 10/25/2023
1.2.38 170 10/24/2023
1.2.37 194 10/23/2023
1.2.36 333 7/17/2023
1.2.34-alpha.0.2 92 7/14/2023
1.2.33 225 7/12/2023
1.2.30 190 6/22/2023
1.2.30-alpha.0.1 74 6/21/2023
1.2.29-alpha.0.1 70 6/20/2023
1.2.28 230 6/20/2023
1.2.27 283 4/18/2023
1.2.26 363 3/23/2023
1.2.25 320 3/16/2023
1.2.22 285 3/7/2023
1.2.21 328 3/6/2023
1.2.21-alpha.0.4 95 3/6/2023
1.2.19 292 2/14/2023
1.2.19-alpha.0.4 96 2/14/2023
1.2.17 343 1/31/2023
1.2.16 334 1/27/2023
1.2.15 318 1/27/2023
1.2.14 352 1/26/2023
1.2.13 346 1/25/2023
1.2.10 321 1/25/2023
1.2.9 301 1/25/2023
1.2.8 315 1/25/2023
1.2.7 400 1/24/2023
1.2.6 368 1/24/2023
1.2.5 336 1/24/2023
1.2.4 315 1/18/2023
1.2.3 328 1/17/2023
1.2.3-alpha.0.1 132 1/9/2023
1.2.2 371 1/9/2023
1.2.1-alpha.0.2 157 1/6/2023
1.2.0 352 1/5/2023
1.1.8-alpha.0.16.4 127 1/5/2023
1.1.8-alpha.0.16.2 176 1/5/2023
1.1.8-alpha.0.16.1 183 1/5/2023
1.1.8-alpha.0.16 149 1/5/2023
1.1.8-alpha.0.15 178 1/4/2023
1.1.7 404 12/14/2022
1.1.6-alpha.0.5 106 12/14/2022
1.1.6-alpha.0.4 101 12/13/2022
1.1.6-alpha.0.2 98 12/13/2022
1.1.6-alpha.0.1 95 12/13/2022
1.1.5 370 12/9/2022
1.1.3 355 12/8/2022
1.1.3-alpha.0.2 84 12/8/2022
1.1.3-alpha.0.1 94 12/8/2022
1.1.2 319 12/8/2022
1.1.1 331 12/7/2022
1.1.0 352 12/6/2022
1.0.29-alpha.0.50 101 12/6/2022
1.0.29-alpha.0.48 101 12/6/2022
1.0.29-alpha.0.22 102 11/30/2022
1.0.28 411 11/18/2022
1.0.27 437 11/18/2022
1.0.26 384 11/18/2022
1.0.25 415 11/18/2022
1.0.22 389 11/17/2022
1.0.21 387 11/17/2022
1.0.20 344 11/16/2022
1.0.20-alpha.0.2 96 11/16/2022
1.0.20-alpha.0.1 92 11/16/2022
1.0.19 395 11/16/2022
1.0.18 382 11/16/2022
1.0.17-alpha.0.2 98 11/16/2022
1.0.17-alpha.0.1 102 11/15/2022
1.0.16 368 11/15/2022
1.0.16-alpha.0.2 94 11/15/2022
1.0.14-alpha.0.17 91 11/15/2022