# borisdj/efcore.bulkextensions architecture

> Architecture diagram of the GitHub repository borisdj/efcore.bulkextensions, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/borisdj/efcore.bulkextensions
- Repository: https://github.com/borisdj/efcore.bulkextensions

## Overview

##### Project Type and Purpose
- This is an open-source .NET class library (EFCore.BulkExtensions) that plugs into Entity Framework Core to provide ultra-fast bulk CRUD operations across multiple SQL database providers.
- Its core use cases are high-volume Insert/Update/Delete/Upsert/Read/Sync calls on EF Core DbContext, with provider-specific optimizations (SQL Server, PostgreSQL, MySQL, Oracle, SQLite).

##### High-Level Architecture (file-structure analysis)
- EFCore.BulkExtensions.sln
- EFCore.BulkExtensions.Core (shared core logic)
- EFCore.BulkExtensions.SqlServer (/PostgreSql, /MySql, /Oracle, /Sqlite) – each implements the SQL-dialect adapter interfaces defined in Core
- EFCore.BulkExtensions (main NuGet package) – aggregates all provider packages
- EFCore.BulkExtensions.Tests – integration & unit tests, Docker Compose for test DBs
- Directory.Build.props, CI workflows, CONTRIBUTING, GitHub Actions under .github/workflows

##### Key Components
a. EFCore.BulkExtensions.Core
- Contains extension methods (BulkInsert, BulkUpdate, BulkDelete, etc.) on DbContext
- Defines interfaces: ISqlOperationsAdapter, ISqlDialect, IDbServer
- Implements the orchestration: building temp tables, MERGE/COPY/UPSERT statements, BulkConfig, stats, transaction management
b. Provider Adapter Libraries (SqlServer, PostgreSql, MySql, Oracle, Sqlite)
- Each library implements the core interfaces for its SQL dialect (QueryBuilder, DbServer, Adapter)
- Contains provider-specific SQL builders and low-level calls (e.g., SqlBulkCopy for SQL Server, COPY for Postgres)
c. EFCore.BulkExtensions (aggregate NuGet)
- References Core + all provider libraries
- Single-point package for users
d. Entity Framework Core (external)
- Provides DbContext, ChangeTracker, EF Core metadata
- The user-land application code calls BulkExtensions extension methods on DbContext
e. Databases (external)
- Five target RDBMS instances: SQL Server, PostgreSQL, MySQL, Oracle, SQLite
f. Tests & CI/CD
- EFCore.BulkExtensions.Tests uses Docker Compose to spin up real database containers
- GitHub Actions workflows: build → test → security scan → publish NuGet

##### Relationships & Data Flow
- User Code → calls DbContext.BulkInsert(…)
- Extension method from Core library orchestrates:
→ BulkConfig
→ Temporary table creation (in tempdb or schema)
→ Bulk data load via DataReader or bulk API
→ MERGE / COPY / UPSERT SQL generated by SqlQueryBuilder (provider adapter)
→ Commit transaction
→ (Optional) OUTPUT identity or stats back into entity objects
- Core library depends on EFCore metadata + adapter interfaces
- Provider libs implement those interfaces and register with Core via DI or static mapping (SqlAdaptersMapping)
- Main package ties Core + all providers for easy NuGet consumption
- Tests validate each code path against live DB containers

##### Architectural Patterns & Principles
- Adapter / Plugin Pattern – pluggable SQL-dialect modules implementing a common interface
- Single Responsibility – Core focuses on orchestration, adapters focus on SQL generation/execution
- Dependency Inversion – Core depends on SQL adapter interfaces; concrete providers injected at runtime
- Extension Methods – augment DbContext with bulk methods for seamless EF Core integration
- Modular multi-project solution – separate projects per provider for lighter NuGet packages

##### Essential Elements
- Clear component labels and grouping (Core vs Adapters vs Tests vs External)
- Annotation of key protocols/technologies: .NET 9, EF Core 9, SqlBulkCopy, COPY BINARY, ON DUPLICATE, MERGE
- BulkConfig / transaction boundary around bulk operations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    UserApp["User Application"]:::external

    %% Aggregate Package
    subgraph "Aggregate NuGet Package"
        Aggregate["EFCore.BulkExtensions"]:::internal
    end

    %% Core Library
    subgraph "Core Library"
        Core["EFCore.BulkExtensions.Core"]:::internal
    end

    %% Provider Adapters
    subgraph "Provider Adapter Libraries"
        subgraph "SQL Server Adapter"
            SqlServer["EFCore.BulkExtensions.SqlServer"]:::internal
        end
        subgraph "PostgreSQL Adapter"
            Pg["EFCore.BulkExtensions.PostgreSql"]:::internal
        end
        subgraph "MySQL Adapter"
            MySql["EFCore.BulkExtensions.MySql"]:::internal
        end
        subgraph "Oracle Adapter"
            Oracle["EFCore.BulkExtensions.Oracle"]:::internal
        end
        subgraph "SQLite Adapter"
            SqliteDB["EFCore.BulkExtensions.Sqlite"]:::internal
        end
    end

    %% External Systems
    subgraph "External Systems"
        EFCore["Entity Framework Core"]:::external
        subgraph "Databases"
            SQLSrv["SQL Server"]:::external
            PostgreSQL["PostgreSQL"]:::external
            MySQLDB["MySQL"]:::external
            OracleDB["Oracle"]:::external
            SQLiteDB["SQLite"]:::external
        end
    end

    %% CI and Tests
    subgraph "CI/Test Pipeline"
        CI["GitHub Actions & Docker Compose"]:::ci
        Tests["EFCore.BulkExtensions.Tests"]:::ci
    end

    %% Relationships
    UserApp -->|"BulkInsert(), BulkUpdate(), etc."| Aggregate
    Aggregate -->|"references"| Core
    Aggregate -->|"references"| SqlServer
    Aggregate -->|"references"| Pg
    Aggregate -->|"references"| MySql
    Aggregate -->|"references"| Oracle
    Aggregate -->|"references"| SqliteDB

    Core -->|"depends on EF Core metadata"| EFCore

    SqlServer -->|"implements Core interfaces"| Core
    Pg -->|"implements Core interfaces"| Core
    MySql -->|"implements Core interfaces"| Core
    Oracle -->|"implements Core interfaces"| Core
    SqliteDB -->|"implements Core interfaces"| Core

    SqlServer -->|"executes MERGE SQL / SqlBulkCopy"| SQLSrv
    Pg -->|"executes COPY BINARY / COPY SQL"| PostgreSQL
    MySql -->|"executes ON DUPLICATE KEY"| MySQLDB
    Oracle -->|"executes MERGE SQL"| OracleDB
    SqliteDB -->|"executes UPSERT SQL"| SQLiteDB

    CI -->|"runs tests"| Tests
    Tests -->|"integration tests on containers"| SQLSrv
    Tests -->|"integration tests on containers"| PostgreSQL
    Tests -->|"integration tests on containers"| MySQLDB
    Tests -->|"integration tests on containers"| OracleDB
    Tests -->|"integration tests on containers"| SQLiteDB

    %% Click Events
    click Core "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.Core/"
    click SqlServer "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.SqlServer/"
    click Pg "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.PostgreSql/"
    click MySql "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.MySql/"
    click Oracle "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.Oracle/"
    click SqliteDB "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.Sqlite/"
    click Aggregate "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions/"
    click Tests "https://github.com/borisdj/efcore.bulkextensions/tree/master/EFCore.BulkExtensions.Tests/"
    click CI "https://github.com/borisdj/efcore.bulkextensions/tree/master/.github/workflows/"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef ci fill:#FFA500,stroke:#333,stroke-width:1px
```
