Skip to content

API Reference Overview

SmartSql is a .NET ORM library targeting netstandard2.0 (C# 7.3) that provides XML-managed SQL statements, read/write splitting, caching, dynamic repository proxies, and a middleware-based execution pipeline. Version 4.1.68 is published under the Apache-2.0 license.

This section documents the public API surface of all SmartSql packages.

At a Glance

AspectDetails
Target Frameworknetstandard2.0
Language VersionC# 7.3
LicenseApache-2.0
Current Version4.1.68
AuthorAhoo Wang
Repositorydotnetcore/SmartSql

Package Dependency Diagram

mermaid
graph TD
    subgraph core["Core"]
        style core fill:#161b22,stroke:#30363d,color:#e6edf3
        SmartSql["SmartSql<br>Core ORM Library"]
    end
    subgraph extensions["Extension Packages"]
        style extensions fill:#161b22,stroke:#30363d,color:#e6edf3
        DI["SmartSql.DIExtension"]
        DyRepo["SmartSql.DyRepository"]
        Options["SmartSql.Options"]
        AOP["SmartSql.AOP"]
        Extensions["SmartSql.Extensions"]
        ScriptTag["SmartSql.ScriptTag"]
    end
    subgraph caching["Caching Packages"]
        style caching fill:#161b22,stroke:#30363d,color:#e6edf3
        CacheRedis["SmartSql.Cache.Redis"]
        CacheSync["SmartSql.Cache.Sync"]
        DistCache["SmartSql.DistributedCache"]
    end
    subgraph bulk["Bulk Insert Packages"]
        style bulk fill:#161b22,stroke:#30363d,color:#e6edf3
        BulkBase["SmartSql.Bulk"]
        BulkSQL["SmartSql.Bulk.SqlServer"]
        BulkMSSQL["SmartSql.Bulk.MsSqlServer"]
        BulkMy["SmartSql.Bulk.MySql"]
        BulkMyConn["SmartSql.Bulk.MySqlConnector"]
        BulkPG["SmartSql.Bulk.PostgreSql"]
    end
    subgraph sync["Sync Packages"]
        style sync fill:#161b22,stroke:#30363d,color:#e6edf3
        InvokeSync["SmartSql.InvokeSync"]
        SyncKafka["SmartSql.InvokeSync.Kafka"]
        SyncRMQ["SmartSql.InvokeSync.RabbitMQ"]
    end
    subgraph providers["Database Providers"]
        style providers fill:#161b22,stroke:#30363d,color:#e6edf3
        Oracle["SmartSql.Oracle"]
        TypeHandler["SmartSql.TypeHandler"]
        TypeHandlerPG["SmartSql.TypeHandler.PostgreSql"]
    end

    SmartSql --> DI
    SmartSql --> DyRepo
    SmartSql --> Options
    SmartSql --> AOP
    SmartSql --> Extensions
    SmartSql --> ScriptTag
    SmartSql --> CacheRedis
    SmartSql --> CacheSync
    SmartSql --> DistCache
    BulkBase --> BulkSQL
    BulkBase --> BulkMSSQL
    BulkBase --> BulkMy
    BulkBase --> BulkMyConn
    BulkBase --> BulkPG
    SmartSql --> BulkBase
    SmartSql --> InvokeSync
    InvokeSync --> SyncKafka
    InvokeSync --> SyncRMQ
    SmartSql --> Oracle
    SmartSql --> TypeHandler
    SmartSql --> TypeHandlerPG

NuGet Packages

Core

PackageDescription
SmartSqlCore ORM library with middleware pipeline, XML SQL management, and ISqlMapper

Extensions

PackageDescription
SmartSql.DIExtensionASP.NET Core dependency injection integration (AddSmartSql())
SmartSql.DyRepositoryDynamic proxy repository generation via IL emit
SmartSql.OptionsOptions-pattern configuration builder for appsettings.json
SmartSql.AOPAOP transaction support with [Transaction] attribute
SmartSql.ExtensionsGeneral-purpose extensions
SmartSql.ScriptTagScript tag support for dynamic SQL
SmartSql.DataConnectorData connector service

Caching

PackageDescription
SmartSql.Cache.RedisRedis-based distributed cache provider
SmartSql.Cache.SyncCache synchronization across instances
SmartSql.DistributedCacheDistributed cache abstraction

Bulk Insert

PackageDescription
SmartSql.BulkBase bulk insert abstractions
SmartSql.Bulk.SqlServerSQL Server bulk insert
SmartSql.Bulk.MsSqlServerMS SQL Server bulk insert
SmartSql.Bulk.MySqlMySQL bulk insert
SmartSql.Bulk.MySqlConnectorMySQL (MySqlConnector driver) bulk insert
SmartSql.Bulk.PostgreSqlPostgreSQL bulk insert

Synchronization

PackageDescription
SmartSql.InvokeSyncData synchronization via message queues
SmartSql.InvokeSync.KafkaKafka-based sync transport
SmartSql.InvokeSync.RabbitMQRabbitMQ-based sync transport

Database Providers

PackageDescription
SmartSql.OracleOracle database provider
SmartSql.TypeHandlerJSON and custom type handlers
SmartSql.TypeHandler.PostgreSqlPostgreSQL-specific type handlers

Main Entry Points

SmartSql exposes three primary interfaces that form the public API surface:

mermaid
graph TD
    subgraph entrypoints["Main Entry Points"]
        style entrypoints fill:#161b22,stroke:#30363d,color:#e6edf3
        ISqlMapper["ISqlMapper<br>Data access operations"]
        IDbSessionFactory["IDbSessionFactory<br>Session creation"]
        IDbSession["IDbSession<br>Low-level command execution"]
    end
    subgraph support["Supporting Types"]
        style support fill:#161b22,stroke:#30363d,color:#e6edf3
        SmartSqlBuilder["SmartSqlBuilder<br>Fluent configuration"]
        SmartSqlConfig["SmartSqlConfig<br>Runtime configuration"]
        ITransaction["ITransaction<br>Transaction management"]
        IDbSessionStore["IDbSessionStore<br>Session lifecycle"]
    end

    SmartSqlBuilder -->|".Build()"| ISqlMapper
    SmartSqlBuilder -->|".Build()"| IDbSessionFactory
    IDbSessionFactory -->|"Open()"| IDbSession
    ISqlMapper --> IDbSessionStore
    IDbSessionStore -->|"Open()"| IDbSession
    ISqlMapper -.->|extends| ITransaction
    IDbSession -.->|extends| ITransaction
    SmartSqlBuilder --> SmartSqlConfig

ISqlMapper

The primary data access interface. Provides sync and async methods for executing SQL statements, queries, and retrieving results. It automatically manages session lifecycle (open/close) around each operation. See Core Interfaces for the full method listing.

csharp
// Typical usage
var list = sqlMapper.Query<User>(new RequestContext { FullSqlId = "User.Query" });
var count = await sqlMapper.ExecuteAsync(new RequestContext { FullSqlId = "User.Delete", Request = new { Id = 1 } });

IDbSessionFactory

Creates IDbSession instances for lower-level control. Useful when you need explicit session management or custom data source routing.

csharp
var session = sessionFactory.Open();
var result = session.Query<User>(requestContext);

IDbSession

The lowest-level interface. Provides direct access to DbConnection, DbTransaction, and raw command execution. Exposes events (Opened, Committed, Rollbacked, Disposed) for lifecycle hooks.

SmartSqlBuilder

The fluent entry point for constructing the entire runtime. All configuration flows through SmartSqlBuilder before calling Build(). See Configuration API for the full fluent API.

mermaid
sequenceDiagram
autonumber
    participant App as Application
    participant Builder as SmartSqlBuilder
    participant Config as SmartSqlConfig
    participant Container as SmartSqlContainer

    App->>Builder: UseXmlConfig() or UseDataSource()
    App->>Builder: UseCache()
    App->>Builder: RegisterEntity()
    App->>Builder: AddMiddleware()
    App->>Builder: Build()
    Builder->>Config: Create SmartSqlConfig
    Builder->>Config: Build middleware pipeline
    Builder->>Config: Initialize filters, type handlers
    Builder->>Container: Register(builder)
    Builder-->>App: ISqlMapper, IDbSessionFactory

Cross-References

References

SourceDescription
src/SmartSql/ISqlMapper.csISqlMapper interface definition
src/SmartSql/SqlMapper.csSqlMapper implementation
src/SmartSql/SmartSqlBuilder.csFluent builder
src/SmartSql/Configuration/SmartSqlConfig.csCentral configuration
src/SmartSql/DbSession/IDbSession.csSession interface
src/SmartSql/DbSession/IDbSessionFactory.csSession factory interface
Directory.Build.propsShared build properties

Released under the MIT License.