{"id":15019625,"url":"https://github.com/dotnetnext/sqlsugar","last_synced_at":"2025-05-14T22:02:42.225Z","repository":{"id":37209893,"uuid":"38992233","full_name":"DotNetNext/SqlSugar","owner":"DotNetNext","description":".Net aot ORM    Fastest ORM  DB2 Hana   Simple Easy VB.NET Sqlite  orm Oracle ORM Mysql Orm 虚谷数据库  postgresql ORm  SqlServer oRm     达梦 ORM 人大金仓 ORM 神通ORM  C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm Object/Relational Mapping","archived":false,"fork":false,"pushed_at":"2025-04-17T12:48:30.000Z","size":80094,"stargazers_count":5529,"open_issues_count":3,"forks_count":1360,"subscribers_count":257,"default_branch":"master","last_synced_at":"2025-04-17T19:31:23.629Z","etag":null,"topics":["clickhouse","core","mysql","oralce","orm","postgresql","questdb","sqlite","sqlsever"],"latest_commit_sha":null,"homepage":"https://www.donet5.com/Home/Doc","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DotNetNext.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-07-13T05:07:40.000Z","updated_at":"2025-04-17T14:36:40.000Z","dependencies_parsed_at":"2025-04-17T10:17:30.344Z","dependency_job_id":"7d960efb-aab5-43c8-992e-50926000fa4d","html_url":"https://github.com/DotNetNext/SqlSugar","commit_stats":{"total_commits":11359,"total_committers":70,"mean_commits":"162.27142857142857","dds":"0.014173782903424637","last_synced_commit":"0179fef3315ae54d10886292c6ba5b9d79f77d28"},"previous_names":["sunkaixuan/sqlsugar","donet5/sqlsugar"],"tags_count":100,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DotNetNext%2FSqlSugar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DotNetNext%2FSqlSugar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DotNetNext%2FSqlSugar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DotNetNext%2FSqlSugar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DotNetNext","download_url":"https://codeload.github.com/DotNetNext/SqlSugar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250282715,"owners_count":21405032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clickhouse","core","mysql","oralce","orm","postgresql","questdb","sqlite","sqlsever"],"created_at":"2024-09-24T19:53:48.159Z","updated_at":"2025-04-22T16:51:30.883Z","avatar_url":"https://github.com/DotNetNext.png","language":"C#","readme":"\n\u003cp  align=\"center\"\u003e\n    \u003cspan\u003eEnglish\u003c/span\u003e |  \n    \u003ca  href=\"https://www.donet5.com/Home/Doc\"\u003e\u003cfont color=\"red\"\u003e中文\u003c/font\u003e\u003c/a\u003e\n\u003c/p\u003e\n \n## SqlSugar ORM\nSqlSugar 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\n\nAdvantages: [Low code] [High performance] [Super simple] [Comprehensive features] [ Multi-database compatible] [Suitable products]\n\n## Support .NET\n.net framework.net core3.1.ne5.net6.net7.net8 .net9 .net10\n\n## Support database \nMySql、SqlServer、Sqlite、Oracle 、 postgresql、达梦、\n人大金仓(国产推荐)、神通数据库、瀚高、Access 、OceanBase\nTDengine  QuestDb Clickhouse  MySqlConnector、华为 GaussDB \n南大通用 GBase、MariaDB、Tidb、Odbc、Percona Server,\nAmazon Aurora、Azure Database for MySQL、\n Google Cloud SQL for MySQL、custom database\n\n## Description\n1. Truly achieve zero SQL ORM table building, index and CRUD all support\n2. Support.NET millions of big data write, update, subtable and has billions of query statistics mature solutions\n3. Support SAAS complete application: cross-database query, audit, tenant sub-database, tenant sub-table and tenant data isolation\n4. Support low code + workflow (dynamic class building, dynamic table building, non-entity multi-library compatible with CRUD, JSON TO SQL, custom XML, etc.)\n5. Support ValueObject, discriminator, repository, UnitOfWork, DbContext, AOP\n\n##  Documentation\n|Other |Select  | Insert    | Update  | Delete| \n| ----- | --------- | ----------- | ------- |------- |\n \u003ca target=\"_blank\" href=\"https://github.com/donet5/SqlSugar/wiki/NUGET\"\u003eNuget\u003c/a\u003e| \u003ca href=\"https://github.com/DotNetNext/SqlSugar/wiki/1.1--Query‐Simple\"\u003eQuery\u003c/a\u003e | \u003ca  target=\"_blank\" href=\"https://github.com/DotNetNext/SqlSugar/wiki/3.Insert\"\u003e Insert \u003c/a\u003e |\u003ca  target=\"_blank\" href=\"https://github.com/DotNetNext/SqlSugar/wiki/2.Update\"\u003eUpdate\u003c/a\u003e|    \u003ca  target=\"_blank\" href=\"https://github.com/DotNetNext/SqlSugar/wiki/4.1-Delete\"\u003eDelete\u003c/a\u003e    | \n\u003ca target=\"_blank\" href=\"https://github.com/donet5/SqlSugar/wiki\"\u003e Start guide\u003c/a\u003e  | \u003ca target=\"_bank\" href=\"https://github.com/DotNetNext/SqlSugar/wiki/1.2-Query%E2%80%90Join\"\u003eJoin query \u003c/a\u003e |\u003ca href=\"https://github.com/DotNetNext/SqlSugar/wiki/3.2-Dynamic-Insert\"\u003eInsert without entity \u003c/a\u003e | \u003ca href=\"https://github.com/DotNetNext/SqlSugar/wiki/2.2-Dynamic-Update\"\u003eUpdate without entity\u003c/a\u003e  | \u003ca href=\"https://github.com/DotNetNext/SqlSugar/wiki/4.2-Dynamic-Delete\"\u003e  Delete without entity \u003c/a\u003e   |     |\n|\u003ca href=\"https://www.donet5.com/Home/Doc?typeId=2246\"\u003eMultiple databases\u003c/a\u003e | \u003ca target=\"_bank\" href=\"https://github.com/DotNetNext/SqlSugar/wiki/1.6-Query%E2%80%90Include\"\u003eInclude query\u003c/a\u003e|\u003ca target=\"_bank\" href=\"https://www.donet5.com/Home/Doc?typeId=2430\"\u003eInclude Insert\u003c/a\u003e| \u003ca target=\"_bank\" href=\"https://www.donet5.com/Home/Doc?typeId=2432\"\u003eInclude Update\u003c/a\u003e| \u003ca target=\"_bank\" href=\"https://www.donet5.com/Home/Doc?typeId=2431\"\u003eInclude Delete\u003c/a\u003e \n |\u003ca  href=\"https://www.donet5.com/Home/Doc\"\u003e\u003cfont color=\"red\"\u003e中文文档\u003c/font\u003e\u003c/a\u003e|\u003ca  href=\"https://www.donet5.com/Home/Doc?typeId=2244\"\u003eCross database query\u003c/a\u003e|\u003ca  href=\"https://www.donet5.com/Home/Doc?typeId=2420\"\u003eInsert by json\u003c/a\u003e|\u003ca  href=\"https://www.donet5.com/Home/Doc?typeId=2420\"\u003eUpdate by json\u003c/a\u003e|\u003ca  href=\"https://www.donet5.com/Home/Doc?typeId=2420\"\u003eDelete by json\u003c/a\u003e|\n\n##  Feature characteristic\n\n###  Feature1 : Join query  \nSuper simple query syntax\n```cs\nvar query  = db.Queryable\u003cOrder\u003e()\n            .LeftJoin\u003cCustom\u003e  ((o, cus) =\u003e o.CustomId == cus.Id)\n            .LeftJoin\u003cOrderItem\u003e ((o, cus, oritem ) =\u003e o.Id == oritem.OrderId)\n            .LeftJoin\u003cOrderItem\u003e ((o, cus, oritem , oritem2) =\u003e o.Id == oritem2.OrderId)\n            .Where(o =\u003e o.Id == 1)  \n            .Select((o, cus) =\u003e new ViewOrder { Id = o.Id, CustomName = cus.Name })\n            .ToList();   \n```\n```sql\nSELECT\n  [o].[Id] AS [Id],\n  [cus].[Name] AS [CustomName]\nFROM\n  [Order] o\n  Left JOIN [Custom] cus ON ([o].[CustomId] = [cus].[Id])\n  Left JOIN [OrderDetail] oritem ON ([o].[Id] = [oritem].[OrderId])\n  Left JOIN [OrderDetail] oritem2 ON ([o].[Id] = [oritem2].[OrderId])\nWHERE\n  ([o].[Id] = @Id0)\n``` \n###   Feature2 :Include Query、Insert、Delete and Update\n```cs\n\n//Includes\nvar list=db.Queryable\u003cTest\u003e()\n           .Includes(x =\u003e x.Provinces,x=\u003ex.Citys ,x=\u003ex.Street) //multi-level\n           .Includes(x =\u003e x.ClassInfo) \n           .ToList();\n\n//Includes+left join        \nvar list5= db.Queryable\u003cStudent_004\u003e()\n           .Includes(x =\u003e x.school_001, x =\u003e x.rooms)\n           .Includes(x =\u003e x.books)\n           .LeftJoin\u003cOrder\u003e((x, y) =\u003e x.Id==y.sid)\n           .Select((x,y) =\u003e new Student_004DTO\n           {\n               SchoolId = x.SchoolId,\n               books = x.books,\n               school_001 = x.school_001,\n               Name=y.Name\n           })\n           .ToList();          \n```\n\n###   Feature3 : Page query\n```cs\n\n int pageIndex = 1; \n int pageSize = 20;\n int totalCount=0;\n var page = db.Queryable\u003cStudent\u003e().ToPageList(pageIndex, pageSize, ref totalCount);\n```\n \n###    Feature4 : Dynamic expression\n```cs\nvar names= new string [] { \"a\",\"b\"};\nExpressionable\u003cOrder\u003e exp = new Expressionable\u003cOrder\u003e();\nforeach (var item in names)\n{\n    exp.Or(it =\u003e it.Name.Contains(item.ToString()));\n}\nvar list= db.Queryable\u003cOrder\u003e().Where(exp.ToExpression()).ToList();\n ```\n ```sql\nSELECT [Id],[Name],[Price],[CreateTime],[CustomId]\n        FROM [Order]  WHERE (\n                      ([Name] like '%'+ CAST(@MethodConst0 AS NVARCHAR(MAX))+'%') OR \n                      ([Name] like '%'+ CAST(@MethodConst1 AS NVARCHAR(MAX))+'%')\n                     )\n```\n###   Feature5 : Multi-tenant transaction\n```cs\n//Creaate  database object\nSqlSugarClient db = new SqlSugarClient(new List\u003cConnectionConfig\u003e()\n{\n    new ConnectionConfig(){ ConfigId=\"0\", DbType=DbType.SqlServer,  ConnectionString=Config.ConnectionString, IsAutoCloseConnection=true },\n    new ConnectionConfig(){ ConfigId=\"1\", DbType=DbType.MySql, ConnectionString=Config.ConnectionString4 ,IsAutoCloseConnection=true}\n});\n\n\nvar mysqldb = db.GetConnection(\"1\");//mysql db\nvar sqlServerdb = db.GetConnection(\"0\");// sqlserver db\n \ndb.BeginTran();\n            mysqldb.Insertable(new Order()\n            {\n                CreateTime = DateTime.Now,\n                CustomId = 1,\n                Name = \"a\",\n                Price = 1\n            }).ExecuteCommand();\n            mysqldb.Queryable\u003cOrder\u003e().ToList();\n            sqlServerdb.Queryable\u003cOrder\u003e().ToList();\n\ndb.CommitTran();\n```\n###  Feature6 : Singleton Pattern\nImplement transactions across methods\n```CS\npublic static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()\n {\n            DbType = SqlSugar.DbType.SqlServer,\n            ConnectionString = Config.ConnectionString,\n            IsAutoCloseConnection = true \n  },\n  db=\u003e {\n            db.Aop.OnLogExecuting = (s, p) =\u003e\n            {\n                Console.WriteLine(s);\n            };\n });\n \n \n  using (var tran = Db.UseTran())\n  {\n          \n              \n               new Test2().Insert(XX);\n               new Test1().Insert(XX);\n               ..... \n                ....\n                         \n             tran.CommitTran(); \n }\n```\n### Feature7 : Query filter\n```cs\n//set filter\ndb.QueryFilter.Add(new TableFilterItem\u003cOrder\u003e(it =\u003e it.Name.Contains(\"a\")));  \n \n   \ndb.Queryable\u003cOrder\u003e().ToList();\n//SELECT [Id],[Name],[Price],[CreateTime],[CustomId] FROM [Order]  WHERE  ([Name] like '%'+@MethodConst0+'%')  \n\ndb.Queryable\u003cOrderItem, Order\u003e((i, o) =\u003e i.OrderId == o.Id)\n        .Where(i =\u003e i.OrderId != 0)\n        .Select(\"i.*\").ToList();\n//SELECT i.* FROM [OrderDetail] i  ,[Order]  o  WHERE ( [i].[OrderId] = [o].[Id] )  AND \n//( [i].[OrderId] \u003c\u003e @OrderId0 )  AND  ([o].[Name] like '%'+@MethodConst1+'%')\n \n```\n\n### Feature8 : Insert or update \ninsert or update \n```cs\nDb.Storageable(list2).ExecuteCommand();\nDb.Storageable(list2).PageSize(1000).ExecuteCommand();\nDb.Storageable(list2).PageSize(1000,exrows=\u003e {   }).ExecuteCommand();\n```\n \n### Feature9 : Auto split table\nSplit entity \n```cs\n[SplitTable(SplitType.Year)]//Table by year (the table supports year, quarter, month, week and day)\n[SugarTable(\"SplitTestTable_{year}{month}{day}\")] \n public class SplitTestTable\n {\n     [SugarColumn(IsPrimaryKey =true)]\n     public long Id { get; set; }\n \n     public string Name { get; set; }\n     \n     //When the sub-table field is inserted, which table will be inserted according to this field. \n     //When it is updated and deleted, it can also be convenient to use this field to      \n     //find out the related table \n     [SplitField] \n     public DateTime CreateTime { get; set; }\n }\n ```\nSplit query\n```cs\n var lis2t = db.Queryable\u003cOrderSpliteTest\u003e()\n.SplitTable(DateTime.Now.Date.AddYears(-1), DateTime.Now)\n.ToPageList(1,2);　\n``` \n\n### Feature10 : Big data insert or update \n```cs\n10.1 BulkCopy\ndb.Fastest\u003cOrder\u003e().BulkCopy(lstData);//insert\ndb.Fastest\u003cOrder\u003e().PageSize(100000).BulkCopy(insertObjs);\ndb.Fastest\u003cSystem.Data.DataTable\u003e().AS(\"order\").BulkCopy(dataTable);\n \n10.2 BulkUpdate\ndb.Fastest\u003cOrder\u003e().BulkUpdate(GetList())//update \ndb.Fastest\u003cOrder\u003e().PageSize(100000).BulkUpdate(GetList()) \ndb.Fastest\u003cOrder\u003e().BulkUpdate(GetList(),new string[] { \"Id\"});//no primary key\ndb.Fastest\u003cOrder\u003e().BulkUpdate(GetList(), new string[]{\"id\"},\n                     new string[]{\"name\",\"time\"})//Set the updated column\n//DataTable                           \ndb.Fastest\u003cSystem.Data.DataTable\u003e().AS(\"Order\").BulkUpdate(dataTable,\"Id\");//Id is primary key\ndb.Fastest\u003cSystem.Data.DataTable\u003e().AS(\"Order\").BulkUpdate(dataTable,\"Id\",Set the updated column);\n                          \n\n10.3 BulkMerge （5.1.4.109）\ndb.Fastest\u003cOrder\u003e().BulkMerge(List);\ndb.Fastest\u003cOrder\u003e().PageSize(100000).BulkMerge(List);\n \n\n10.4 BulkQuery\ndb.Queryable\u003cOrder\u003e().ToList();//Slightly faster than Dapper\n//Suitable for big data export\nList\u003cOrder\u003e order = new List\u003cOrder\u003e(); \ndb.Queryable\u003cOrder\u003e().ForEach(it=\u003e { order.Add(it); } ,2000);\n\n10.5 BulkDelete\ndb.Deleteable\u003cOrder\u003e(list).PageSize(1000).ExecuteCommand();\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnetnext%2Fsqlsugar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotnetnext%2Fsqlsugar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnetnext%2Fsqlsugar/lists"}