Pondhawk.Rules.EFCore
1.0.24
dotnet add package Pondhawk.Rules.EFCore --version 1.0.24
NuGet\Install-Package Pondhawk.Rules.EFCore -Version 1.0.24
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="Pondhawk.Rules.EFCore" Version="1.0.24" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pondhawk.Rules.EFCore" Version="1.0.24" />
<PackageReference Include="Pondhawk.Rules.EFCore" />
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 Pondhawk.Rules.EFCore --version 1.0.24
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Pondhawk.Rules.EFCore, 1.0.24"
#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 Pondhawk.Rules.EFCore@1.0.24
#: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=Pondhawk.Rules.EFCore&version=1.0.24
#tool nuget:?package=Pondhawk.Rules.EFCore&version=1.0.24
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Pondhawk.Rules.EFCore
Pre-save entity validation interceptor for EF Core powered by the Pondhawk.Rules engine. Validates all Added and Modified entities through your rule set before they reach the database.
Quick Start
Configure Validation
using Pondhawk.Rules.EFCore;
using Pondhawk.Rules.Factory;
// Define validation rules
var ruleSet = new RuleSet();
ruleSet.AddValidation<Order>("total-positive")
.Assert<decimal>(o => o.Total)
.IsGreaterThan(0m);
ruleSet.AddValidation<Order>("items-required")
.AssertOver<OrderItem>(o => o.Items)
.IsNotEmpty();
// Wire into DbContext
var options = new DbContextOptionsBuilder<AppContext>()
.UseSqlServer(connectionString)
.AddRuleValidation(ruleSet)
.Options;
Automatic SaveChanges Validation
var context = new AppContext(options);
var order = new Order { Total = 100m, Items = [new OrderItem()] };
context.Orders.Add(order);
await context.SaveChangesAsync();
// Interceptor validates all Added/Modified entities
// Throws EntityValidationException if violations exist
Handle Validation Failures
try
{
await context.SaveChangesAsync();
}
catch (EntityValidationException ex)
{
var violations = ex.ValidationResult.Violations;
// violations contains the structured RuleEvent violations
}
How It Works
RuleValidationInterceptorextendsSaveChangesInterceptor.- On
SavingChanges/SavingChangesAsync, it pulls allAddedandModifiedentities fromChangeTracker. - Each entity is validated through
IRuleSet.Validate(). - If any entity fails validation,
EntityValidationExceptionis thrown before the save reaches the database.
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- CommunityToolkit.Diagnostics (>= 8.4.0)
- Microsoft.EntityFrameworkCore (>= 5.0.0)
- Pondhawk.Rules (>= 1.0.24)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.