Hlibz.EntityFrameworkCore.ModelRules
2.0.0-preview.1
dotnet add package Hlibz.EntityFrameworkCore.ModelRules --version 2.0.0-preview.1
NuGet\Install-Package Hlibz.EntityFrameworkCore.ModelRules -Version 2.0.0-preview.1
<PackageReference Include="Hlibz.EntityFrameworkCore.ModelRules" Version="2.0.0-preview.1" />
<PackageVersion Include="Hlibz.EntityFrameworkCore.ModelRules" Version="2.0.0-preview.1" />
<PackageReference Include="Hlibz.EntityFrameworkCore.ModelRules" />
paket add Hlibz.EntityFrameworkCore.ModelRules --version 2.0.0-preview.1
#r "nuget: Hlibz.EntityFrameworkCore.ModelRules, 2.0.0-preview.1"
#:package Hlibz.EntityFrameworkCore.ModelRules@2.0.0-preview.1
#addin nuget:?package=Hlibz.EntityFrameworkCore.ModelRules&version=2.0.0-preview.1&prerelease
#tool nuget:?package=Hlibz.EntityFrameworkCore.ModelRules&version=2.0.0-preview.1&prerelease
![]()
Hlibz.EntityFrameworkCore.ModelRules
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 implementingIModelRule. VerifyAll(() => new BillingDbContext(...), ...)checks several contexts in one test.
Full documentation and a sample: github.com/hlib-zinchenko/Hlibz.EntityFrameworkCore.ModelRules.
| Product | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.12)
-
net11.0
- Microsoft.EntityFrameworkCore.Relational (>= 11.0.0)
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 |