Repository navigation
Add IgnoreEntity<T>(), and stop an excluded multi-column key from throwing - #1
Merged
Merged
Conversation
…owing The interceptor reported a skipped entity with its key, and reading a multi-column key throws, so a class-level [AuditIgnore] on such an entity - the refusal's own advice - still failed every save. A skip is now reported with an empty key when the key cannot be addressed: the library never composes a multi-column key, and empty is what a report already says for an entity skipped before it was addressed. A non-excluded multi-column key is still refused, and the message now names IgnoreEntity<T>(). IgnoreEntity<T>() / IgnoreEntities(params Type[]) are a class-level [AuditIgnore] for a type the application cannot annotate - the motivating case being DotNetBoost.MultiLingual's Translation, which shares the context and is keyed on four columns. Same rule as the attribute: EntityIgnored, ahead of [Audited] and RequireOptIn, subclasses included, writes by name included. Held in the options rather than the static AuditPlan cache. Build() refuses a type both declared and ignored, and an ignored type that shares a declared entity's stored name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
DotNetBoost.MultiLingual adds a
Translationrow to every catalogue save.Translationhas a multi-column primary key (EntityName, EntityId, PropertyName, LanguageCode), and the EF Core interceptor throws on any multi-column key. As a result,.UseMultiLingual(sp).UseAuditing(sp)can't be used on one context, and dotnetboost-sample records every audit entry by hand as a workaround. This PR is the library half of the fix and is meant to ship as 1.0.0-preview.2.Bug: excluding a multi-column-key entity still threw
The error message tells you to exclude such an entity with
[AuditIgnore]. But when the interceptor skipped an excluded entity, it reported the skip with the entity's key. Reading a multi-column key throws, so[AuditIgnore]andRequireOptInfailed every save anyway.TrackedKeys.KeyForReport.EntityKeyand both key accessors. Empty is also what a report already says for a creation skipped before its key existed..IgnoreEntity<T>().Feature:
IgnoreEntity<TEntity>()/IgnoreEntities(params Type[])This works like a class-level
[AuditIgnore], for a type the application can't annotate because it doesn't own it.EntityIgnored, and it takes precedence over[Audited]andRequireOptIn. Subclasses are ignored too, which also covers EF proxies. A write addressed by name,audit.For("Translation", id), is suppressed as well, and a test checks it behaves the same as a declared[AuditIgnore]type.AuditingOptionsand checked next toplan.Ignored. They are not stored in the staticAuditPlancache, because an ignore is configuration (likeRequireOptIn), not a fact about the type.Build()refuses a type that is both declared and ignored. Declaring coversDeclareEntity,DeclareEntitiesand assembly scans. It also refuses an ignored type whose stored name matches a declared entity's. Because of this, an ignored type can never appear inGET /api/audit/entities.IgnoreEntityand notIgnorebecause EF Core'smodelBuilder.Ignore<T>()means "don't map this type".The only new public API is the two builder methods;
PublicApi.txtis updated.Tests
The new tests were written first and failed before the fix. The
[AuditIgnore]regression test failed with the exact exception from the bug report.Translation-shaped entity with a 4-column key saves beside an auditedProduct, across both create and update.Productgets its entries andTranslationis reported asEntityIgnored.[AuditIgnore]multi-column-key regression.RequireOptIn, an ignored entity is reported asEntityIgnored, not as not opted in.Build().IgnoreEntity<.[AuditIgnore]type.[Audited]andRequireOptIn.Locally, after rebasing onto the Aspire 13.6.4 commit: the Release build is clean, and unit (189), provider (238), API (59) and surface (7) tests pass on net8.0 and net10.0. The 202 integration tests passed locally before the rebase; this PR's CI runs them on amd64.
Docs
Translationexample.1.0.0-preview.2section.configuration-reference.md,limitations.mdandscope.mdare updated.Not in this PR
When an entity's key is generated by the database, the interceptor writes the audit entry in a second save. That second save overwrites MultiLingual translations. The sample will avoid it by assigning keys in code (HiLo).
🤖 Generated with Claude Code