Skip to content
bitzorcas
中EN

Concept

Multi-ORM Dual-Engine Architecture & Selection Matrix

In-depth architecture of BitzOrcas.Modern persistence adapters: division of responsibilities, selection matrix, and dual-engine coexistence for SqlSugar, EF Core, Dapper, and MongoDB.

Last updated

Multi-ORM Dual-Engine Architecture & Selection Matrix

In enterprise backend engineering, selecting an Object-Relational Mapper (ORM) often leads to heated debates:

  • SqlSugar: Highly agile CodeFirst schema synchronization, automated table partitioning by date, and built-in snowflake sequence generation;
  • Entity Framework Core (EF Core): Microsoft’s flagship ORM with strict type-safety, comprehensive LINQ translation, and powerful navigation graph tracking;
  • Dapper: Minimal memory overhead, near bare-metal ADO.NET throughput, and ideal support for complex read-side reporting;
  • MongoDB: The gold standard for unstructured audit event logging, operational payload archiving, and schema-less document collections.

BitzOrcas.Modern avoids false dichotomies by implementing a Multi-ORM Dual-Engine architecture within src/Framework. Through unified abstractions (IRepository<T, TId>, IUnitOfWork, and strongly typed read ports), different database adapters cooperate harmoniously within the same application.


1. Division of Responsibilities Across Four Engines

BitzOrcas defines distinct boundaries and responsibilities for each adapter:

Underlying StorageBitzOrcas Persistence AdaptersCQRS Request Flow

Business Write Commands

Business Read Queries

Audit Trails & Payloads

BitzOrcas.Infrastructure.SqlSugar
(Primary Write Engine: CodeFirst, Partitioning, Auto-DDL)

BitzOrcas.Infrastructure.EfCore
(Alternative Write Engine: Entity Graphs, ChangeTracker)

BitzOrcas.Infrastructure.Dapper
(High-Throughput Read Engine: Connection Pooling, DTOs)

BitzOrcas.Infrastructure.Mongo
(Document Archiving: Massive Audit Trails, Dynamic Payloads)

SQL Server / PostgreSQL (Write DB)

Read Replica Instance

MongoDB Document Cluster

Engine Selection Matrix & Trade-offs

Persistence EnginePrimary StrengthsIdeal ScenarioRole in BitzOrcas
SqlSugar- Catalog probing and sub-second column/table patching
- Automated physical table partitioning by month/day
- Built-in snowflake primary key generation
Teams seeking rapid feature iteration and automated schema evolution without manual migration filesDefault Primary Write Engine: Powers platform capabilities (Identity, Workflow, Tickets) and business aggregate CodeFirst management.
EF Core- Strict ChangeTracker lifecycle
- Comprehensive Fluent API entity relationship mapping
- Native Microsoft ecosystem alignment & AOT support
Teams with deep EF Core expertise requiring navigation property graphs or strict compliance mandatesIsomorphic Alternative Write Engine: Provides aggregate repositories and CAP outbox support via BitzOrcasDbContext.
Dapper- Micro-ORM with near-zero allocation overhead
- Full control over hand-optimized raw SQL
- Ideal for multi-pool connection distribution
High-concurrency dashboards, complex multi-join analytical queries, and low-latency paginated listingsDedicated Read Engine: Implements IReadStore ports against read-only database replicas.
MongoDB- Dynamic BSON document storage
- High-throughput ingestion without lock contention
- Ideal for wide tables and arbitrary JSON payloads
Large-scale event tracing, audit trail snapshots, and historical webhook payloadsAudit Archiving Engine: Offloads high-volume operational events from relational tables.

2. Isomorphic Entity Invariant

To ensure business modules can switch between SqlSugar and EF Core without rewriting domain models, BitzOrcas enforces the Isomorphic Entity Invariant:

  1. Unified Base Types: All domain aggregate roots inherit from TenantAggregateRoot<TId> or Entity<TId>;
  2. Adapter-Neutral Metadata & Fluent Parity:
    • Aggregate classes declare compile-time adapter-neutral metadata ([BitzTable], [BitzColumn]) from BitzOrcas.Persistence.Metadata, keeping the Contracts tier 100% ORM-neutral without direct SqlSugar or EF Core package dependencies;
    • In persistence infrastructure, source generators automate adapter translation, while EF Core mappings can reside in dedicated IEntityTypeConfiguration<T> classes without contaminating domain logic;
  3. Transactional Outbox Parity: Both SqlSugarUnitOfWork and EfCoreUnitOfWork integrate with DotNetCore.CAP, binding domain event dispatch atomically to underlying database commits.

3. Host Composition & Dependency Injection

Switching primary persistence engines in src/Hosts/BitzOrcas.Api requires a single configuration line:

// Option A: Use SqlSugar as primary write engine (Recommended Default)
builder.Services.AddBitzOrcasSqlSugar(builder.Configuration);
// Option B: Use EF Core as primary write engine
builder.Services.AddBitzOrcasEfCore(builder.Configuration);
// Additive: Enable Dapper for specialized read ports
builder.Services.AddBitzOrcasDapper(builder.Configuration);

100%

Scroll or use controls to zoom · drag when enlarged · double-click for 100% / 200%