• Stars
    star
    5,250
  • Rank 7,880 (Top 0.2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

.Net aot ORM Fastest ORM 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

English | 中文

SqlSugar ORM

SqlSugar ORM is a library providing Object/Relational Mapping (ORM)

An ORM framework from the future

Using SqlSugar is very simple , And it's powerful.

Description

  • Support Cross database query
  • Support SqlServer、MySql、PgSql and Oracle insert bulkcopy
  • Split table big data self-processing
  • Support Multi-tenant, multi-library transactions
  • Support CodeFirst data migration.
  • Support Join query 、 Union all 、 Subquery
  • Support Configure the query
  • Support DbFirst import entity class from database, or use Generation Tool.
  • Support one-to-many and many-to-many navigation properties
  • Support MySql、SqlServer、Sqlite、Oracle 、 postgresql 、QuestDb、ClickHouse、达梦、人大金仓 、神通数据库、瀚高、MsAccess、华为GaussDB、GBase 8s、Odbc、Custom
  • Support AOP 、 Diff Log 、 Query Filter

Documentation

Other Select Insert Update Delete
Nuget Query Insert Update Delete
Start guide Join query Insert without entity Update without entity Delete without entity
Multiple databases Include query Include Insert Include Update Include Delete
中文文档 Cross database query Insert by json Update by json Delete by json

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

//query  by nav
var list=db.Queryable<Test>()
           .Includes(x => x.Provinces,x=>x.Citys ,x=>x.Street) //multi-level
           .Includes(x => x.ClassInfo) 
           .ToList();
           
//insert by nav
 db.InsertNav(list) //Finer operation than EFCore's SaveChange
            .Include(z1 => z1.SchoolA).ThenInclude(z1 => z1.RoomList)//multi-level
            .Include(z1 => z1.Books) 
            .ExecuteCommand(); 
            
//delete by nav               
 db.DeleteNav<Student>(it=>it.Id==1) 
            .Include(z1 => z1.SchoolA) .ThenInclude(z1 => z1.RoomList)//multi-level
            .Include(z1 => z1.Books) 
            .ExecuteCommand();  
            
//update by nav     
 db.UpdateNav(list)
            .Include(z1 => z1.SchoolA) .ThenInclude(z1 => z1.RoomList)//multi-level
            .Include(z1 => z1.Books) 
            .ExecuteCommand();           

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

    var x = Db.Storageable(list2).ToStorage();  
    x.AsInsertable.ExecuteCommand();  
    x.AsUpdateable.ExecuteCommand();  

insert into not exists

var x = Db.Storageable(list).SplitInsert(it => !it.Any()).ToStorage()
x.AsInsertable.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

//Insert A million only takes a few seconds
db.Fastest<RealmAuctionDatum>().BulkCopy(GetList());
 
 
//update A million only takes a few seconds
db.Fastest<RealmAuctionDatum>().BulkUpdate(GetList());//A million only takes a few seconds完
db.Fastest<RealmAuctionDatum>().BulkUpdate(GetList(),new string[]{"id"},new string[]{"name","time"})//no primary key
 
//if exists update, else  insert
 var x= db.Storageable<Order>(data).ToStorage();
     x.BulkCopy();
     x.BulkUpdate(); 
     
//set table name
db.Fastest<RealmAuctionDatum>().AS("tableName").BulkCopy(GetList())
 
//set page 
db.Fastest<Order>().PageSize(300000).BulkCopy(insertObjs);

More Repositories

1

WebFirst

.NET CORE 代码生成器 ,Web中使用CodeFirst模式, 实体 生成器,UI代码 生成器,在线建表,PostgresSql生成器,达梦生成器,金仓生成器MySql生成器,SQLServere生成器、Oracle生成器、Sqlite生成器、导出文档,模版配置, WEB代码生成器 ,API代码生成器
C#
729
star
2

SugarSite

SugarSite 一个支持移动端的企业站,集成BBS 第三方登录等 bbs Bbs Bbs CMS
JavaScript
160
star
3

ReZero

🔥🔥🔥 rezero.api 全网唯一免费的在线运行时创建API接口的项目,并且生成接口文档,真正的运时行创建【 低代码 】【 运时建表 】【 运时创建接口 】【 热插拔 】【 超级API 】【 云ORM框架 】
C#
156
star
4

ASP_NET_CORE_ORM_SqlSugar

.NET Core SqlServer ORM Fastest ORM , Simple oRM, Easy ORm oRm Orm API: See README.md
C#
62
star
5

MySqlSugar

MySql ORM MySqlSugarORM is the fastest, Simple,Easy API: See README.md
C#
60
star
6

SqliteSugar

Sqlite ORM SqlSugarORM is the fastest, Simple,Easy API: See README.md
C#
50
star
7

-common-jquery-ejq.js

HTML
30
star
8

ASP_NET_CORE_ORM_MySqlSugar

C#
28
star
9

OracleSugar

net 4.0+ Oracle ORM SqlSugarORM is the fastest, Simple,Easy API: See README.md
C#
25
star
10

SqlSugarRepository

C#
24
star
11

SqlSugar.IOC

.NET5 .NETCore3.1 IOC简化 封装类库
C#
20
star
12

SyntacticSugar

C#
19
star
13

SqlSugarSnippets

15
star
14

AopSugar

C#
11
star
15

ASPNETMVCCRUDDEMO

JavaScript
9
star
16

JQWidgetsSugar

jqweigets asp.net dll
CSS
7
star
17

AutoLayout

HTML
6
star
18

ASP_NET_CORE_ORM_SqliteSugar

C#
5
star
19

easyliter

A nice SQLite ORM framework
C#
3
star
20

ASP_NET_CORE_ORM_OracleSugar

2
star
21

EmitTest

1
star
22

themeone

HTML
1
star
23

NFD

HTML
1
star
24

AsCellSugar

C#
1
star