Skip to main content

Asset DbContext and Object Sets

Summary

Source-backed description of AssetDbContext and a verified inventory of its seven object sets — the persistence surface of the Asset bounded context.

Audience

Backend engineers, database reviewers, architects, QA, support, operations, security reviewers, and product owners.

Overview

AssetDbContext is the single EF Core DbContext for the Asset Service. It owns a dedicated logical schema, exposes seven object sets, and overrides SaveChangesAsync to dispatch domain events to the outbox before committing. All persistence for the bounded context flows through it.

Confirmed persistence behavior

AssetDbContext (AssetDbContext : DbContext, in Infrastructure/AssetDbContext.cs):

  • Constructor takes DbContextOptions plus ITenantContext; the tenant context supplies the current tenant id and super-admin flag used by the global query filters.
  • CompatIdStoreGenerated is a protected virtual bool (default true) controlling whether CompatId is a database identity column at runtime. The backfill subclass overrides it to false so migrated identifiers are inserted verbatim. See Compatibility Identity Storage.
  • Default schema is set via HasDefaultSchema(...) to the Asset bounded-context schema (the physical qualifier is redacted here).
  • SaveChangesAsync override dispatches the aggregate's domain events to outbox rows — mapping six asset domain events to contract integration events and running the EnsureComplete completeness guard — and then calls the base save, all in one transaction.
  • Provider: Npgsql PostgreSQL on EF Core 8, with legacy timestamp behavior enabled.
  • Global query filters apply to five of the seven object sets (IsSuperAdmin || TenantId == CurrentTenantId); the two messaging sets are unfiltered.

Object-set inventory

#DbSet propertyCLR typePersistence purposeClassificationAggregate ownershipTenant scopeQuery filterKeyKey relationshipsSource
1AssetsAsset (aggregate root)Canonical asset record with owned value columns and lifecycle stateTenant-domain (aggregate root)RootTenant-scopedYesGuid IdParent of history and document-reference childrenDomain/Asset/Asset.cs
2AssetAssignmentHistoryAssetAssignmentHistory (entity)Append-only lifecycle/assignment logAggregate childOwned by AssetTenant-scopedYesGuid Id (value-generated-never)FK AssetId → Assets (cascade, required)Domain/Asset/Asset.cs
3AssetDocumentReferencesAssetDocumentReference (entity)Pointer/metadata for externally-stored documentsAggregate childOwned by AssetTenant-scopedYesGuid Id (value-generated-never)FK AssetId → Assets (cascade, required)Domain/Asset/Asset.cs
4AuditLogsAssetAuditLog (infrastructure)Append-only audit evidenceAudit (evidence)IndependentTenant-scopedYesGuid IdEntityId is a string reference (not a FK)Infrastructure/AssetDbContext.cs
5TimelineEntriesAssetTimeline (infrastructure)Append-only human-readable timelineTimeline (evidence)IndependentTenant-scopedYesGuid IdEntityId is a string reference (not a FK)Infrastructure/AssetDbContext.cs
6ProcessedEventsProcessedIntegrationEvent (infrastructure)Inbound idempotency ledger (modeled, not yet consumed)Processed-event (messaging)IndependentNot tenant-filteredNoGuid IdUnique index on EventIdInfrastructure/AssetDbContext.cs
7OutboxMessagesOutboxMessage (shared kernel)Outbound integration-event stagingOutbox (messaging)IndependentNot tenant-filteredNoGuid IdUnique index on EventIdshared-kernel

Verified totals

  • 7 object sets mapping to 7 physical tables.
  • 5 tenant-filtered sets (Assets, history, document references, audit, timeline); 2 non-filtered sets (outbox, processed-event).
  • 1 aggregate root (Assets); 2 aggregate children (history, document references).
  • 2 evidence sets (audit, timeline); 2 messaging sets (outbox, processed-event).
  • 0 separate compatibility tables — the compatibility identity is a property on the Asset aggregate, not its own table.

The two messaging sets are deliberately unfiltered because they are infrastructure concerns: the outbox carries envelope-level identifiers, and the processed-event ledger is a modeled foundation that the service does not yet consume at runtime.

Classification

Implemented DbContext with a fully mapped seven-set persistence surface; the processed-event set is Transitional (modeled, unused at runtime).

Requires confirmation

Activation plan for the processed-event idempotency ledger and any future inbound-consumer wiring require confirmation.

Diagram

See Also

Keywords

  • Asset persistence
  • DbContext and Object Sets
  • Draft database documentation

Source References

  • microservices/src/asset-service/Infrastructure/AssetDbContext.cs
  • microservices/src/asset-service/Domain/Asset/Asset.cs
  • microservices/src/asset-service/Infrastructure/Migrations/AssetDbContextModelSnapshot.cs

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-17
  • Review cycle: Quarterly