SmartSql (Document)

SmartSql = MyBatis + Cache(Memory | Redis) + R/W Splitting +Dynamic Repository + Diagnostics

SmartSql (Document)

SmartSql (Document)


SmartSql = MyBatis + Cache(Memory | Redis) + R/W Splitting +Dynamic Repository + Diagnostics ......

Simple, efficient, high-performance, scalable, monitoring, progressive development!

How does she work?

SmartSql draws on MyBatis's ideas, uses XML to manage SQL, and provides several filter tags to eliminate various if/else judgment branches at the code level. SmartSql will manage your SQL and filter the tags to maintain your various conditional judgments at the code level to make your code more beautiful.

Why Choose SmartSql?

The Orm,linq of the DotNet system, which is mostly Linq, is very good, eliminating the developer's reliance on SQL. But it ignores the fact that SQL itself is not complex, and that it is difficult for developers to write Linq to generate good performance SQL in complex query scenarios, and I believe that students who have used EF must have this experience: "I think about how SQL writes, and then I write Linq, It's over. You may also want to see what SQL output of Linq is like. " It was a very bad experience. To be absolutely optimized for SQL, developers must have absolute control over SQL. In addition, SQL itself is very simple, why add a layer of translators?

SmartSql has been out of formal open source for more than two years, in the production environment after several micro-service verification. There are also some businesses that are using SmartSql (if you are also using SmartSql Welcome to submit issue)Who is using SmartSql. Has now joined NCC。 The future (Roadmap-2019) SmartSql will continue to add new features to help developers improve efficiency. Welcome to submit Issue

So why not Dapper, or DbHelper?

Dapper is really good and good performance, but the code that will be ceded to you is filled with SQL and various judgment branches that will make code maintenance difficult to read and maintain. In addition, Dapper only provides DataReader to Entity anti-serialization function. And SmartSql offers a number of features to improve developer efficiency.

Feature Overview

Dynamic Repository

Dynamic Agent Repository (SmartSql.DyRepository) components are SmartSql very unique features that simplify the use of SmartSql. There is little intrusion into the business code. It can be said that using ISqlMapper is the original method, and DyRepository automatically helps you implement these methods.

DyRepository only need to define the Repository interface, through a simple configuration can automatically implement these interfaces and register in the IoC container, when used injection instant acquisition implementation. The principle is to obtain the Scope and SqlId in the XML file of SmartSql through the naming rules of the interface and interface method, use the parameters of the interface method as the Request, and automatically judge the query or perform the operation through the SQL in the XML, and finally realize the ISqlMapper Call.

0. Define Repository interfaces

1. Injection dependencies

2. Use

SmartSql Best practices -> SmartCode

By SmartCode Developers simply configure the database connection to build everything that is required for the solution, including, but not limited to:

  • Solution Engineering

  • Give you a restore.

  • Docker

    • Building Docker Mirroring & Running Instances
  • Open a browser by the way


Directory structure generated by SmartCode

Read and write separation

SmartSql Read and write separation is especially easy, just provide a good configuration can be:


  • Lru Least recently used algorithms
  • Fifo Advanced first-out algorithm
  • RedisCacheProvider
  • Other inherited self-ICacheProvider cache types are available

Type Handler

The SmartSql is implemented internally DotNet the main types of type handlers, and some types of compatible type conversion processors are provided, as well as more commonly used JsonTypeHanlder.

CUD Code generation

SmartSql also provides CUD extension functions to help developers generate good CUD-SQL for direct developer use without having to write any configuration.

Id Generator



AOP Transaction

Transaction nesting

When a transaction is nested, the transaction attribute annotation of the child function is no longer turned on, and the transaction that calls the function by the parent is used instead


Skywalking Monitoring

SmartSql currently supports Skywalking monitoring and is enabled by installing the SkyAPM-dotnet agent. The following is a partial screenshot.

Monitoring execution commands

View whether the cache is cached and the number of records returned

View executed SQL statements



Exception stack Trace

Nuget Packages

Package NuGet Stable Downloads




Click on the link to join the QQ group [SmartSql official QQ group]:604762592


Quick list of the latest Issues we found



Icon For Comments0

在我实际应用中,In中的元素个数会有几百个甚至也许会更多。目前SmartSql中实现时,有多少个元素就会定义多少个参数,类似:@Ids_0,@Ids_1,@Ids_2…… 。这样执行效率会很低。相同条件的查询,使用EFCore时,它会把元素直接拼接到SQL中,不会使用参数化,类似 where id in (1,2,3……)。通过我的对比,EFCore这样的做法会有更好的性能。因此,我建议SmartSql对In也这样处理,不再使用参数化。



Icon For Comments0

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • Update dependency MySqlConnector to v2.1.10
  • Update dependency Oracle.ManagedDataAccess.Core to v2.19.151
  • Update dependency System.Data.SQLite to v1.0.116
  • Update dependency Confluent.Kafka to v1.9.0
  • Update dependency Microsoft.CodeAnalysis.CSharp.Scripting to v4.2.0
  • Update dependency StackExchange.Redis to v2.6.48
  • Update dependency Oracle.ManagedDataAccess.Core to v3
  • Update dependency RabbitMQ.Client to v6
  • Update dependency Serilog.Extensions.Hosting to v5
  • Update dependency Serilog.Extensions.Logging.File to v3
  • Update dependency SkyAPM.Agent.AspNetCore to v2
  • Update dependency SkyAPM.Diagnostics.SmartSql to v2
  • Update dependency Swashbuckle.AspNetCore to v6
  • Update dotnet monorepo (major) (Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.SqlServer, Microsoft.Extensions.Configuration.Abstractions, Microsoft.Extensions.Configuration.EnvironmentVariables, Microsoft.Extensions.Configuration.Json, Microsoft.Extensions.DependencyInjection, Microsoft.Extensions.DependencyInjection.Abstractions, Microsoft.Extensions.Hosting, Microsoft.Extensions.Logging, Microsoft.Extensions.Logging.Abstractions, Microsoft.Extensions.Options, Microsoft.Extensions.Options.ConfigurationExtensions, System.ComponentModel.Annotations, System.Diagnostics.DiagnosticSource)


These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies



  • actions/checkout master
  • actions/setup-dotnet v2



  • Microsoft.SourceLink.GitHub 1.1.1



  • System.Data.SQLite
  • Swashbuckle.AspNetCore 4.0.1
  • SkyAPM.Diagnostics.SmartSql 0.9.0
  • SkyAPM.Agent.AspNetCore 0.9.0


  • AspectCore.Extensions.DependencyInjection 1.2.0


  • Microsoft.Data.SqlClient 4.1.0


  • MySql.Data 8.0.28


  • MySqlConnector 2.1.8


  • Npgsql 4.1.10


  • System.Data.SqlClient 4.8.3



  • StackExchange.Redis 2.5.61
  • Newtonsoft.Json 13.0.1



  • Microsoft.Extensions.DependencyInjection.Abstractions 2.0.0
  • Microsoft.Extensions.Configuration.Abstractions 2.0.0


  • YamlDotNet 11.2.1
  • System.Data.SQLite
  • System.Data.SqlClient 4.8.3
  • Serilog.Sinks.File 5.0.0
  • Serilog.Sinks.Console 4.0.1
  • Serilog.Settings.Configuration 3.3.0
  • Serilog.Extensions.Hosting 3.0.0-dev-00019
  • Oracle.ManagedDataAccess.Core 2.19.140
  • Npgsql 4.1.10
  • MySql.Data 8.0.28
  • Microsoft.Extensions.Options.ConfigurationExtensions 2.2.0
  • Microsoft.Extensions.Hosting 2.2.0
  • Microsoft.Extensions.Configuration.Json 2.2.0
  • Microsoft.Extensions.Configuration.EnvironmentVariables 3.0.0-preview7.19362.4
  • McMaster.Extensions.CommandLineUtils 4.0.1





  • Newtonsoft.Json 13.0.1
  • Confluent.Kafka 1.8.2


  • RabbitMQ.Client 5.2.0
  • Newtonsoft.Json 13.0.1



  • Microsoft.Extensions.Options 2.2.0


  • Oracle.ManagedDataAccess.Core 2.19.140


  • Jint 2.11.58


  • System.Data.SqlClient 4.8.3
  • Microsoft.EntityFrameworkCore.SqlServer 2.2.3
  • Microsoft.EntityFrameworkCore 2.2.3
  • Dapper 1.60.6
  • BenchmarkDotNet 0.13.1


  • xunit.runner.visualstudio 2.4.3
  • xunit 2.4.1
  • Jint 2.11.58
  • Microsoft.CodeAnalysis.CSharp.Scripting 4.1.0
  • System.Data.SqlClient 4.8.3
  • Serilog.Extensions.Logging.File 2.0.0
  • Microsoft.NET.Test.Sdk 16.11.0
  • Microsoft.Extensions.Options.ConfigurationExtensions 2.2.0
  • Microsoft.Extensions.Logging 2.2.0
  • Microsoft.Extensions.DependencyInjection 2.2.0
  • Microsoft.Extensions.Configuration.Json 2.2.0
  • Microsoft.Data.Sqlite 6.0.3


  • System.ComponentModel.Annotations 4.5.0


  • Npgsql 4.1.10


  • Newtonsoft.Json 13.0.1


  • System.Reflection.Emit 4.7.0
  • System.Reflection.Emit.Lightweight 4.7.0
  • System.Diagnostics.DiagnosticSource 4.5.1
  • Microsoft.Extensions.Logging.Abstractions 2.0.0
  • Check this box to trigger a request for Renovate to run again on this repository


Icon For Comments5

Steps to reproduce


<Database> <DbProvider Name="SQLite"/> <Write Name="WriteDB" ConnectionString="${SmartSqlConnectionString}"/> <Read Name="ReadDb-1" ConnectionString="${SmartSqlConnectionString}" Weight="100"/> <Read Name="ReadDb-2" ConnectionString="${SmartSqlConnectionString}" Weight="100"/> </Database>

如上面代码,没有任何配置添加了 SmartSqlConnectionString 的定义

Expected result

能在异常信息里面体现是配置项缺失,如找不到 xx 配置等

Actual result




Icon For Comments0

SmartSql version 4.1.29

Database Mysql and 5.7

Steps to reproduce


    (  ?Id,

Repository: [Statement(Id = "SaveBatch")] int SaveBatch(IList list); Service: Console.WriteLine("开始时间:" + DateTime.Now); UserWechatFriendsRepository.SaveBatch(insertFriends); Console.WriteLine("结束时间:" + DateTime.Now);

Expected result

打印: 开始时间:2019/12/19 20:46:38 结束时间:2019/12/19 20:49:21 3分钟时长

Actual result

//手动拼接sql string sql = CreateSql(insertFriends); Console.WriteLine("执行开始时间:" + DateTime.Now); UserWechatFriendsRepository.SqlMapper.Execute(new SmartSql.RequestContext { Scope = nameof(UserWechatFriends), SqlId = "Insert", RealSql = sql }); Console.WriteLine("执行结束时间:" + DateTime.Now);

打印: 执行开始时间:2019/12/20 11:07:01 执行结束时间:2019/12/20 11:07:02 时长:1s

Stack trace




Icon For Comments3

SmartSql version


Database provider and version

Steps to reproduce

Expected result

namespace SmartSql.DyRepository.Annotations { [AttributeUsage(AttributeTargets.Method||AttributeTargets.Class, AllowMultiple = false)] public class UseTransactionAttribute : Attribute { public IsolationLevel Level { get; set; } = IsolationLevel.Unspecified; } }

Actual result

namespace SmartSql.DyRepository.Annotations { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class UseTransactionAttribute : Attribute { public IsolationLevel Level { get; set; } = IsolationLevel.Unspecified; } }

Stack trace



help wanted
Icon For Comments0




Icon For Comments0

如下所示,获存储过程的返回值,由于手误,参数多了一个空格,希望参数最后空格能自动掉。 new SmartSql.Data.SqlParameter { Name = "TotalRecords ", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.ReturnValue } 希望类似 Name = "TotalRecords " 等这样的参数,前后空可自动掉进。


Quick list of the latest released versions

v4.1.64 - May 13, 2022

What's Changed

Full Changelog:

v4.1.62 - Apr 29, 2022

What's Changed

New Contributors

Full Changelog:

v4.1.59 - Apr 06, 2022

What's Changed

New Contributors

Full Changelog:

v4.1.56 - Jul 14, 2020

  1. MySqlConnector版本升级到1.0.0 -->> thx @ktdynamic

v4.1.55 - Jun 18, 2020

  1. fix TypeDeserializer bug when resultType is String

v4.1.54 - Jun 12, 2020

  • add some Unsigned-TypeHandler
  • optimize bulkInsert datetime format. thx @RocherKong
  • 修复 MYSQL BulkInsert Null值问题。 thx @XiaoHeitu

v4.1.50 - Mar 10, 2020

  1. optimize for #127

  2. add support for Microsoft.Data.SqlClient

  3. add SmartSql.Bulk.MsSqlServer.csproj by Microsoft.Data.SqlClient

v4.1.45 - Dec 18, 2019

  1. add code-of-conduct
  2. fix Concurrent Register EnumTypeHandler bug
  3. add support TypeHandler for CommandType.StoredProcedure

v4.1.42 - Nov 19, 2019

  1. fix #94
  2. fix #113
  3. fix CUD use ColumnAttribute.Name bug
  4. fix #114
  5. add Support for simultaneous use of SqlMap and StatementAttribute
  6. fix #119
  7. Fix ResultMap missing BUG

v4.1.33 - Oct 28, 2019

  1. optimize TypeUtils error msg
  2. add Ordered for Middlewares
  3. fix CUD bug
  4. optimize ConfigBuilder
  5. add support automatically assign [Id] to [Entity] using the IdGenerator

v4.1.29 - Sep 26, 2019

1. add support Auto Converter

configure for SmartSqlConfig.xml

configure for SqlMaps

assign auto converter at RequestContext

v4.1.27 - Aug 30, 2019

  1. fix StatementType parse bug for SmartSql.DataConnector
  2. optimize FlushOnExecuted log
  3. fix ISqlMapperExtensions SessionStore.Dispose bug
  4. optimize PropertyTokenizer
  5. fix #99
  6. fix #100 -> thx #101
  7. optimize #102
  8. add QueryDynamic/QueryDictionary extension for DbSession/SqlMapper
  9. add support same [Scope] for mutil-sqlmap -> thx #104

v4.1.19 - Aug 13, 2019

  1. add AES/DES TypeHandler impl
  2. init SmartSql.DataConnector
  3. task builder register smartsql use alias for SmartSql.DataConnector
  4. optimize Error log
  5. optimize sourceParameterPrefix when null
  6. SmartSql.DataConnector pack as tool
  7. add support Mutil-Publisher-Subscriber for SmartSql.InvokeSync.RabbitMQ
  8. add support Mutil-Publisher-Subscriber for SmartSql.InvokeSync.Kafka
  9. add support DbCommandCreated event for CommandExecuter
  10. fix #89

v4.1.11 - Jul 30, 2019

  1. add support Now-Tag

  2. add support Properties nest propExp

  3. add UsePropertiesFromEnv api for SmartSqlBuilder

  4. add CryptoTypeHandler api - pre

  5. add IFunction api - pre

v4.1.9 - Jul 29, 2019

  1. add support IgnoreDbNull ofr SmartSqlConfig
  2. add support AddTypeHandler for SmartSqlBuilder
  3. add GetSetParameterValue api for TypeHandler
  4. add TypeScan
  5. add RegisterEntity for SmartSqlBuilder
  6. add support TypeHandler for Bulk api
  7. add support Cache-Annotation with Cache-XML Mixed use
  8. optimize PrepareStatement
  9. add support EnablePropertyChangedTrack/ReadDb/CommandTimeout for StatementAttribute

v4.1.5 - Jul 27, 2019

  1. add support CacheKeyTemplate for RequestContext
  2. add Rest api for ICacheManager
  3. add support for dynamic generation of SqlMap with Repository interface

v4.1.3 - Jul 26, 2019

  1. Change Sample DB To SQLite And Fix SQLite ParameterPrefix

  2. add support [For-tag] nest-value-access

  3. optimize Check null-Tag.Property from XML-tag

  4. optimize Check null-Tag.Property ExceptionMessage

  5. add support Cache-Annotations for Repository-interface - Demo

  6. add support ColumnAttribute for EntityDeserializer

  7. add support ColumnAttribute for RequestConvert

  8. add support ParamAttribute for TypeHandler

  9. add ResultType From ArrayType to Object for ExecuteScalar.

v4.1.0 - Jul 24, 2019

v4.0.88 - Jul 24, 2019

  1. add support PropertyChanged for IsProperty-Tag
  2. update SmartSqlMapConfig.EnablePropertyChangedTrack default=false
  3. fix ResolveConfigPath with Env bug
  4. add support OrderBy Tag -> ref #56
  5. optimize deps-version
  6. add PropertyTokenizer
  7. add support nest object access by IGetAccessorFactory
  8. add support nest object access -> ref #51

v4.0.78 - Jul 19, 2019

  1. add support EnablePropertyChangedTrack .ref #49

-> only update Changed Property

or use IRepository

v4.0.76 - Jul 17, 2019

  1. refactor FormatSql
  2. refactor Middleware
  3. add support IFilter

v4.0.73 - Jul 10, 2019

  1. fix #77

v4.0.72 - Jul 05, 2019

  1. refactor SnowflakeId support ToIdString -> {yyyyMMddHHmmssfff}{machineId}{sequenceId}
  2. refactor sync proj
  3. add Kafka Sync Imlp
  4. refactor Cahce
  5. add support #57 ( Using MQ to handle the final consistency of memory-level caches in Service Clusters )

v4.0.65 - Jun 17, 2019

  1. change BeginTransaction return DbTransaction
  2. fix #72
  3. add IRepositoryProxy to DyRepositoryImpl
  4. add IsNotProperty Tag

v4.0.59 - Jun 11, 2019

  1. add SmartSql.InvokeSync proj
  2. add SmartSql.InvokeSync.Kafka proj
  3. add SmartSql.InvokeSync.RabbitMQ proj
  4. add ISyncFilter for InvokeSync
  5. add ISubscriber for InvokeSync
  6. add ValidateParameterMiddleware
  7. add ValidateResultMiddleware
  8. fix Statement DataSourceChoice bug
  9. add support ConcatString Property Expr for Properties
  10. fix #69
  11. add UseCacheManager for SmartSqlBuilder
  12. refactor CacheManager
  13. fix #70
  14. fix #71

v4.0.48 - May 24, 2019

  1. add CustomSnowflakeId
  2. add support MultipleResultMap for ValueTupleDeserializer
  3. add support Colon Key for Properties
  4. add InvokeSucceedListener (support approximate-real-time synchronization to other storage(e.g. ElasticSearch))

v4.0.42 - Apr 28, 2019

  1. add support SmartSql.Bulk.MySqlConnector
  2. add support AOPTransaction to DyRepository interface [Not recommended]
  3. add some Geometric/Network Address/Arrays Types for PostgreSql TypeHandler
  4. add UnknownTypeHandler
  5. fix missing exception stack problem.
  6. fix Postgresql JsonTypeHandler bug
  7. add support CustomDeserializer.
  8. add support CommandTimeout


  1. add support return DictionaryStringObject

v4.0.29 - Apr 18, 2019

  1. Bypass the caching policy after opening a transaction
  2. add TransactionMiddleware
  3. add SmartSql.DyRepository.Annotations.UseTransactionAttribute

v4.0.26 - Apr 18, 2019

  1. support multiple-IdGenerator
  2. add DbSequence
  3. add ISetupSmartSql

v4.0.16 - Apr 12, 2019

  1. add support nest AOP.TransactionAttribute
  2. fix Bulk.SqlServer bug
  3. add BulkExtensions

Library Stats (Sep 15, 2022)

Subscribers: 77
Stars: 877
Forks: 207
Issues: 33


here, otherwise you are in the right place


Dotnet client for Tarantool NoSql database

Some methods are not implemented yet because there are no direct analogs in IProto

Dotnet client for Tarantool NoSql database


coverage (binary format) files to


dotnet-stellar-sdk Stellar API SDK for

Report Bug · Report Security Vulnerability

dotnet-stellar-sdk Stellar API SDK for

dotnet-jwk is a JSON Web Key manager for dotnet

It allow to generate, encrypt, decrypt, convert and check JWK

dotnet-jwk is a JSON Web Key manager for dotnet

Kiota Json Serialization Library for dotnet

The Json Serialization Library for dotnet is the dotnet JSON serialization library implementation with System

Kiota Json Serialization Library for dotnet

Kiota Text Serialization Library for dotnet

The Text Serialization Library for dotnet is the dotnet Text serialization library implementation to handle text/plain responses

Kiota Text Serialization Library for dotnet

dotnet add package Brighid

Protecting the Client Secret

dotnet add package Brighid


A real time chat using C# dotnet and RabbitMQ

dotnet tool install --global dotnet-extract