Hlibz.EntityFrameworkCore.ModelRules 2.0.0-preview.1

This is a prerelease version of Hlibz.EntityFrameworkCore.ModelRules.
dotnet add package Hlibz.EntityFrameworkCore.ModelRules --version 2.0.0-preview.1
                    
NuGet\Install-Package Hlibz.EntityFrameworkCore.ModelRules -Version 2.0.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hlibz.EntityFrameworkCore.ModelRules" Version="2.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hlibz.EntityFrameworkCore.ModelRules" Version="2.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Hlibz.EntityFrameworkCore.ModelRules" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hlibz.EntityFrameworkCore.ModelRules --version 2.0.0-preview.1
                    
#r "nuget: Hlibz.EntityFrameworkCore.ModelRules, 2.0.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hlibz.EntityFrameworkCore.ModelRules@2.0.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hlibz.EntityFrameworkCore.ModelRules&version=2.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Hlibz.EntityFrameworkCore.ModelRules&version=2.0.0-preview.1&prerelease
                    
Install as a Cake Tool

Hlibz.EntityFrameworkCore.ModelRules icon

Hlibz.EntityFrameworkCore.ModelRules

NuGet CI

Declarative rules that check a finished EF Core model against your team's conventions. A model that breaks one fails to build, at startup or in a unit test, and the error lists every violation at once, each with a rule ID and how to fix it. EF Core 10 and 11; provider-neutral.

dotnet add package Hlibz.EntityFrameworkCore.ModelRules
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) =>
    configurationBuilder.UseModelRules(rules => rules
        .NoShadowProperties()
        .NamesFollow(NamingStyle.SnakeCase)
        .DecimalsHavePrecision()
        .StringsHaveMaxLength()
        .NoCascadeDeleteAcrossAggregates<IAggregateRoot>()
        .NoRedundantIndexes());

Then one test, so a violation fails CI rather than an app startup. It builds the model without a database, and it is where the rules run when the app uses a compiled model:

[Fact]
public void Model_follows_rules()
{
    using BillingDbContext context = new(options);
    ModelRuleVerifier.Verify(context);
}
ID Rule ID Rule
MR001 NoShadowProperties() MR008 NoCascadeDeleteAcrossAggregates(isRoot)
MR002 NamesFollow(style, scope) MR009 MaxIdentifierLength(max, scope)
MR003 DecimalsHavePrecision() MR010 EntitiesHaveQueryFilter<TMarker>()
MR004 StringsHaveMaxLength() MR011 NoClientSideDeleteBehaviors()
MR005 NullabilityMatchesClr() MR012 NoNavigationsAcrossAggregates(isRoot)
MR006 EnumsStoredAsStrings() MR013 AggregateRootsHaveConcurrencyToken(isRoot)
MR007 SingleSchema(schema?) MR014 NoRedundantIndexes()
  • Each rule is opt-in and independent; rule IDs are never renumbered or reused.
  • Opt entity types or members out per rule (.DecimalsHavePrecision(except => except .Property<Invoice>(x => x.Total))) or out of every rule (.Except(except => except .Entity<OutboxMessage>())). Add your own rules by implementing IModelRule.
  • VerifyAll(() => new BillingDbContext(...), ...) checks several contexts in one test.

Full documentation and a sample: github.com/hlib-zinchenko/Hlibz.EntityFrameworkCore.ModelRules.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0-preview.1 35 11/13/2026
1.1.0 48 11/13/2026
1.0.0 183 9/29/2026
1.0.0-preview.4 89 9/29/2026
1.0.0-preview.3 61 9/29/2026
1.0.0-preview.2 74 9/29/2026
1.0.0-preview.1 67 9/28/2026