# omar-adel11/linq2db architecture

> Architecture diagram of the GitHub repository omar-adel11/linq2db, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omar-adel11/linq2db
- Repository: https://github.com/omar-adel11/linq2db

## Overview

LINQ to DB turns typed LINQ expressions over mapped POCOs into provider-specific SQL and executes that SQL through a database connection. The main path is query construction, translation and execution; mapping, provider configuration, SQL extensions, and CLI scaffolding are meaningful adjacent capabilities. Relationships among unsampled translation internals are kept conservative: the README supports the principal workflow, while source-index references and excerpts support the cited internal links.

Main entry points: [`Source/LinqToDB/Internal/Linq/Query.cs`](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/Linq/Query.cs) (Query expressions), [`Source/LinqToDB.CLI/CommandLine/Commands/Scaffold/ScaffoldCommand.Execute.cs`](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.CLI/CommandLine/Commands/Scaffold/ScaffoldCommand.Execute.cs) (Model scaffolding), [`Source/LinqToDB/Linq/Expressions.cs`](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Linq/Expressions.cs) (LINQ API), [`Source/LinqToDB/DataProvider/IDataProvider.cs`](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/DataProvider/IDataProvider.cs) (Data provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_query["Query processing"]
  node_linq_api["LINQ API<br/>[Expressions.cs]"]
  node_query_expression["Query expressions<br/>[Query.cs]"]
  node_expression_cache["Expression cache"]
  node_mapping["POCO mapping<br/>[MappingSchema.cs]"]
end

subgraph group_runtime["Execution runtime"]
  node_provider["Data provider<br/>[IDataProvider.cs]"]
  node_provider_flags["SQL capabilities"]
  node_options["Data options<br/>[DataOptions.cs]"]
  node_context["Data context<br/>[IDataContext.cs]"]
  node_connection["Database connection<br/>[DataConnection.cs]"]
  node_query_runner["Query runner"]
end

subgraph group_scaffold["Schema scaffolding"]
  node_cli["CLI commands<br/>[CliController.cs]"]
  node_scaffold["Model scaffolding"]
  node_schema["Database schema<br/>[DatabaseModel.cs]"]
  node_generated_code["Generated POCOs"]
end

subgraph group_integration["Extensibility"]
  node_sql_functions["SQL functions<br/>[Sql.cs]"]
  node_remote_service["Remote service API<br/>[ILinqService.cs]"]
end

node_developer(("Application code"))
node_database[("Database")]

node_developer -->|"writes queries"| node_linq_api
node_linq_api -.->|"builds expressions"| node_query_expression
node_query_expression -->|"uses cache"| node_expression_cache
node_query_expression -.->|"maps types"| node_mapping
node_query_expression -->|"translates functions"| node_sql_functions
node_options -->|"configures provider"| node_provider
node_context -->|"holds options"| node_options
node_query_runner -->|"executes through"| node_connection
node_connection -.->|"runs SQL"| node_database
node_provider -.->|"provides capabilities"| node_provider_flags
node_developer -->|"invokes tool"| node_cli
node_cli -.->|"dispatches command"| node_scaffold
node_scaffold -.->|"reads schema"| node_schema
node_scaffold -.->|"generates models"| node_generated_code
node_remote_service -.->|"serves queries"| node_query_runner

click node_linq_api "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Linq/Expressions.cs"
click node_query_expression "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/Linq/Query.cs"
click node_expression_cache "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/Linq/ExpressionCacheManager.cs"
click node_mapping "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Mapping/MappingSchema.cs"
click node_sql_functions "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Sql/Sql.cs"
click node_provider "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/DataProvider/IDataProvider.cs"
click node_provider_flags "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/SqlProvider/SqlProviderFlags.cs"
click node_options "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/DataOptions.cs"
click node_context "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/IDataContext.cs"
click node_connection "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Data/DataConnection.cs"
click node_query_runner "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Data/DataConnection.QueryRunner.cs"
click node_cli "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.CLI/CommandLine/CliController.cs"
click node_scaffold "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.CLI/CommandLine/Commands/Scaffold/ScaffoldCommand.Execute.cs"
click node_schema "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.Scaffold/DataModel/Model/DatabaseModel.cs"
click node_generated_code "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.Scaffold/DataModel/DataModelGenerator.DataContext.cs"
click node_remote_service "https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Remote/ILinqService.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_linq_api,node_query_expression,node_expression_cache,node_mapping toneBlue
class node_provider,node_provider_flags,node_options,node_context,node_connection,node_query_runner,node_database toneAmber
class node_cli,node_scaffold,node_schema,node_generated_code toneMint
class node_sql_functions,node_remote_service toneRose
class node_developer toneIndigo
```

## Components

### Query processing

- [LINQ API](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Linq/Expressions.cs): `Source/LinqToDB/Linq/Expressions.cs`
- [Query expressions](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/Linq/Query.cs): `Source/LinqToDB/Internal/Linq/Query.cs`
- [Expression cache](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/Linq/ExpressionCacheManager.cs): `Source/LinqToDB/Internal/Linq/ExpressionCacheManager.cs`
- [POCO mapping](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Mapping/MappingSchema.cs): `Source/LinqToDB/Mapping/MappingSchema.cs`

### Execution runtime

- [Data provider](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/DataProvider/IDataProvider.cs): `Source/LinqToDB/DataProvider/IDataProvider.cs`
- [SQL capabilities](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Internal/SqlProvider/SqlProviderFlags.cs): `Source/LinqToDB/Internal/SqlProvider/SqlProviderFlags.cs`
- [Data options](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/DataOptions.cs): `Source/LinqToDB/DataOptions.cs`
- [Data context](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/IDataContext.cs): `Source/LinqToDB/IDataContext.cs`
- [Database connection](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Data/DataConnection.cs): `Source/LinqToDB/Data/DataConnection.cs`
- [Query runner](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Data/DataConnection.QueryRunner.cs): `Source/LinqToDB/Data/DataConnection.QueryRunner.cs`

### Schema scaffolding

- [CLI commands](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.CLI/CommandLine/CliController.cs): `Source/LinqToDB.CLI/CommandLine/CliController.cs`
- [Model scaffolding](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.CLI/CommandLine/Commands/Scaffold/ScaffoldCommand.Execute.cs): `Source/LinqToDB.CLI/CommandLine/Commands/Scaffold/ScaffoldCommand.Execute.cs`
- [Database schema](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.Scaffold/DataModel/Model/DatabaseModel.cs): `Source/LinqToDB.Scaffold/DataModel/Model/DatabaseModel.cs`
- [Generated POCOs](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB.Scaffold/DataModel/DataModelGenerator.DataContext.cs): `Source/LinqToDB.Scaffold/DataModel/DataModelGenerator.DataContext.cs`

### Extensibility

- [SQL functions](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Sql/Sql.cs): `Source/LinqToDB/Sql/Sql.cs`
- [Remote service API](https://github.com/omar-adel11/linq2db/blob/master/Source/LinqToDB/Remote/ILinqService.cs): `Source/LinqToDB/Remote/ILinqService.cs`

### Other components

- **Application code**
- **Database**

## Connections

- Application code → LINQ API: writes queries (evidence: `README.md`)
- LINQ API → Query expressions: builds expressions (evidence: `Source/LinqToDB/Internal/Linq/Query.cs`)
- Query expressions → Expression cache: uses cache (evidence: `Source/LinqToDB/Internal/Linq/ExpressionCacheManager.cs`)
- Query expressions → POCO mapping: maps types (evidence: `Source/LinqToDB/Internal/Linq/Query.cs`)
- Query expressions → SQL functions: translates functions (evidence: `Source/LinqToDB/Sql/Sql.cs`)
- Data options → Data provider: configures provider (evidence: `Source/LinqToDB/DataOptions.cs`)
- Data context → Data options: holds options (evidence: `Source/LinqToDB/IDataContext.cs`)
- Query runner → Database connection: executes through (evidence: `Source/LinqToDB/Data/DataConnection.QueryRunner.cs`)
- Database connection → Database: runs SQL
- Data provider → SQL capabilities: provides capabilities
- Application code → CLI commands: invokes tool (evidence: `README.md`)
- CLI commands → Model scaffolding: dispatches command
- Model scaffolding → Database schema: reads schema
- Model scaffolding → Generated POCOs: generates models
- Remote service API → Query runner: serves queries
