SqlSugar is a free, open source databases project written in C# and released under MIT. It has 5,836 GitHub stars, 1,390 forks and 15 open issues, and was last pushed 5 days ago. On this registry it ranks #132 of 203 tracked projects in Databases, with 5 head-to-head comparisons available.

What is SqlSugar?

SqlSugar is an MIT-licensed, open-source object/relational mapping (ORM) framework for .NET that lets C# and VB.NET developers work with more than thirty SQL and NoSQL databases — from SQL Server, MySQL, PostgreSQL, Oracle and SQLite to 达梦, 人大金仓, 神通数据库, ClickHouse, MongoDB and GaussDB — through a single low-code API.

What it is

SqlSugar is a .NET ORM framework maintained and updated by the Fructose Big Data Technology team. It maps C# and VB.NET objects onto relational and NoSQL stores, and it runs across .NET Framework, .NET Core 3.1, and .NET 5 through .NET 10. The project is distributed under the MIT licence, with primary documentation hosted on donet5.com, and ships as the SqlSugar NuGet package.

The concrete problem it solves is hand-written data access code. Rather than writing raw SQL and manual mapping for every table, index and CRUD path, SqlSugar claims genuinely zero-SQL table building: tables, indexes and CRUD operations are all generated from entity definitions and fluent calls. It replaces the boilerplate of hand-maintained ADO.NET queries and the per-database dialects a team would otherwise write by hand, using a single API surface across engines as different as SqlServer, MySql, Sqlite, Oracle, postgresql, DB2, DuckDb, Hana, OceanBase, TDengine, QuestDb and TiDb.

Key capabilities

  • Join query with chained LeftJoin calls that compile to SQL, producing aliased SELECT output such as FROM [Order] o Left JOIN [Custom] cus.
  • Includes navigation for query, insert, update and delete, including multi-level paths like .Includes(x => x.Provinces, x => x.Citys, x => x.Street).
  • Paging through ToPageList(pageIndex, pageSize, ref totalCount), which returns page data and the total count together.
  • Dynamic expression building with Expressionable, Or and ToExpression, letting query predicates be assembled at runtime from collections.
  • Multi-tenant transactions: a single SqlSugarClient can register several ConnectionConfig entries with distinct ConfigId and DbType values, then wrap inserts and queries on different engines in one BeginTran block.
  • Low-code and workflow support: dynamic class building, dynamic table building, non-entity multi-library CRUD, JSON TO SQL, and custom XML.
  • Application patterns including ValueObject, discriminator, repository, UnitOfWork, DbContext and AOP.

Who uses it and how

  • SAAS applications that need tenant sub-database, tenant sub-table and tenant data isolation, plus audit and cross-database query.
  • High-volume write workloads, with stated support for millions of rows written, updated or split across subtables.
  • Analytics-style systems running billion-row query statistics.
  • Teams standardizing data access across many engines, including Chinese domestic databases such as 达梦, 人大金仓, 神通数据库, 瀚高 and GBase.

Getting started

Install the SqlSugar NuGet package, then create a SqlSugarClient with one or more ConnectionConfig entries naming the DbType and connection string; the README's start guide and the donet5.com documentation cover the full setup path.

How it compares

The provided facts list no paid products that SqlSugar replaces, and they name no comparable ORM tools. On the evidence in this registry, SqlSugar stands alone rather than being contrasted with a competing commercial or open-source alternative.

When to use it — and when not to

Choose SqlSugar when a .NET team needs one API over many relational and NoSQL engines, especially when domestic Chinese databases, SAAS tenant isolation or bulk write are on the roadmap. A self-hoster operates only their own databases, since the facts describe a library rather than a hosted service. The honest caveat is presentation: the README excerpt is bilingual, split between English and Chinese, and truncated mid-sample, so real evaluation depends on the separate documentation site rather than the GitHub page alone.

project readme (upstream, from github) — read inline

English | 中文

SqlSugar ORM

SqlSugar is .NET open source ORM framework, maintained and updated by Fructose Big Data Technology team, the most easy-to-use ORM out of the box

Advantages: [Low code] [High performance] [Super simple] [Comprehensive features] [ Multi-database compatible] [Suitable products]

Support .NET

.net framework.net core3.1.ne5.net6.net7.net8 .net9 .net10

Support database

MySql、SqlServer、Sqlite、Oracle 、 postgresql、达梦、Mongodb 人大金仓(国产推荐)、神通数据库、瀚高、Access DB2、DuckDb、Hana、OceanBase TDengine QuestDb Clickhouse MySqlConnector、华为 GaussDB 南大通用 GBase、MariaDB、Tidb、Odbc、Percona Server, Amazon Aurora、Azure Database for MySQL、 Google Cloud SQL for MySQL、custom database

Description

  1. Truly achieve zero SQL ORM table building, index and CRUD all support
  2. Support.NET millions of big data write, update, subtable and has billions of query statistics mature solutions
  3. Support SAAS complete application: cross-database query, audit, tenant sub-database, tenant sub-table and tenant data isolation
  4. Support low code + workflow (dynamic class building, dynamic table building, non-entity multi-library compatible with CRUD, JSON TO SQL, custom XML, etc.)
  5. Support ValueObject, discriminator, repository, UnitOfWork, DbContext, AOP

Documentation

Feature characteristic

Feature1 : Join query

Super simple query syntax

var query  = db.Queryable<Order>()
            .LeftJoin<Custom>  ((o, cus) => o.CustomId == cus.Id)
            .LeftJoin<OrderItem> ((o, cus, oritem ) => o.Id == oritem.OrderId)
            .LeftJoin<OrderItem> ((o, cus, oritem , oritem2) => o.Id == oritem2.OrderId)
            .Where(o => o.Id == 1)  
            .Select((o, cus) => new ViewOrder { Id = o.Id, CustomName = cus.Name })
            .ToList();   
SELECT
  [o].[Id] AS [Id],
  [cus].[Name] AS [CustomName]
FROM
  [Order] o
  Left JOIN [Custom] cus ON ([o].[CustomId] = [cus].[Id])
  Left JOIN [OrderDetail] oritem ON ([o].[Id] = [oritem].[OrderId])
  Left JOIN [OrderDetail] oritem2 ON ([o].[Id] = [oritem2].[OrderId])
WHERE
  ([o].[Id] = @Id0)

Feature2 :Include Query、Insert、Delete and Update


//Includes
var list=db.Queryable<Test>()
           .Includes(x => x.Provinces,x=>x.Citys ,x=>x.Street) //multi-level
           .Includes(x => x.ClassInfo) 
           .ToList();

//Includes+left join        
var list5= db.Queryable<Student_004>()
           .Includes(x => x.school_001, x => x.rooms)
           .Includes(x => x.books)
           .LeftJoin<Order>((x, y) => x.Id==y.sid)
           .Select((x,y) => new Student_004DTO
           {
               SchoolId = x.SchoolId,
               books = x.books,
               school_001 = x.school_001,
               Name=y.Name
           })
           .ToList();          

Feature3 : Page query


 int pageIndex = 1; 
 int pageSize = 20;
 int totalCount=0;
 var page = db.Queryable<Student>().ToPageList(pageIndex, pageSize, ref totalCount);

Feature4 : Dynamic expression

var names= new string [] { "a","b"};
Expressionable<Order> exp = new Expressionable<Order>();
foreach (var item in names)
{
    exp.Or(it => it.Name.Contains(item.ToString()));
}
var list= db.Queryable<Order>().Where(exp.ToExpression()).ToList();
SELECT [Id],[Name],[Price],[CreateTime],[CustomId]
       FROM [Order]  WHERE (
                     ([Name] like '%'+ CAST(@MethodConst0 AS NVARCHAR(MAX))+'%') OR 
                     ([Name] like '%'+ CAST(@MethodConst1 AS NVARCHAR(MAX))+'%')
                    )

Feature5 : Multi-tenant transaction

//Creaate  database object
SqlSugarClient db = new SqlSugarClient(new List<ConnectionConfig>()
{
    new ConnectionConfig(){ ConfigId="0", DbType=DbType.SqlServer,  ConnectionString=Config.ConnectionString, IsAutoCloseConnection=true },
    new ConnectionConfig(){ ConfigId="1", DbType=DbType.MySql, ConnectionString=Config.ConnectionString4 ,IsAutoCloseConnection=true}
});


var mysqldb = db.GetConnection("1");//mysql db
var sqlServerdb = db.GetConnection("0");// sqlserver db
 
db.BeginTran();
            mysqldb.Insertable(new Order()
            {
                CreateTime = DateTime.Now,
                CustomId = 1,
                Name = "a",
                Price = 1
            }).ExecuteCommand();
            mysqldb.Queryable<Order>().ToList();
            sqlServerdb.Queryable<Order>().ToList();

db.CommitTran();

Feature6 : Singleton Pattern

Implement transactions across methods

public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
 {
            DbType = SqlSugar.DbType.SqlServer,
            ConnectionString = Config.ConnectionString,
            IsAutoCloseConnection = true 
  },
  db=> {
            db.Aop.OnLogExecuting = (s, p) =>
            {
                Console.WriteLine(s);
            };
 });
 
 
  using (var tran = Db.UseTran())
  {
          
              
               new Test2().Insert(XX);
               new Test1().Insert(XX);
               ..... 
                ....
                         
             tran.CommitTran(); 
 }

Feature7 : Query filter

//set filter
db.QueryFilter.Add(new TableFilterItem<Order>(it => it.Name.Contains("a")));  
 
   
db.Queryable<Order>().ToList();
//SELECT [Id],[Name],[Price],[CreateTime],[CustomId] FROM [Order]  WHERE  ([Name] like '%'+@MethodConst0+'%')  

db.Queryable<OrderItem, Order>((i, o) => i.OrderId == o.Id)
        .Where(i => i.OrderId != 0)
        .Select("i.*").ToList();
//SELECT i.* FROM [OrderDetail] i  ,[Order]  o  WHERE ( [i].[OrderId] = [o].[Id] )  AND 
//( [i].[OrderId] <> @OrderId0 )  AND  ([o].[Name] like '%'+@MethodConst1+'%')
 

Feature8 : Insert or update

insert or update

Db.Storageable(list2).ExecuteCommand();
Db.Storageable(list2).PageSize(1000).ExecuteCommand();
Db.Storageable(list2).PageSize(1000,exrows=> {   }).ExecuteCommand();

Feature9 : Auto split table

Split entity

[SplitTable(SplitType.Year)]//Table by year (the table supports year, quarter, month, week and day)
[SugarTable("SplitTestTable_{year}{month}{day}")] 
 public class SplitTestTable
 {
     [SugarColumn(IsPrimaryKey =true)]
     public long Id { get; set; }
 
     public string Name { get; set; }
     
     //When the sub-table field is inserted, which table will be inserted according to this field. 
     //When it is updated and deleted, it can also be convenient to use this field to      
     //find out the related table 
     [SplitField] 
     public DateTime CreateTime { get; set; }
 }

Split query

 var lis2t = db.Queryable<OrderSpliteTest>()
.SplitTable(DateTime.Now.Date.AddYears(-1), DateTime.Now)
.ToPageList(1,2); 

Feature10 : Big data insert or update

10.1 BulkCopy
db.Fastest().BulkCopy(lstData);//insert
db.Fastest().PageSize(100000).BulkCopy(insertObjs);
db.Fastest().AS("

readme truncated — read the full docs on github

Frequently asked questions

Is SqlSugar free to use?

SqlSugar is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does SqlSugar do?

.Net aot ORM SqlServer ORM Mongodb ORM MySql 瀚高 Postgresql ORM DB2 Hana 高斯 Duckdb C# VB.NET Sqlite ORM Oracle ORM Mysql Orm 虚谷数据库 达梦 ORM 人大金仓 ORM 神通ORM C#

What is SqlSugar written in?

SqlSugar is primarily written in C#. Its source is publicly available at https://github.com/DotNetNext/SqlSugar, and it has 5,836 GitHub stars.