Skip to main content

Employee Database Overview

Summary

Employee Service uses EF Core code-first persistence with the Npgsql PostgreSQL provider. One context owns the Employee bounded-context schema and coordinates aggregate state, audit records, timeline entries, and outbox records.

Audience

  • Backend developers and QA engineers
  • DevOps engineers and solution architects

Overview

EmployeeDbContext is registered per request. Repository adapters expose Employee, Department, Designation, and timeline persistence ports. UnitOfWork delegates one commit to the context; the context converts queued domain events into outbox messages before saving. Read paths use tenant-filtered queries and frequent no-tracking projections.

Persistence responsibilities

ConcernConfirmed implementationSource
ProviderNpgsql EF Core provider for PostgreSQLmicroservices/src/employee-service/employee-service.csproj
SchemaDefault employee schemamicroservices/src/employee-service/Infrastructure/EmployeeDbContext.cs
MappingFluent configuration in OnModelCreatingsame
RepositoriesEF-backed aggregate and organization adaptersmicroservices/src/employee-service/Infrastructure/Persistence.cs
Unit of workOne SaveChangesAsync boundary per handler commitsame
SearchComposable no-tracking Employee queriesmicroservices/src/employee-service/Infrastructure/PostgresEmployeeSearchProvider.cs
EvolutionTwo code-first migrations plus current snapshotmicroservices/src/employee-service/Infrastructure/Migrations/

Tenant and history behavior

Global query filters cover Employee roots, Employee child objects, Departments, Designations, and audit logs. Timeline records are child objects and inherit the child filter. Outbox processing uses a separate operational query path. See Tenant isolation.

Legacy relationship

The monolith AppDbContext still owns Legacy Labor, Department, Designation, and related document records. Those are separate models with numeric identifiers. Coexistence does not establish shared-table access or automatic synchronization.

Source References

  • microservices/src/employee-service/Program.cs
  • microservices/src/employee-service/employee-service.csproj
  • microservices/src/employee-service/Infrastructure/EmployeeDbContext.cs
  • microservices/src/employee-service/Infrastructure/Persistence.cs
  • microservices/src/employee-service/Infrastructure/PostgresEmployeeSearchProvider.cs
  • Data/AppDbContext.cs

See Also

Keywords

  • EmployeeDbContext
  • PostgreSQL persistence
  • EF Core code first

Revision Information

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