Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

.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# ORM , C# ORM .NET ORM NET9 ORM .NET8 ORM ClickHouse ORM QuestDb ,TDengine ORM,OceanBase ORM,GaussDB ORM,Tidb ORM Object/Relational Mapping

License

NotificationsYou must be signed in to change notification settings

DotNetNext/SqlSugar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13,337 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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、OceanBaseTDengine 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

OtherSelectInsertUpdateDelete
NugetQuery InsertUpdateDelete
Start guideJoin queryInsert without entityUpdate without entity Delete without entity
Multiple databasesInclude queryInclude InsertInclude UpdateInclude Delete
中文文档Cross database queryInsert by jsonUpdate by jsonDelete by json

Feature characteristic

Feature1 : Join query

Super simple query syntax

varquery=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)=>newViewOrder{Id=o.Id,CustomName=cus.Name}).ToList();
SELECT  [o].[Id]AS [Id],  [cus].[Name]AS [CustomName]FROM  [Order] oLeft JOIN [Custom] cusON ([o].[CustomId]= [cus].[Id])Left JOIN [OrderDetail] oritemON ([o].[Id]= [oritem].[OrderId])Left JOIN [OrderDetail] oritem2ON ([o].[Id]= [oritem2].[OrderId])WHERE  ([o].[Id]= @Id0)

Feature2 :Include Query、Insert、Delete and Update

//Includesvarlist=db.Queryable<Test>().Includes(x=>x.Provinces,x=>x.Citys,x=>x.Street)//multi-level.Includes(x=>x.ClassInfo).ToList();//Includes+left joinvarlist5=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)=>newStudent_004DTO{SchoolId=x.SchoolId,books=x.books,school_001=x.school_001,Name=y.Name}).ToList();

Feature3 : Page query

intpageIndex=1;intpageSize=20;inttotalCount=0;varpage=db.Queryable<Student>().ToPageList(pageIndex,pageSize,reftotalCount);

Feature4 : Dynamic expression

varnames=newstring[]{"a","b"};Expressionable<Order>exp=newExpressionable<Order>();foreach(variteminnames){exp.Or(it=>it.Name.Contains(item.ToString()));}varlist=db.Queryable<Order>().Where(exp.ToExpression()).ToList();
SELECT [Id],[Name],[Price],[CreateTime],[CustomId]FROM [Order]WHERE (                     ([Name]like'%'+ CAST(@MethodConst0AS NVARCHAR(MAX))+'%')OR                      ([Name]like'%'+ CAST(@MethodConst1AS NVARCHAR(MAX))+'%')                    )

Feature5 : Multi-tenant transaction

//Creaate  database objectSqlSugarClientdb=newSqlSugarClient(newList<ConnectionConfig>(){newConnectionConfig(){ConfigId="0",DbType=DbType.SqlServer,ConnectionString=Config.ConnectionString,IsAutoCloseConnection=true},newConnectionConfig(){ConfigId="1",DbType=DbType.MySql,ConnectionString=Config.ConnectionString4,IsAutoCloseConnection=true}});varmysqldb=db.GetConnection("1");//mysql dbvarsqlServerdb=db.GetConnection("0");// sqlserver dbdb.BeginTran();mysqldb.Insertable(newOrder(){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

publicstaticSqlSugarScopeDb=newSqlSugarScope(newConnectionConfig(){DbType=SqlSugar.DbType.SqlServer,ConnectionString=Config.ConnectionString,IsAutoCloseConnection=true},  db=>{db.Aop.OnLogExecuting=(s,p)=>{Console.WriteLine(s);};});using(vartran=Db.UseTran()){newTest2().Insert(XX);newTest1().Insert(XX);               .....                 ....tran.CommitTran();}

Feature7 : Query filter

//set filterdb.QueryFilter.Add(newTableFilterItem<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}")]publicclassSplitTestTable{[SugarColumn(IsPrimaryKey=true)]publiclongId{get;set;}publicstringName{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]publicDateTimeCreateTime{get;set;}}

Split query

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

Feature10 : Big data insert or update

10.1 BulkCopydb.Fastest<Order>().BulkCopy(lstData);//insertdb.Fastest<Order>().PageSize(100000).BulkCopy(insertObjs);db.Fastest<System.Data.DataTable>().AS("order").BulkCopy(dataTable);10.2 BulkUpdatedb.Fastest<Order>().BulkUpdate(GetList())//updatedb.Fastest<Order>().PageSize(100000).BulkUpdate(GetList()) db.Fastest<Order>().BulkUpdate(GetList(),newstring[]{"Id"});//no primary keydb.Fastest<Order>().BulkUpdate(GetList(),newstring[]{"id"},newstring[]{"name","time"})//Set the updated column//DataTabledb.Fastest<System.Data.DataTable>().AS("Order").BulkUpdate(dataTable,"Id");//Id is primary keydb.Fastest<System.Data.DataTable>().AS("Order").BulkUpdate(dataTable,"Id",Setthe updated column);10.3 BulkMerge (5.1.4.109)db.Fastest<Order>().BulkMerge(List);db.Fastest<Order>().PageSize(100000).BulkMerge(List);10.4 BulkQuerydb.Queryable<Order>().ToList();//Slightly faster than Dapper//Suitable for big data exportList<Order>order=newList<Order>();db.Queryable<Order>().ForEach(it=>{order.Add(it);},2000);10.5 BulkDeletedb.Deleteable<Order>(list).PageSize(1000).ExecuteCommand();

About

.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# ORM , C# ORM .NET ORM NET9 ORM .NET8 ORM ClickHouse ORM QuestDb ,TDengine ORM,OceanBase ORM,GaussDB ORM,Tidb ORM Object/Relational Mapping

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors70

Languages


[8]ページ先頭

©2009-2026 Movatter.jp