Skip to content

Commit

Permalink
feat: User-friendly error messages for db constraint violations (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 authored Oct 8, 2024
1 parent d070ce2 commit 617dd2e
Show file tree
Hide file tree
Showing 21 changed files with 1,910 additions and 32 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 5.0.4
# 5.1.0

- feat: Automatically produce user-friendly response messages in behaviors for Save and Delete operations that fail due to a violation of a SQL Server foreign key or unique constraint. This behavior can be controlled with the `DetailedEfConstraintExceptionMessages` setting in `.AddCoalesce(c => c.Configure(o => { ... }))`, or by overriding `StandardBehaviors.GetExceptionResult`. This is not a substitute for adding proper validation or other handling of related entities - it only exists to provide a better user experience in cases where the developer has forgotten to handle these situations. This behavior does respect Coalesce's security model and won't produce descriptions of types or values that the user is not allowed to see.

- refactor: `CoalesceOptions.DetailedEntityFrameworkExceptionMessages` has been renamed to `CoalesceOptions.DetailedEFMigrationExceptionMessages`
- fix: The "Max _N_ items retrieved" message in c-select now accounts for list calls that don't provide a count, e.g. by passing `noCount=true`.

# 5.0.3
Expand Down
6 changes: 6 additions & 0 deletions playground/Coalesce.Domain/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Remove cascading deletes.
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}

modelBuilder.Entity<Product>().OwnsOne(p => p.Details, cb =>
{
cb.OwnsOne(c => c.ManufacturingAddress);
Expand Down
Loading

0 comments on commit 617dd2e

Please sign in to comment.