Skip to main content

Asset Entity Mappings

Summary​

Source-backed EF Core mapping inventory for every persisted entity in the Asset bounded context — table mapping, Guid keys, required properties and lengths, enum-to-string conversions, owned value objects and collections, indexes, query filters, generated values, jsonb columns, and ignored members.

Audience​

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

Overview​

AssetDbContext configures seven persisted entities. The Asset aggregate root owns four value objects and two child collections; audit and timeline are infrastructure evidence entities; the outbox and processed-event tables are messaging infrastructure. All primary keys are Guids. Enum values are stored as strings, and three columns are jsonb.

Confirmed persistence behavior​

Asset (aggregate root → Assets)​

AspectMapping
TableAssets
KeyGuid Id, ValueGeneratedOnAdd (uuid factory-supplied at runtime)
Required propertiesTenantId (int); AssetType varchar(120); Condition, Status; owned Code/Name/Serial/Assignee navigations required
Optional propertiesTenantKey varchar(120); AssignedOnUtc timestamptz; ReturnDueDate timestamp; Notes varchar(2000); WorkflowInstanceId Guid
Enum → stringStatus (AssetStatus) → varchar(40); Condition (AssetCondition) → varchar(40)
Owned valuesAssetCode → AssetCode varchar(80); AssetName → AssetName varchar(200); SerialNumber → SerialNumber varchar(160); AssetAssignee → AssignedToUserId int?, LaborId int?
Owned collectionsHistory — HasMany / WithOne / HasForeignKey(AssetId), cascade; Documents — HasMany / WithOne / HasForeignKey(AssetId), cascade
IndexesUX_Assets_CompatId (unique), IX_Assets_AssetCode (non-unique), IX_Assets_Tenant_Status, IX_Assets_Tenant_Type, IX_Assets_WorkflowInstance
Query filterYes — `IsSuperAdmin
Generated valuesCompatId int — DB identity at runtime (ValueGeneratedNever on backfill); Id Guid factory-supplied
jsonbNone on this table
IgnoredDomainEvents (Ignore); computed IsWorkflowManaged, IsDeletable not mapped

AssetAssignmentHistory (child → AssetAssignmentHistory)​

AspectMapping
TableAssetAssignmentHistory
KeyGuid Id, ValueGeneratedNever (avoids phantom-Modified; nav-added rows insert)
Required propertiesTenantId (int); AssetId (Guid, FK); Action varchar(60); Condition; Actor varchar(256), default system
Optional propertiesUserId int?, LaborId int?; Notes varchar(2000); OccurredOnUtc timestamptz
Enum → stringCondition (AssetCondition) → varchar(40)
Owned valuesNone
IndexesIX_AssetAssignmentHistory_AssetId (convention FK), IX_AssetHistory_Tenant_Asset (TenantId,AssetId)
Query filterYes
Generated valuesKey not store-generated (append-only inserts)
jsonbNone
IgnoredNone documented

AssetDocumentReference (child → AssetDocumentReferences)​

AspectMapping
TableAssetDocumentReferences
KeyGuid Id, ValueGeneratedNever
Required propertiesTenantId (int); AssetId (Guid, FK); DocumentType varchar(80); FileName varchar(400); StorageObjectKey varchar(500); UploadedBy varchar(256); SizeBytes bigint; UploadedOnUtc
Optional propertiesContentType varchar(160); DocumentServiceId Guid?; StorageObjectId Guid?; Sha256 varchar(128)
Enum → stringNone
Owned valuesNone
IndexesIX_AssetDocumentReferences_AssetId (convention FK), IX_AssetDocuments_Tenant_Asset (TenantId,AssetId)
Query filterYes
Generated valuesKey not store-generated
jsonbNone
IgnoredComputed HasStoredContent not mapped

AssetAuditLog (evidence → AssetAuditLogs)​

AspectMapping
TableAssetAuditLogs
KeyGuid Id
Required propertiesTenantId (int); EntityType varchar(120); EntityId varchar(80) — string reference, not a FK; Action varchar(120); ActorEmail varchar(256), default system; OccurredAtUtc
Optional propertiesDetailsJson
Enum → stringNone
IndexesIX_AssetAuditLogs_TenantId_OccurredAtUtc (TenantId,OccurredAtUtc)
Query filterYes
jsonbDetailsJson
IgnoredNone documented

AssetTimeline (evidence → AssetTimeline)​

AspectMapping
TableAssetTimeline
KeyGuid Id
Required propertiesTenantId (int); EntityType varchar(120); EntityId varchar(80); EntryType varchar(80); Category varchar(60), default Asset; Actor varchar(256); OccurredAtUtc
Optional propertiesDescription varchar(2000); MetadataJson
IndexesIX_AssetTimeline_Tenant_Occurred (TenantId,OccurredAtUtc)
Query filterYes
jsonbMetadataJson
IgnoredNone documented

ProcessedIntegrationEvent (messaging → ProcessedIntegrationEvents)​

AspectMapping
TableProcessedIntegrationEvents
KeyGuid Id
Required propertiesEventId Guid; EventType varchar(160); SourceService varchar(120); Outcome varchar(40), default Processed; ProcessedOnUtc
Optional propertiesTenantId int?; CorrelationId varchar(160)
IndexesUX_ProcessedEvents_EventId (unique)
Query filterNo
jsonbNone
IgnoredNone documented

OutboxMessage (messaging → OutboxMessages, shared kernel)​

AspectMapping
TableOutboxMessages
KeyGuid Id
Required propertiesEventId Guid; EventType varchar(160); PayloadJson; OccurredAtUtc; Status varchar(40); RetryCount int; SourceService varchar(120)
Optional propertiesProcessedOnUtc; ErrorMessage varchar(1000); CorrelationId varchar(120); TenantId Guid? (envelope tenant, null for asset events)
IndexesIX_OutboxMessages_EventId (unique), IX_OutboxMessages_Status_OccurredAtUtc (Status,OccurredAtUtc)
Query filterNo
jsonbPayloadJson
IgnoredNone documented

Classification​

Implemented EF Core mappings with a Transitional compatibility surface.

Requires confirmation​

Additional mapping hardening (for example database uniqueness on business codes, concurrency tokens) is not present in source and requires confirmation.

Diagram​

See Also​

Keywords​

  • Asset mappings
  • Entity Mappings
  • Entity mappings

Source References​

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

Revision Information​

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