Skip to content

Add opt-in EF Core entity improvements at framework level - #27

Merged
antosubash merged 1 commit into
mainfrom
claude/efcore-entity-improvements-X8z2C
Mar 29, 2026
Merged

antosubash merged 1 commit into
mainfrom
claude/efcore-entity-improvements-X8z2C

Conversation

@antosubash

@antosubash antosubash commented Mar 29, 2026 •

Copy link
Copy Markdown
Owner

Introduce layered entity interfaces and convenience base classes in
SimpleModule.Core that modules can adopt for automatic field population:

Interfaces (SimpleModule.Core/Entities/):

  • IHasCreationTime, IHasModificationTime — auto-set timestamps
  • IAuditable — timestamps + CreatedBy/UpdatedBy from current user
  • ISoftDelete — intercepts hard delete, converts to soft delete
  • IVersioned — auto-incrementing version number
  • IHasConcurrencyStamp — random concurrency stamp
  • IHasExtraProperties — JSON key-value bag
  • IMultiTenant — auto-set tenant ID from ITenantContext
  • IHasDomainEvents — domain event collection + auto-dispatch

Base classes (SimpleModule.Core/Entities/):

  • Entity — timestamps + concurrency
  • AuditableEntity — + CreatedBy/UpdatedBy
  • FullAuditableEntity — + soft delete + versioning
  • MultiTenantFullAuditableEntity — + tenant + extra properties
  • AuditableAggregateRoot — + domain events

Interceptors (SimpleModule.Database/Interceptors/):

  • EntityInterceptor — populates fields based on interfaces
  • DomainEventInterceptor — dispatches domain events after save
  • EntityChangeInterceptor — invokes IEntityChangeHandler after save

Conventions auto-applied via ApplyModuleSchema():

  • ISoftDelete → global query filter
  • IHasConcurrencyStamp/IVersioned → concurrency tokens
  • IHasExtraProperties → JSON column

Also updates AuditSaveChangesInterceptor to detect soft-delete changes
and log them as Deleted instead of Updated.

Introduce layered entity interfaces and convenience base classes in
SimpleModule.Core that modules can adopt for automatic field population.

Interfaces (SimpleModule.Core/Entities/):
- IHasCreationTime, IHasModificationTime — auto-set timestamps
- IAuditable — timestamps + CreatedBy/UpdatedBy from current user
- ISoftDelete — intercepts hard delete, converts to soft delete
- IVersioned — auto-incrementing version number
- IHasConcurrencyStamp — random concurrency stamp
- IHasExtraProperties — JSON key-value bag
- IMultiTenant — auto-set tenant ID from ITenantContext + query filter
- IHasDomainEvents — domain event collection + auto-dispatch

Base classes (SimpleModule.Core/Entities/):
- Entity<TId> — timestamps + concurrency
- AuditableEntity<TId> — + CreatedBy/UpdatedBy
- FullAuditableEntity<TId> — + soft delete + versioning
- MultiTenantFullAuditableEntity<TId> — + tenant + extra properties
- AuditableAggregateRoot<TId> — + domain events

Interceptors (SimpleModule.Database/Interceptors/):
- EntityInterceptor — populates fields based on interfaces
- DomainEventInterceptor — dispatches domain events after save
- EntityChangeInterceptor — invokes IEntityChangeHandler<T> after save

Conventions auto-applied via ApplyModuleSchema():
- ISoftDelete → global query filter (named)
- IMultiTenant → parameterized query filter via ApplyMultiTenantFilters()
- IHasConcurrencyStamp/IVersioned → concurrency tokens
- IHasExtraProperties → provider-aware JSON column

Uses EF Core 10 named query filters so soft-delete and multi-tenant
filters coexist independently. EntityChangeInterceptor uses compiled
expression-tree delegates for zero-reflection dispatch at runtime.
AuditSaveChangesInterceptor updated to detect soft-delete changes.
@antosubash
antosubash force-pushed the claude/efcore-entity-improvements-X8z2C branch from bc19983 to 72b929f Compare March 29, 2026 19:42
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 72b929f
Status: ✅  Deploy successful!
Preview URL: https://759b46c8.simplemodule-website.pages.dev
Branch Preview URL: https://claude-efcore-entity-improve.simplemodule-website.pages.dev

View logs

@antosubash
antosubash merged commit 7e96c89 into main Mar 29, 2026
3 checks passed
antosubash pushed a commit that referenced this pull request Mar 29, 2026
Migrate FeatureFlagEntity and FeatureFlagOverrideEntity to inherit from
Entity<int>, gaining automatic CreatedAt/UpdatedAt population via the
EntityInterceptor, and ConcurrencyStamp for optimistic concurrency.

Remove manual UpdatedAt assignments since the interceptor handles them.

https://claude.ai/code/session_01Cfi9aG39WHwLr2cmsmPAnK
@antosubash
antosubash deleted the claude/efcore-entity-improvements-X8z2C branch April 1, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant