This commit is contained in:
guoshun.du 2024-05-09 13:58:49 +08:00
commit 1fcc1974b1
1617 changed files with 51226 additions and 3438 deletions
.gitattributes.gitignoreREADME.md
Src/Asp.Net
AccessTest/Demo
CustomDbTest
DmTest
Json2SqlTest
MySqlConnectorTest/Demo
MySqlTest

2
.gitattributes vendored
View File

@ -61,4 +61,4 @@
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

1
.gitignore vendored
View File

@ -210,3 +210,4 @@ _Pvt_Extensions/
ModelManifest.xml
Src/Asp.NetCore2/SqlSeverTest/.idea/
.idea

125
README.md
View File

@ -5,39 +5,27 @@
</p>
## SqlSugar ORM
SqlSugar ORM is a library providing Object/Relational Mapping (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
An ORM framework from the future
Advantages: [Low code] [High performance] [Super simple] [Comprehensive features] [ Multi-database compatible] [Suitable products]
Using SqlSugar is very simple , And it's powerful.
## Support .NET
.net framework.net core3.1.ne5.net6.net7.net8 .net9 .net10
## Support database
MySql、SqlServer、Sqlite、Oracle 、 postgresql、达梦、
人大金仓(国产推荐)、神通数据库、瀚高、Access 、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
- 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
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
|Other |Select | Insert | Update | Delete|
@ -73,30 +61,27 @@ WHERE
([o].[Id] = @Id0)
```
### Feature2 :Include Query、Insert、Delete and Update
```cs
//query by nav
```cs
//Includes
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();
//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
@ -200,17 +185,12 @@ db.Queryable<OrderItem, Order>((i, o) => i.OrderId == o.Id)
### Feature8 : Insert or update
insert or update
```cs
var x = Db.Storageable(list2).ToStorage();
x.AsInsertable.ExecuteCommand();
x.AsUpdateable.ExecuteCommand();
```
insert into not exists
```cs
var x = Db.Storageable(list).SplitInsert(it => !it.Any()).ToStorage()
x.AsInsertable.ExecuteCommand();
Db.Storageable(list2).ExecuteCommand();
Db.Storageable(list2).PageSize(1000).ExecuteCommand();
Db.Storageable(list2).PageSize(1000,exrows=> { }).ExecuteCommand();
```
### Feature9 Auto split table
### Feature9 : Auto split table
Split entity
```cs
[SplitTable(SplitType.Year)]//Table by year (the table supports year, quarter, month, week and day)
@ -236,25 +216,36 @@ Split query
.ToPageList(1,2); 
```
### Feature10 Big data insert or update
### Feature10 : Big data insert or update
```cs
//Insert A million only takes a few seconds
db.Fastest<RealmAuctionDatum>().BulkCopy(GetList());
10.1 BulkCopy
db.Fastest<Order>().BulkCopy(lstData);//insert
db.Fastest<Order>().PageSize(100000).BulkCopy(insertObjs);
db.Fastest<System.Data.DataTable>().AS("order").BulkCopy(dataTable);
10.2 BulkUpdate
db.Fastest<Order>().BulkUpdate(GetList())//update
db.Fastest<Order>().PageSize(100000).BulkUpdate(GetList())
db.Fastest<Order>().BulkUpdate(GetList(),new string[] { "Id"});//no primary key
db.Fastest<Order>().BulkUpdate(GetList(), new string[]{"id"},
new string[]{"name","time"})//Set the updated column
//DataTable
db.Fastest<System.Data.DataTable>().AS("Order").BulkUpdate(dataTable,"Id");//Id is primary key
db.Fastest<System.Data.DataTable>().AS("Order").BulkUpdate(dataTable,"Id",Set the updated column);
10.3 BulkMerge 5.1.4.109
db.Fastest<Order>().BulkMerge(List);
db.Fastest<Order>().PageSize(100000).BulkMerge(List);
//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);
10.4 BulkQuery
db.Queryable<Order>().ToList();//Slightly faster than Dapper
//Suitable for big data export
List<Order> order = new List<Order>();
db.Queryable<Order>().ForEach(it=> { order.Add(it); } ,2000);
10.5 BulkDelete
db.Deleteable<Order>(list).PageSize(1000).ExecuteCommand();
```

View File

@ -40,8 +40,14 @@ namespace OrmTest
var updateRow2 = x2.AsUpdateable.ExecuteCommand();
x2.AsInsertable.ExecuteCommand();
var orders = new List<Order>()
{
new Order() { Id = 0, Name = "jack" },
new Order() { Id = 0, Name = "jack" }
};
var x3 = db.Storageable(orders).ExecuteCommand();
// db.Saveable(new Order() { Id = 159, Name = "jack" }).ExecuteCommand();
// db.Saveable(new Order() { Id = 159, Name = "jack" }).ExecuteCommand();
Console.WriteLine("");
Console.WriteLine("#### Saveable End ####");
}

View File

@ -24,7 +24,7 @@ namespace OrmTest
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
public static string ConnectionString = "Provider=Microsoft.ACE.OleDB.15.0;Data Source="+GetCurrentProjectPath+"\\test.accdb";
public static string ConnectionString = "Provider=Microsoft.ACE.OleDB.16.0;Data Source="+GetCurrentProjectPath+"\\test.accdb";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号

View File

@ -1,5 +1,6 @@
using SqlSugar;
using System;
using System.Reflection;
namespace OrmTest
{
@ -15,6 +16,8 @@ namespace OrmTest
//Set Custom Db
InstanceFactory.CustomDbName = "Access";
InstanceFactory.CustomDllName = "SqlSugar.Access";
InstanceFactory.CustomAssemblies =
new Assembly[] { typeof(SqlSugar.Access.AccessProvider).Assembly };
InstanceFactory.CustomNamespace = "SqlSugar.Access";
Demo0_SqlSugarClient.Init();

View File

@ -87,6 +87,7 @@
<Compile Include="UnitTest\UCodeFirst.cs" />
<Compile Include="UnitTest\UInsert3.cs" />
<Compile Include="UnitTest\UJson.cs" />
<Compile Include="UnitTest\UnitBulkCopy.cs" />
<Compile Include="UnitTest\Updateable.cs" />
<Compile Include="UnitTest\UQueryable.cs" />
<Compile Include="UnitTest\UQueryableAsync.cs" />

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OrmTest
{
internal class UnitBulkCopy
{
public static void Init()
{
var db = NewUnitTest.Db;
db.CodeFirst.InitTables<Unitadfa>();
db.Insertable(new Unitadfa()
{
Name = "A",
Date = DateTime.Now,
}).ExecuteCommand();
db.Insertable(new List<Unitadfa>() {
new Unitadfa()
{
Name = "A",
Date = DateTime.Now,
},
new Unitadfa()
{
Name = "A",
Date = DateTime.Now,
}}).ExecuteCommand();
var list = db.Queryable<Unitadfa>().ToList();
db.DbMaintenance.TruncateTable<Unitadfa>();
db.Fastest<Unitadfa>().OffIdentity().BulkCopy(list);
db.Insertable(new Unitadfa()
{
Name = "A",
Date = DateTime.Now,
}).ExecuteCommand();
db.DbMaintenance.DropTable<Unitadfa>();
}
}
public class Unitadfa
{
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
[SqlSugar.SugarColumn(ColumnDataType = "Date")]
public DateTime Date { get; set; }
}
}

View File

@ -9,18 +9,18 @@ namespace Test
static void Main(string[] args)
{
JsonClient jsonToSqlClient = new JsonClient();
//jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
//{
// DbType = DbType.SqlServer,
// IsAutoCloseConnection = true,
// ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST"
//});
jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.MySql,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql"
}); ;
ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST"
});
//jsonToSqlClient.Context = new SqlSugarClient(new ConnectionConfig()
//{
// DbType = DbType.MySql,
// IsAutoCloseConnection = true,
// ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql"
//}); ;
TestHelper.InitDatabase(jsonToSqlClient);
jsonToSqlClient.Context.Aop.OnLogExecuted = (sql, p) =>

View File

@ -54,10 +54,17 @@ namespace Test
]
}
";
var x2 = jsonToSqlClient.Queryable(json2).ToSqlList();
var x2 = jsonToSqlClient.Queryable(json2).ToSqlList();
var json3 = @"{
""Table"":""order"",
""Where"":[ ""name"",""="", ""{string}:U"" ],
""Select"":[ ""{string}:abc"",""name"" ]
}";
var x3=jsonToSqlClient.Queryable(json3).ToSqlList();
var list1 = jsonToSqlClient.Context.Ado.SqlQuery<dynamic>(x1[0].Sql, x1[0].Parameters);
var list2 = jsonToSqlClient.Context.Ado.SqlQuery<dynamic>(x2[0].Sql, x2[0].Parameters);
var list3 = jsonToSqlClient.Context.Ado.SqlQuery<dynamic>(x3[0].Sql, x3[0].Parameters);
}
private static void JoinTest(JsonClient jsonToSqlClient)
{

View File

@ -29,9 +29,9 @@ namespace OrmTest
db.CodeFirst.SplitTables().InitTables<OrderSpliteTest>();
Console.WriteLine();
var id = Guid.NewGuid();
//根据最近3个表进行查询
var list=db.Queryable<OrderSpliteTest>().Where(it=>it.Pk==Guid.NewGuid())
var list=db.Queryable<OrderSpliteTest>().Where(it=>it.Pk== id)
.SplitTable(tabs => tabs.Take(3))
.Where(it=>it.Time==DateTime.Now).ToOffsetPage(1,2);
@ -43,7 +43,7 @@ namespace OrmTest
Console.WriteLine();
//删除数据只在最近3张表执行操作
var x = db.Deleteable<OrderSpliteTest>().Where(it=>it.Pk==Guid.NewGuid()).SplitTable(tabs => tabs.Take(3)).ExecuteCommand();
var x = db.Deleteable<OrderSpliteTest>().Where(it=>it.Pk== id).SplitTable(tabs => tabs.Take(3)).ExecuteCommand();
Console.WriteLine();

View File

@ -0,0 +1,138 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
/// <summary>
/// Class for demonstrating CodeFirst initialization operations
/// 用于展示 CodeFirst 初始化操作的类
/// </summary>
public class _1_CodeFirst
{
public static void Init()
{
// Get a new database instance
// 获取新的数据库实例
var db = DbHelper.GetNewDb();
// Create the database if it doesn't exist
// 如果数据库不存在,则创建数据库
db.DbMaintenance.CreateDatabase();
//support bulkcopy
//支持大数据操作
db.Ado.ExecuteCommand("SET GLOBAL local_infile=1");
// Initialize tables based on UserInfo001 entity class
// 根据 UserInfo001 实体类初始化表
db.CodeFirst.InitTables<UserInfo001>();
//Table structure and class are different
//表结构和类存在差异 初始化表
db.CodeFirst.InitTables<UserInfo002>();
//Insert
//插入
var id=db.Insertable(new UserInfo001()
{
Context = "Context",
Email="dfafa@qq.com",
Price=Convert.ToDecimal(1.1),
UserName="admin",
RegistrationDate=DateTime.Now,
}).ExecuteReturnIdentity();
//Query
//查询
var userInfo=db.Queryable<UserInfo001>().InSingle(id);
//Update
//更新
db.Updateable(userInfo).ExecuteCommand();
//Delete
//删除
db.Deleteable(userInfo).ExecuteCommand();
}
/// <summary>
/// User information entity class
/// 用户信息实体类
/// </summary>
public class UserInfo001
{
/// <summary>
/// User ID (Primary Key)
/// 用户ID主键
/// </summary>
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int UserId { get; set; }
/// <summary>
/// User name
/// 用户名
/// </summary>
[SugarColumn(Length = 50, IsNullable = false)]
public string UserName { get; set; }
/// <summary>
/// User email
/// 用户邮箱
/// </summary>
[SugarColumn(IsNullable = true)]
public string Email { get; set; }
/// <summary>
/// Product price
/// 产品价格
/// </summary>
public decimal Price { get; set; }
/// <summary>
/// User context
/// 用户内容
/// </summary>
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
public string Context { get; set; }
/// <summary>
/// User registration date
/// 用户注册日期
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? RegistrationDate { get; set; }
}
/// <summary>
/// User information entity class
/// 用户信息实体类
/// </summary>
[SugarTable("UserInfoAAA01")]
public class UserInfo002
{
/// <summary>
/// User ID (Primary Key)
/// 用户ID主键
/// </summary>
[SugarColumn(IsIdentity = true,ColumnName ="Id", IsPrimaryKey = true)]
public int UserId { get; set; }
/// <summary>
/// User name
/// 用户名
/// </summary>
[SugarColumn(Length = 50,ColumnName ="Name", IsNullable = false)]
public string UserName { get; set; }
}
}
}

View File

@ -0,0 +1,136 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class _2_DbFirst
{
/// <summary>
/// 初始化方法包含各种DbFirst操作的演示
/// Initialization method containing demonstrations of various DbFirst operations
/// </summary>
public static void Init()
{
var db = DbHelper.GetNewDb();
// 生成干净的实体类文件
// Generate clean entity class files
Demo1(db);
// 生成带有SqlSugar特性的实体类文件
// Generate entity class files with SqlSugar attributes
Demo2(db);
// 支持字符串类型的Nullable特性
// Support String Nullable attribute
Demo3(db);
// 格式化类名、属性名和文件名
// Format class names, property names, and file names
Demo4(db);
// 条件过滤生成实体类文件
// Generate entity class files with condition filtering
Demo5(db);
// 修改模版生成实体类文件禁用IsCreateAttribute避免冲突
// Generate entity class files with modified templates (disable IsCreateAttribute to avoid conflicts)
Demo6(db);
}
/// <summary>
/// 生成干净的实体类文件
/// Generate clean entity class files
/// </summary>
private static void Demo1(SqlSugarClient db)
{
db.DbFirst.CreateClassFile("c:\\Demo\\1", "Models");
}
/// <summary>
/// 生成带有SqlSugar特性的实体类文件
/// Generate entity class files with SqlSugar attributes
/// </summary>
private static void Demo2(SqlSugarClient db)
{
db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\2", "Models");
}
/// <summary>
/// 支持字符串类型的Nullable特性
/// Support String Nullable attribute
/// </summary>
private static void Demo3(SqlSugarClient db)
{
db.DbFirst.IsCreateAttribute().StringNullable().CreateClassFile("c:\\Demo\\3", "Models");
}
/// <summary>
/// 格式化类名、属性名和文件名
/// Format class names, property names, and file names
/// </summary>
private static void Demo4(SqlSugarClient db)
{
db.DbFirst
.IsCreateAttribute()
.FormatFileName(it => "File_" + it)
.FormatClassName(it => "Class_" + it)
.FormatPropertyName(it => "Property_" + it)
.CreateClassFile("c:\\Demo\\4", "Models");
}
/// <summary>
/// 条件过滤生成实体类文件
/// Generate entity class files with condition filtering
/// </summary>
private static void Demo5(SqlSugarClient db)
{
db.DbFirst.IsCreateAttribute().Where(it => it.ToLower() == "userinfo001").CreateClassFile("c:\\Demo\\5", "Models");
}
/// <summary>
/// 修改模版生成实体类文件禁用IsCreateAttribute避免冲突
/// Generate entity class files with modified templates (disable IsCreateAttribute to avoid conflicts)
/// </summary>
private static void Demo6(SqlSugarClient db)
{
db.DbFirst
// 类
.SettingClassTemplate(old => { return old;/* 修改old值替换 */ })
// 类构造函数
.SettingConstructorTemplate(old => { return old;/* 修改old值替换 */ })
.SettingNamespaceTemplate(old =>
{
return old + "\r\nusing SqlSugar;"; // 追加引用SqlSugar
})
// 属性备注
.SettingPropertyDescriptionTemplate(old => { return old;/* 修改old值替换 */})
// 属性:新重载 完全自定义用配置
.SettingPropertyTemplate((columns, temp, type) =>
{
var columnattribute = "\r\n [SugarColumn({0})]";
List<string> attributes = new List<string>();
if (columns.IsPrimarykey)
attributes.Add("IsPrimaryKey=true");
if (columns.IsIdentity)
attributes.Add("IsIdentity=true");
if (attributes.Count == 0)
{
columnattribute = "";
}
return temp.Replace("{PropertyType}", type)
.Replace("{PropertyName}", columns.DbColumnName)
.Replace("{SugarColumn}", string.Format(columnattribute, string.Join(",", attributes)));
})
.CreateClassFile("c:\\Demo\\6");
}
}
}

View File

@ -0,0 +1,191 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
internal class _3_EasyQuery
{
/// <summary>
/// 初始化方法,包含各种查询操作的演示
/// Initialization method containing demonstrations of various query operations
/// </summary>
public static void Init()
{
// 创建表并插入一条记录
// Create table and insert a record
CreateTable();
// 查询所有学生信息
// Query all student records
GetAllStudents();
// 查询学生总数
// Get the total count of students
GetStudentCount();
// 按条件查询学生信息
// Query student records based on conditions
GetStudentsByCondition();
// 模糊查询学生信息(名字包含"jack"的学生)
// Fuzzy search for student records (students with names containing "jack")
GetStudentsByName("jack");
// 根据学生ID查询单个学生
// Query a single student by student ID
GetStudentById(1);
// 获取Student03表中的最大Id
// Get the maximum ID from the Student03 table
GetMaxStudentId();
// 简单排序按照Id降序排序
// Simple sorting (sorting by Id in descending order)
GetStudentsOrderedByIdDesc();
// 查询学生姓名列表
// Query the list of student names
GetStudentNames();
}
/// <summary>
/// 创建表并插入一条记录
/// Create table and insert a record
/// </summary>
private static void CreateTable()
{
SqlSugarClient db = DbHelper.GetNewDb();
db.CodeFirst.InitTables<Student03>();
db.Insertable(new Student03() { Name = "name" + SnowFlakeSingle.Instance.NextId() })
.ExecuteCommand();
}
/// <summary>
/// 查询所有学生信息
/// Query all student records
/// </summary>
private static void GetAllStudents()
{
SqlSugarClient db = DbHelper.GetNewDb();
var students = db.Queryable<Student03>().ToList();
// 处理查询结果
// Process the query results
}
/// <summary>
/// 查询学生总数
/// Get the total count of students
/// </summary>
private static void GetStudentCount()
{
SqlSugarClient db = DbHelper.GetNewDb();
var count = db.Queryable<Student03>().Count();
// 处理查询结果
// Process the query results
}
/// <summary>
/// 按条件查询学生信息
/// Query student records based on conditions
/// </summary>
private static void GetStudentsByCondition()
{
SqlSugarClient db = DbHelper.GetNewDb();
// 查询name字段不为null的学生
// Query students where the 'name' field is not null
var studentsWithNameNotNull = db.Queryable<Student03>().Where(it => it.Name != null).ToList();
// 查询name字段为null的学生
// Query students where the 'name' field is null
var studentsWithNameNull = db.Queryable<Student03>().Where(it => it.Name == null).ToList();
// 查询name字段不为空的学生
// Query students where the 'name' field is not empty
var studentsWithNameNotEmpty = db.Queryable<Student03>().Where(it => it.Name != "").ToList();
// 多条件查询
// Query students with multiple conditions
var studentsWithMultipleConditions = db.Queryable<Student03>().Where(it => it.Id > 10 && it.Name == "a").ToList();
// 动态OR查询
// Dynamic OR query
var exp = Expressionable.Create<Student03>();
exp.OrIF(true, it => it.Id == 1);
exp.Or(it => it.Name.Contains("jack"));
var studentsWithDynamicOr = db.Queryable<Student03>().Where(exp.ToExpression()).ToList();
}
/// <summary>
/// 模糊查询学生信息
/// Fuzzy search for student records
/// </summary>
private static void GetStudentsByName(string keyword)
{
SqlSugarClient db = DbHelper.GetNewDb();
var students = db.Queryable<Student03>().Where(it => it.Name.Contains(keyword)).ToList();
// 处理查询结果
// Process the query results
}
/// <summary>
/// 根据学生ID查询单个学生
/// Query a single student by student ID
/// </summary>
private static void GetStudentById(int id)
{
SqlSugarClient db = DbHelper.GetNewDb();
var student = db.Queryable<Student03>().Single(it => it.Id == id);
// 处理查询结果
// Process the query results
}
/// <summary>
/// 获取Student03表中的最大Id
/// Get the maximum ID from the Student03 table
/// </summary>
private static void GetMaxStudentId()
{
SqlSugarClient db = DbHelper.GetNewDb();
var maxId = db.Queryable<Student03>().Max(it => it.Id);
// 处理查询结果
// Process the query results
}
/// <summary>
/// 简单排序按照Id降序排序
/// Simple sorting (sorting by Id in descending order)
/// </summary>
private static void GetStudentsOrderedByIdDesc()
{
SqlSugarClient db = DbHelper.GetNewDb();
var students = db.Queryable<Student03>().OrderBy(sc => sc.Id, OrderByType.Desc).ToList();
// 处理查询结果
// Process the query results
}
/// <summary>
/// 查询学生姓名列表
/// Query the list of student names
/// </summary>
private static void GetStudentNames()
{
SqlSugarClient db = DbHelper.GetNewDb();
var studentNames = db.Queryable<Student03>().Select(it => it.Name).ToList();
// 处理查询结果
// Process the query results
}
public class Student03
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
}
}
}

View File

@ -0,0 +1,171 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static OrmTest._4_JoinQuery;
namespace OrmTest
{
internal class _4_JoinQuery
{
public static void Init()
{
InitializeDatabase();
SyntaxSugar1();
SyntaxSugar2();
SyntaxSugar3();
}
/// <summary>
/// 使用语法糖1进行联表查询。
/// Performs a Join query using Syntax Sugar 1.
/// </summary>
/// <returns>查询结果列表。The list of query results.</returns>
public static List<ViewOrder2> SyntaxSugar1()
{
var db = DbHelper.GetNewDb();
var query = db.Queryable<Order>()
.LeftJoin<Custom>((o, cus) => o.CustomId == cus.Id)
.LeftJoin<OrderDetail>((o, cus, oritem) => o.Id == oritem.OrderId)
.Where(o => o.Id == 1)
.Select((o, cus, oritem) => new ViewOrder2 { Id = o.Id,Name=o.Name, CustomName = cus.Name })
.ToList();
return query;
}
/// <summary>
/// 使用语法糖2进行联表查询。
/// Performs a Join query using Syntax Sugar 2.
/// </summary>
/// <returns>查询结果列表。The list of query results.</returns>
public static List<Order> SyntaxSugar2()
{
var db = DbHelper.GetNewDb();
var rightQueryable = db.Queryable<Custom>()
.LeftJoin<OrderDetail>((o, i) => o.Id == i.Id)
.Select(o => o);
var list = db.Queryable<Order>()
.LeftJoin(rightQueryable, (c, j) => c.CustomId == j.Id)
.Select(c => c)
.ToList();
return list;
}
/// <summary>
/// 使用语法糖3进行联表查询。
/// Performs a Join query using Syntax Sugar 3.
/// </summary>
/// <returns>查询结果列表。The list of query results.</returns>
public static List<ViewOrder2> SyntaxSugar3()
{
var db = DbHelper.GetNewDb();
var list = db.Queryable<Order, OrderDetail, Custom>((o, i, c) => o.Id == i.OrderId && c.Id == o.CustomId)
.Select((o, i, c) => new ViewOrder2 { Id = o.Id, Name = o.Name, CustomName = c.Name })
.ToList();
return list;
}
static void InitializeDatabase()
{
// Initialize order data
// 初始化订单数据
var orders = new List<Order>
{
new Order { Id = 1, Name = "Order 1", CustomId = 1 },
new Order { Id = 2, Name = "Order 2", CustomId = 2 },
new Order { Id = 3, Name = "Order 3", CustomId = 1 },
};
// Initialize order details data
// 初始化订单详情数据
var orderDetails = new List<OrderDetail>
{
new OrderDetail { Id = 1, OrderId = 1 },
new OrderDetail { Id = 2, OrderId = 2 },
new OrderDetail { Id = 3, OrderId = 3 },
};
// Initialize customer data
// 初始化客户数据
var customers = new List<Custom>
{
new Custom { Id = 1, Name = "Customer 1" },
new Custom { Id = 2, Name = "Customer 2" },
new Custom { Id = 3, Name = "Customer 3" },
};
// Get database connection
// 获取数据库连接
var db = DbHelper.GetNewDb();
// Initialize database tables and truncate data
// 初始化数据库表并清空数据
db.CodeFirst.InitTables<Custom, OrderDetail, Order>();
db.DbMaintenance.TruncateTable<Custom, OrderDetail, Order>();
// Insert data into tables
// 向表中插入数据
db.Insertable(orders).ExecuteCommand();
db.Insertable(orderDetails).ExecuteCommand();
db.Insertable(customers).ExecuteCommand();
}
/// <summary>
/// 订单实体类。
/// Order entity class.
/// </summary>
[SqlSugar.SugarTable("Order04")]
public class Order
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public int CustomId { get; set; }
// 其他订单相关属性...
}
/// <summary>
/// 订单详情实体类。
/// Order detail entity class.
/// </summary>
[SqlSugar.SugarTable("OrderDetail04")]
public class OrderDetail
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public int OrderId { get; set; }
// 其他订单详情相关属性...
}
/// <summary>
/// 客户实体类。
/// Customer entity class.
/// </summary>
[SqlSugar.SugarTable("Custom04")]
public class Custom
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
// 其他客户相关属性...
}
/// <summary>
/// 类1实体类。
/// Class1 entity class.
/// </summary>
public class ViewOrder2
{
public int Id { get; set; }
public string Name { get; set; }
public string CustomName { get; set; }
// 其他类1相关属性...
}
}
}

View File

@ -0,0 +1,68 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class _4_Subquery
{
public static void Init()
{
var db = DbHelper.GetNewDb();
db.CodeFirst.InitTables<Student, School>();
db.DbMaintenance.TruncateTable<Student, School>();
db.Insertable(new Student() { Id = 1, SchoolId = 1 }).ExecuteCommand();
db.Insertable(new School() { Id = 1, Name = "Harvard School" }).ExecuteCommand();
db.Insertable(new Student() { Id = 2, SchoolId = 2 }).ExecuteCommand();
db.Insertable(new School() { Id = 2, Name = "haha School" }).ExecuteCommand();
//subquery select
var result = db.Queryable<Student>()
.Select(st => new
{
SchoolName = SqlFunc.Subqueryable<School>().Where(s => s.Id == st.SchoolId).Select(s => s.Name),
MaxSchoolId = SqlFunc.Subqueryable<School>().Where(s => s.Id == st.SchoolId).Select(s => SqlFunc.AggregateMax(s.Id)),
MaxSchoolId2 = SqlFunc.Subqueryable<School>().Where(s => s.Id == st.SchoolId).Max(s => s.Id),
})
.ToList();
//Exists:
//SELECT [Id],[SchoolId] FROM [Student0402] [it] WHERE (EXISTS ( SELECT * FROM [School0402] [s] WHERE ( [Id] = [it].[SchoolId] ) ))
var result2 = db.Queryable<Student>()
.Where(it => SqlFunc.Subqueryable<School>().Where(s => s.Id == it.SchoolId).Any())
.ToList();
//In:
//SELECT [Id],[SchoolId] FROM [Student0402] [it] WHERE [Id] in (SELECT [Id] FROM [School0402] [s] GROUP BY [Id])
var result3 = db.Queryable<Student>()
.Where(it => it.Id == SqlFunc.Subqueryable<School>().GroupBy(s => s.Id).Select(s => s.Id))
.ToList();
//Equal:
//SELECT [Id],[SchoolId] FROM [Student0402] [it] WHERE ( [Id] =(SELECT TOP 1 [s].[Id] FROM [School0402] [s] ))
var result4 = db.Queryable<Student>()
.Where(it => it.Id == SqlFunc.Subqueryable<School>().Select(s => s.Id))
.ToList();
}
[SugarTable("Student0402")]
public class Student
{
public int Id { get; set; }
public int SchoolId { get; set; }
}
[SugarTable("School0402")]
public class School
{
public int Id { get; set; }
public string Name { get; set; }
}
}
}

View File

@ -0,0 +1,112 @@
using OrmTest;
using SqlSugar;
using System;
using System.Linq;
using System.Threading.Tasks;
public class _5_PageQuery
{
public static void Init()
{
int pagenumber = 1;
int pageSize = 20;
int totalCount = 0;
SqlSugarClient db = DbHelper.GetNewDb();
//建表
//Create table
AddTestData(db);
// 同步分页方法
// Synchronous pagination method
SyncPagination(db, pagenumber, pageSize, ref totalCount);
// 异步分页方法
// Asynchronous pagination method
AsyncPagination(db, pagenumber, pageSize) .GetAwaiter() .GetResult();
}
public static void AddTestData(SqlSugarClient db)
{
//建表
//Create table
db.CodeFirst.InitTables<School, Student>();
// 添加学校数据
// Add school data
var school1 = new School { Name = "School A" };
var school2 = new School { Name = "School B" };
db.Insertable(school1).ExecuteCommand();
db.Insertable(school2).ExecuteCommand();
// 添加学生数据
// Add student data
var student1 = new Student { SchoolId = school1.Id, Name = "John", CreateTime = DateTime.Now };
var student2 = new Student { SchoolId = school1.Id, Name = "Alice", CreateTime = DateTime.Now };
db.Insertable(student1).ExecuteCommand();
db.Insertable(student2).ExecuteCommand();
Console.WriteLine("Test data added successfully.");
}
/// <summary>
/// 同步分页示例
/// Synchronous pagination example
/// </summary>
/// <param name="db">数据库连接对象 Database connection object</param>
/// <param name="pagenumber">页码 Page number</param>
/// <param name="pageSize">每页大小 Page size</param>
/// <param name="totalCount">总记录数 Total record count</param>
public static void SyncPagination(SqlSugarClient db, int pagenumber, int pageSize, ref int totalCount)
{
// 同步单表分页
// Synchronous pagination for a single table
var page = db.Queryable<Student>().ToPageList(pagenumber, pageSize, ref totalCount);
// 同步多表分页
// Synchronous pagination for multiple tables
var list = db.Queryable<Student>().LeftJoin<School>((st, sc) => st.SchoolId == sc.Id)
.Select((st, sc) => new { Id = st.Id, Name = st.Name, SchoolName = sc.Name })
.ToPageList(pagenumber, pageSize, ref totalCount);
// offset分页
// offset pagination
var sqlServerPage = db.Queryable<Student>().ToOffsetPage(pagenumber, pageSize);
}
/// <summary>
/// 异步分页示例
/// Asynchronous pagination example
/// </summary>
/// <param name="db">数据库连接对象 Database connection object</param>
/// <param name="pagenumber">页码 Page number</param>
/// <param name="pageSize">每页大小 Page size</param>
public static async Task AsyncPagination(SqlSugarClient db, int pagenumber, int pageSize)
{
RefAsync<int> total = 0;
// 异步分页
// Asynchronous pagination
var orders = await db.Queryable<Student>().ToPageListAsync(pagenumber, pageSize, total);
}
[SugarTable("Student05")]
public class Student
{
[SugarColumn(IsIdentity =true,IsPrimaryKey =true)]
public int Id { get; set; }
public int SchoolId { get; set; }
public string Name { get; set; }
public DateTime CreateTime { get; set; }
}
[SugarTable("School05")]
public class School
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,268 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class _6_NavQuery
{
/// <summary>
/// Initialize navigation query examples.
/// 初始化导航查询示例。
/// </summary>
public static void Init()
{
var db = DbHelper.GetNewDb();
// Initialize database table structures.
// 初始化数据库表结构。
InitializeDatabase(db);
// One-to-One navigation query test.
// 一对一导航查询测试。
OneToOneTest(db);
// One-to-Many navigation query test.
// 一对多导航查询测试。
OneToManyTest(db);
// Many-to-Many navigation query test.
// 多对多导航查询测试。
ManyToManyTest(db);
}
/// <summary>
/// Test many-to-many navigation queries.
/// 测试多对多导航查询。
/// </summary>
private static void ManyToManyTest(SqlSugarClient db)
{
// Many-to-many navigation query, query table A and include its BList.
// 多对多导航查询查询A表并包含其BList。
var list4 = db.Queryable<A>().Includes(it => it.BList).ToList();
// Many-to-many navigation query with filtered BList while preserving the original A records, regardless of the filter on BList.
// 使用过滤条件的多对多导航查询在过滤BList的同时保持A表的原始记录不受BList过滤条件的影响。
var list5 = db.Queryable<A>().Includes(it => it.BList.Where(s => s.BId == 1).ToList()).ToList();
// Many-to-many navigation query with filtered A records while preserving the original BList, regardless of the filter on A records.
// 使用过滤条件的多对多导航查询在过滤A表的同时保持BList的原始记录不受A表过滤条件的影响。
var list6 = db.Queryable<A>().Includes(it => it.BList)
.Where(it =>it.BList.Any(s => s.BId == 1)).ToList();
// Many-to-many navigation query with filtered BList and filtered A records, but not preserving the original A and B records.
// 使用过滤条件的多对多导航查询在A表中过滤BList并过滤A记录但不保持A表和B表的原始记录。
var list7 = db.Queryable<A>()
.Includes(it => it.BList.Where(s => s.BId == 1).ToList())
.Where(it => it.BList.Any(s => s.BId == 1)).ToList();
}
/// <summary>
/// Test one-to-many navigation queries.
/// 测试一对多导航查询。
/// </summary>
private static void OneToManyTest(SqlSugarClient db)
{
// One-to-many navigation query, query table Student and include its Books.
// 一对多导航查询查询Student表并包含其Books。
var list4 = db.Queryable<Student>().Includes(it => it.Books).ToList();
// One-to-many navigation query with filtered Books while preserving the original Student records, regardless of the filter on Books.
// 使用过滤条件的一对多导航查询在过滤Books的同时保持Student表的原始记录不受Books过滤条件的影响。
var list5 = db.Queryable<Student>().Includes(it => it.Books.Where(s => s.BookId == 1).ToList()).ToList();
// One-to-many navigation query with filtered Student records while preserving the original Books, regardless of the filter on Student records.
// 使用过滤条件的一对多导航查询在过滤Student表的同时保持Books的原始记录不受Student表过滤条件的影响。
var list6 = db.Queryable<Student>().Includes(it => it.Books)
.Where(it => it.Books.Any(s => s.BookId == 1)).ToList();
// One-to-many navigation query with filtered Books and filtered Student records, but not preserving the original Student and Books records.
// 使用过滤条件的一对多导航查询在Student表中过滤Books并过滤Student记录但不保持Student表和Books表的原始记录。
var list7 = db.Queryable<Student>()
.Includes(it => it.Books.Where(s => s.BookId == 1).ToList())
.Where(it => it.Books.Any(s => s.BookId == 1)).ToList();
}
/// <summary>
/// Test one-to-one navigation queries.
/// 测试一对一导航查询。
/// </summary>
private static void OneToOneTest(SqlSugarClient db)
{
// One-to-one navigation query with condition, query table Student and include its associated School with specific SchoolId.
// 带条件的一对一导航查询查询Student表并包含其关联的School表条件为特定的SchoolId。
var list = db.Queryable<Student>()
.Where(it => it.School.SchoolId == 1)
.ToList();
// Inner join navigation query, query table Student and include its associated School.
// 内连接导航查询查询Student表并包含其关联的School表。
var list2 = db.Queryable<Student>().IncludeInnerJoin(it => it.School)
.ToList();
// Includes navigation query, query table Student and include its associated School.
// 包含导航查询查询Student表并包含其关联的School表。
var list3 = db.Queryable<Student>().Includes(it => it.School).ToList();
}
/// <summary>
/// Initialize database tables and insert sample data for navigation query examples.
/// 初始化导航查询示例的数据库表并插入示例数据。
/// </summary>
private static void InitializeDatabase(SqlSugarClient db)
{
// Initialize and truncate tables for Student, School, and Book entities.
// 初始化并清空Student、School和Book表。
db.CodeFirst.InitTables<Student, School, Book>();
db.DbMaintenance.TruncateTable<Student, School, Book>();
// Sample data for Student, School, and Book entities.
// Student、School和Book表的示例数据。
var students = new List<Student>
{
new Student
{
Name = "Student 1",
SexCode = "M",
School = new School { SchoolName = "School 1" },
Books = new List<Book>
{
new Book { Name = "Book 1" },
new Book { Name = "Book 2" }
}
},
new Student
{
Name = "Student 2",
SexCode = "F",
School = new School { SchoolName = "School 2" },
Books = new List<Book>
{
new Book { Name = "Book 3" }
}
}
};
// Insert sample data for Student, School, and Book entities using navigation properties.
// 使用导航属性插入Student、School和Book表的示例数据。
db.InsertNav(students)
.Include(it => it.School)
.Include(it => it.Books).ExecuteCommand();
// Initialize and truncate tables for A, B, and ABMapping entities.
// 初始化并清空A、B和ABMapping表。
db.CodeFirst.InitTables<A, B, ABMapping>();
db.DbMaintenance.TruncateTable<A, B, ABMapping>();
// Sample data for A, B, and ABMapping entities.
// A、B和ABMapping表的示例数据。
List<A> a1 = new List<A> { new A() { Name = "A1" }, new A() { Name = "A2" } };
B b1 = new B { Name = "B1" };
B b2 = new B { Name = "B2" };
a1[0].BList = new List<B> { b1, b2 };
// Insert sample data for A, B, and ABMapping entities using navigation properties.
// 使用导航属性插入A、B和ABMapping表的示例数据。
db.InsertNav(a1).Include(x => x.BList).ExecuteCommand();
}
/// <summary>
/// Student entity representing the Student table in the database.
/// 表示数据库中Student表的Student实体类。
/// </summary>
[SugarTable("Student06")]
public class Student
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int StudentId { get; set; }
public string Name { get; set; }
public string SexCode { get; set; }
public int SchoolId { get; set; }
// One-to-One navigation property to School entity.
// 与School实体的一对一导航属性。
[Navigate(NavigateType.OneToOne, nameof(SchoolId))]
public School School { get; set; }
// One-to-Many navigation property to Book entities.
// 与Book实体的一对多导航属性。
[Navigate(NavigateType.OneToMany, nameof(Book.StudentId))]
public List<Book> Books { get; set; }
}
/// <summary>
/// School entity representing the School table in the database.
/// 表示数据库中School表的School实体类。
/// </summary>
[SugarTable("School06")]
public class School
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int SchoolId { get; set; }
public string SchoolName { get; set; }
}
/// <summary>
/// Book entity representing the Book table in the database.
/// 表示数据库中Book表的Book实体类。
/// </summary>
[SugarTable("Book06")]
public class Book
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int BookId { get; set; }
public string Name { get; set; }
public int StudentId { get; set; }
}
/// <summary>
/// A entity representing the A table in the database for many-to-many relationship.
/// 表示多对多关系中数据库中A表的A实体类。
/// </summary>
[SugarTable("A06")]
public class A
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int AId { get; set; }
public string Name { get; set; }
// Many-to-Many navigation property to B entities using ABMapping table.
// 与B实体的多对多导航属性使用ABMapping表。
[Navigate(typeof(ABMapping), nameof(ABMapping.AId), nameof(ABMapping.BId))]
public List<B> BList { get; set; }
}
/// <summary>
/// B entity representing the B table in the database for many-to-many relationship.
/// 表示多对多关系中数据库中B表的B实体类。
/// </summary>
[SugarTable("B06")]
public class B
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int BId { get; set; }
public string Name { get; set; }
// Many-to-Many navigation property to A entities using ABMapping table.
// 与A实体的多对多导航属性使用ABMapping表。
[Navigate(typeof(ABMapping), nameof(ABMapping.BId), nameof(ABMapping.AId))]
public List<A> AList { get; set; }
}
/// <summary>
/// ABMapping entity representing the intermediate table for many-to-many relationship between A and B entities.
/// 表示A和B实体之间多对多关系的中间表的ABMapping实体类。
/// </summary>
[SugarTable("ABMapping06")]
public class ABMapping
{
[SugarColumn(IsPrimaryKey = true)]
public int AId { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public int BId { get; set; }
}
}
}

View File

@ -0,0 +1,74 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class _7_GroupQuery
{
public static void Init()
{
var db = DbHelper.GetNewDb();
List<Student> students = new List<Student>
{
new Student { Id = 1, Name = "Alice", Age = 20 },
new Student { Id = 2, Name = "Bob", Age = 22 },
new Student { Id = 3, Name = "Alice", Age = 21 },
new Student { Id = 4, Name = "Charlie", Age = 19 },
new Student { Id = 5, Name = "Bob", Age = 20 }
};
// 初始化数据库表结构,如果表不存在则创建 (Initialize database table structure; create if not exists)
db.CodeFirst.InitTables<Student>();
// 清空指定表中的所有数据 (Truncate all data in the specified table)
db.DbMaintenance.TruncateTable<Student>();
//插入记录(Insert datas)
db.Insertable(students).ExecuteCommand();
// 分组查询示例 (Grouping Query Example)
var groupedStudents = db.Queryable<Student>()
.GroupBy(s => s.Name)
.Select(g => new
{
Name = g.Name, // 学生姓名 (Student Name)
Count = SqlFunc.AggregateCount(g.Id), // 学生数量 (Count of Students)
AverageAge = SqlFunc.AggregateAvg(g.Age), // 平均年龄 (Average Age)
MaxAge = SqlFunc.AggregateMax(g.Age), // 最大年龄 (Maximum Age)
MinAge = SqlFunc.AggregateMin(g.Age) // 最小年龄 (Minimum Age)
})
.ToList();
// 去重查询示例 (Distinct Query Example)
var distinctNames = students.Select(s => s.Name).Distinct().ToList();
// 分组取第一条记录示例 (Group First Record Example)
var groupFirstRecord = db.Queryable<Student>()
.Select(g => new
{
index = SqlFunc.RowNumber(SqlFunc.Desc(g.Id), g.Name),
Id = g.Id,
Name = g.Name,
Age =g.Age
})
.MergeTable()
.Where(it => it.index == 1)
.ToList();
}
[SqlSugar.SugarTable("Student07")]
public class Student
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; } // 学生ID (Student ID)
public string Name { get; set; } // 学生姓名 (Student Name)
public int Age { get; set; } // 学生年龄 (Student Age)
}
}
}

View File

@ -0,0 +1,66 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class _8_Insert
{
public static void Init()
{
var db = DbHelper.GetNewDb();
// 初始化实体表格Initialize entity tables
db.CodeFirst.InitTables<StudentWithIdentity, StudentWithSnowflake>();
// Use Case 1: 返回插入行数Return the number of inserted rows
var rowCount = db.Insertable(new StudentWithIdentity() { Name = "name" }).ExecuteCommand();
// Use Case 2: 插入数据并返回自增列Insert data and return the auto-incremented column
var identity = db.Insertable(new StudentWithIdentity() { Name = "name2" }).ExecuteReturnIdentity();
// Use Case 3: 返回雪花IDReturn the snowflake ID
var snowflakeId = db.Insertable(new StudentWithSnowflake() { Name = "name" }).ExecuteReturnSnowflakeId();
// Use Case 4: 强制设置表名别名Forcefully set table name alias
db.Insertable(new StudentWithIdentity() { Name = "name2" }).AS("StudentWithIdentity").ExecuteCommand();
// Use Case 5: 批量插入实体非参数化插入Batch insert entities (non-parameterized)
var list = db.Queryable<StudentWithIdentity>().Take(2).ToList();
db.Insertable(list).ExecuteCommand();
db.Insertable(list).PageSize(1000).ExecuteCommand();
// Use Case 6: 参数化内部分页插入Parameterized internal pagination insert
db.Insertable(list).UseParameter().ExecuteCommand();
// Use Case 7: 大数据写入示例代码请根据实际情况调整Bulk data insertion - Example code, adjust based on actual scenario
var listLong = new List<StudentWithSnowflake>() {
new StudentWithSnowflake() { Name = "name",Id=SnowFlakeSingle.Instance.NextId() },
new StudentWithSnowflake() { Name = "name",Id=SnowFlakeSingle.Instance.NextId()}
};
db.Fastest<StudentWithSnowflake>().BulkCopy(listLong);
}
// 实体类带自增主键Entity class: With auto-increment primary key
[SugarTable("StudentWithIdentity08")]
public class StudentWithIdentity
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
}
// 实体类带雪花主键Entity class: With snowflake primary key
[SugarTable("StudentWithSnowflake08")]
public class StudentWithSnowflake
{
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
public string Name { get; set; }
}
}
}

View File

@ -0,0 +1,88 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static OrmTest._8_Insert;
namespace OrmTest
{
internal class _9_Update
{
/// <summary>
/// 初始化更新方法Initialize update methods
/// </summary>
internal static void Init()
{
var db = DbHelper.GetNewDb();
// 初始化实体表格Initialize entity tables
db.CodeFirst.InitTables<StudentWithSnowflake>();
// 创建一个需要更新的实体对象Create an entity object to be updated
var updateObj = new StudentWithSnowflake() { Id = 1, Name = "order1" };
// 创建需要批量更新的实体对象列表Create a list of entity objects to be updated in bulk
var updateObjs = new List<StudentWithSnowflake> {
new StudentWithSnowflake() { Id = 11, Name = "order11", Date=DateTime.Now },
new StudentWithSnowflake() { Id = 12, Name = "order12", Date=DateTime.Now }
};
/***************************根据实体更新 (Update based on entity)***************************/
// 更新单个实体对象Update a single entity object
var result = db.Updateable(updateObj).ExecuteCommand();
// 批量更新实体对象列表Update a list of entity objects in bulk
var result20 = db.Updateable(updateObjs).ExecuteCommand();
var result21 = db.Updateable(updateObjs).PageSize(500).ExecuteCommand();
// 更新实体对象忽略指定列Update entity object, ignoring specific columns
var result3 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Remark }).ExecuteCommand();
// 更新实体对象的指定列Update specific columns of the entity object
var result4 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name, it.Date }).ExecuteCommand();
// 如果没有主键按照指定列更新实体对象If there is no primary key, update entity object based on specified columns
var result5 = db.Updateable(updateObj).WhereColumns(it => new { it.Id }).ExecuteCommand();
// 如果字段值为NULL不进行更新Do not update columns with NULL values
var result6 = db.Updateable(updateObj).IgnoreNullColumns().ExecuteCommand();
// 忽略为NULL和默认值的列进行更新Ignore columns with NULL and default values during update
var result7 = db.Updateable(updateObj)
.IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue:true)
.ExecuteCommand();
// 使用最快的方式批量更新实体对象列表Bulk update a list of entity objects using the fastest method
var result8 = db.Fastest<StudentWithSnowflake>().BulkUpdate(updateObjs);
/***************************表达式更新 (Expression Update)***************************/
// 使用表达式更新实体对象的指定列Update specific columns of the entity object using expressions
var result71 = db.Updateable<StudentWithSnowflake>()
.SetColumns(it => new StudentWithSnowflake() { Name = "a", Date = DateTime.Now })
.Where(it => it.Id == 11)
.ExecuteCommand();
// 使用表达式更新实体对象的指定列Update specific columns of the entity object using expressions
var result81 = db.Updateable<StudentWithSnowflake>()
.SetColumns(it => it.Name == "Name" + "1")
.Where(it => it.Id == 1)
.ExecuteCommand();
}
// 实体类带雪花主键Entity class: With snowflake primary key
[SugarTable("StudentWithSnowflake09")]
public class StudentWithSnowflake
{
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
[SugarColumn(IsNullable = true)]
public string Remark { get; set; }
}
}
}

View File

@ -79,87 +79,107 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Bugs\BugTest1.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Demo\Demo1_Queryable.cs" />
<Compile Include="Demo\Demo2_Updateable.cs" />
<Compile Include="Demo\Demo3_Insertable.cs" />
<Compile Include="Demo\Demo4_Deleteable.cs" />
<Compile Include="Demo\Demo5_SqlQueryable.cs" />
<Compile Include="Demo\Demo6_Queue.cs" />
<Compile Include="Demo\Demo7_Ado.cs" />
<Compile Include="Demo\Demo8_Saveable.cs" />
<Compile Include="Demo\Demo9_EntityMain.cs" />
<Compile Include="Demo\DemoA_DbMain.cs" />
<Compile Include="Demo\DemoB_Aop.cs" />
<Compile Include="Demo\Democ_GobalFilter.cs" />
<Compile Include="Demo\DemoD_DbFirst.cs" />
<Compile Include="Demo\DemoE_CodeFirst.cs" />
<Compile Include="Demo\DemoF_Utilities.cs" />
<Compile Include="Demo\DemoG_SimpleClient.cs" />
<Compile Include="Demo\DemoN_SplitTable.cs" />
<Compile Include="Demo\DemoO_Fastest.cs" />
<Compile Include="Models\AttributeTable.cs" />
<Compile Include="Models\CarType.cs" />
<Compile Include="Models\Custom.cs" />
<Compile Include="Models\EntityMapper.cs" />
<Compile Include="Models\Mapper.cs" />
<Compile Include="Models\MyCustomAttributeTable.cs" />
<Compile Include="Models\Order.cs" />
<Compile Include="Models\OrderItem.cs" />
<Compile Include="Models\TestTree.cs" />
<Compile Include="Models\Tree.cs" />
<Compile Include="Models\Unit\Custom1\EGoods.cs" />
<Compile Include="Models\Unit\Custom1\EGoodsBrand.cs" />
<Compile Include="Models\Unit\Custom1\EGoodsClass.cs" />
<Compile Include="Models\Unit\Custom1\EOrderAlbaran.cs" />
<Compile Include="Models\Unit\Custom1\EOrderAlbaranDetail.cs" />
<Compile Include="Models\Unit\Custom1\EOrderReturn.cs" />
<Compile Include="Models\Unit\Custom1\EOrderReturnDetail.cs" />
<Compile Include="Models\Unit\Custom1\PurchaseDetailModel.cs" />
<Compile Include="Models\ViewOrder.cs" />
<Compile Include="Demo\DemoJ_Report.cs" />
<Compile Include="UnitTest\SubToList002.cs" />
<Compile Include="UnitTest\UnitDateTimeOffset.cs" />
<Compile Include="UnitTest\UinitCustomConvert.cs" />
<Compile Include="UnitTest\Unitadsfasf1.cs" />
<Compile Include="UnitTest\CrossDatabase02.cs" />
<Compile Include="UnitTest\Models\BilPayment.cs" />
<Compile Include="UnitTest\Models\BilSupplierbalancerecord.cs" />
<Compile Include="UnitTest\UCustom20.cs" />
<Compile Include="UnitTest\UBulkCopy2.cs" />
<Compile Include="UnitTest\UCustom07.cs" />
<Compile Include="UnitTest\UDelete.cs" />
<Compile Include="UnitTest\UBulkCopy.cs" />
<Compile Include="UnitTest\UCustom011.cs" />
<Compile Include="UnitTest\UCustom012.cs" />
<Compile Include="UnitTest\UCustom014.cs" />
<Compile Include="UnitTest\UCustom015.cs" />
<Compile Include="UnitTest\UCustom06.cs" />
<Compile Include="UnitTest\UInsert.cs" />
<Compile Include="UnitTest\UInsert3.cs" />
<Compile Include="UnitTest\UnitCustom01.cs" />
<Compile Include="UnitTest\UnitSameKeyBug.cs" />
<Compile Include="UnitTest\UnitSqlFunc.cs" />
<Compile Include="UnitTest\UnitSubToList.cs" />
<Compile Include="UnitTest\UnitSubToList001.cs" />
<Compile Include="UnitTest\UnitTestReturnPkList.cs" />
<Compile Include="UnitTest\UOneManyMany.cs" />
<Compile Include="UnitTest\UQueue.cs" />
<Compile Include="1_CodeFirst.cs" />
<Compile Include="2_DbFirst.cs" />
<Compile Include="3_EasyQuery.cs" />
<Compile Include="4_JoinQuery.cs" />
<Compile Include="4_Subquery.cs" />
<Compile Include="5_PageQuery.cs" />
<Compile Include="6_NavigationPropertyQuery.cs" />
<Compile Include="7_GroupQuery.cs" />
<Compile Include="8_Insert.cs" />
<Compile Include="9_Update.cs" />
<Compile Include="a1_Delete.cs" />
<Compile Include="a2_Sql.cs" />
<Compile Include="a3_Merge.cs" />
<Compile Include="a4_SplitTable.cs" />
<Compile Include="a5_GridSave.cs" />
<Compile Include="a6_SqlPage.cs" />
<Compile Include="a7_JsonType.cs" />
<Compile Include="a8_SelectReturnType.cs" />
<Compile Include="Program.cs" />
<Compile Include="UserTestCases\Config.cs" />
<Compile Include="UserTestCases\Bugs\BugTest1.cs" />
<Compile Include="UserTestCases\Cases\Demo0_SqlSugarClient.cs" />
<Compile Include="UserTestCases\Cases\Demo1_Queryable.cs" />
<Compile Include="UserTestCases\Cases\Demo2_Updateable.cs" />
<Compile Include="UserTestCases\Cases\Demo3_Insertable.cs" />
<Compile Include="UserTestCases\Cases\Demo4_Deleteable.cs" />
<Compile Include="UserTestCases\Cases\Demo5_SqlQueryable.cs" />
<Compile Include="UserTestCases\Cases\Demo6_Queue.cs" />
<Compile Include="UserTestCases\Cases\Demo7_Ado.cs" />
<Compile Include="UserTestCases\Cases\Demo8_Saveable.cs" />
<Compile Include="UserTestCases\Cases\Demo9_EntityMain.cs" />
<Compile Include="UserTestCases\Cases\DemoA_DbMain.cs" />
<Compile Include="UserTestCases\Cases\DemoB_Aop.cs" />
<Compile Include="UserTestCases\Cases\Democ_GobalFilter.cs" />
<Compile Include="UserTestCases\Cases\DemoD_DbFirst.cs" />
<Compile Include="UserTestCases\Cases\DemoE_CodeFirst.cs" />
<Compile Include="UserTestCases\Cases\DemoF_Utilities.cs" />
<Compile Include="UserTestCases\Cases\DemoG_SimpleClient.cs" />
<Compile Include="UserTestCases\Cases\DemoN_SplitTable.cs" />
<Compile Include="UserTestCases\Cases\DemoO_Fastest.cs" />
<Compile Include="UserTestCases\Models\AttributeTable.cs" />
<Compile Include="UserTestCases\Models\CarType.cs" />
<Compile Include="UserTestCases\Models\Custom.cs" />
<Compile Include="UserTestCases\Models\EntityMapper.cs" />
<Compile Include="UserTestCases\Models\Mapper.cs" />
<Compile Include="UserTestCases\Models\MyCustomAttributeTable.cs" />
<Compile Include="UserTestCases\Models\Order.cs" />
<Compile Include="UserTestCases\Models\OrderItem.cs" />
<Compile Include="UserTestCases\Models\TestTree.cs" />
<Compile Include="UserTestCases\Models\Tree.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EGoods.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EGoodsBrand.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EGoodsClass.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EOrderAlbaran.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EOrderAlbaranDetail.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EOrderReturn.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\EOrderReturnDetail.cs" />
<Compile Include="UserTestCases\Models\Unit\Custom1\PurchaseDetailModel.cs" />
<Compile Include="UserTestCases\Models\ViewOrder.cs" />
<Compile Include="UserTestCases\Cases\DemoJ_Report.cs" />
<Compile Include="UserTestCases\UnitTest\SubToList002.cs" />
<Compile Include="UserTestCases\UnitTest\UnitDateTimeOffset.cs" />
<Compile Include="UserTestCases\UnitTest\UinitCustomConvert.cs" />
<Compile Include="UserTestCases\UnitTest\Unitadsfasf1.cs" />
<Compile Include="UserTestCases\UnitTest\CrossDatabase02.cs" />
<Compile Include="UserTestCases\UnitTest\Models\BilPayment.cs" />
<Compile Include="UserTestCases\UnitTest\Models\BilSupplierbalancerecord.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom20.cs" />
<Compile Include="UserTestCases\UnitTest\UBulkCopy2.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom07.cs" />
<Compile Include="UserTestCases\UnitTest\UDelete.cs" />
<Compile Include="UserTestCases\UnitTest\UBulkCopy.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom011.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom012.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom014.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom015.cs" />
<Compile Include="UserTestCases\UnitTest\UCustom06.cs" />
<Compile Include="UserTestCases\UnitTest\UInsert.cs" />
<Compile Include="UserTestCases\UnitTest\UInsert3.cs" />
<Compile Include="UserTestCases\UnitTest\UnitCustom01.cs" />
<Compile Include="UserTestCases\UnitTest\Unitdfafa.cs" />
<Compile Include="UserTestCases\UnitTest\UnitSameKeyBug.cs" />
<Compile Include="UserTestCases\UnitTest\UnitSqlFunc.cs" />
<Compile Include="UserTestCases\UnitTest\UnitSubToList.cs" />
<Compile Include="UserTestCases\UnitTest\UnitSubToList001.cs" />
<Compile Include="UserTestCases\UnitTest\UnitTestReturnPkList.cs" />
<Compile Include="UserTestCases\UnitTest\UOneManyMany.cs" />
<Compile Include="UserTestCases\UnitTest\UQueue.cs" />
<Compile Include="UserTestCases\Cases.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitTest\Main.cs" />
<Compile Include="UnitTest\UAdo.cs" />
<Compile Include="UnitTest\UCodeFirst.cs" />
<Compile Include="UnitTest\UJson.cs" />
<Compile Include="UnitTest\Updateable.cs" />
<Compile Include="UnitTest\UQueryable.cs" />
<Compile Include="UnitTest\UQueryableAsync.cs" />
<Compile Include="UnitTest\UThread.cs" />
<Compile Include="UnitTest\UThread2.cs" />
<Compile Include="UnitTest\UThread3.cs" />
<Compile Include="UnitTest\UValidate.cs" />
<Compile Include="UserTestCases\UnitTest\Main.cs" />
<Compile Include="UserTestCases\UnitTest\UAdo.cs" />
<Compile Include="UserTestCases\UnitTest\UCodeFirst.cs" />
<Compile Include="UserTestCases\UnitTest\UJson.cs" />
<Compile Include="UserTestCases\UnitTest\Updateable.cs" />
<Compile Include="UserTestCases\UnitTest\UQueryable.cs" />
<Compile Include="UserTestCases\UnitTest\UQueryableAsync.cs" />
<Compile Include="UserTestCases\UnitTest\UThread.cs" />
<Compile Include="UserTestCases\UnitTest\UThread2.cs" />
<Compile Include="UserTestCases\UnitTest\UThread3.cs" />
<Compile Include="UserTestCases\UnitTest\UValidate.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View File

@ -1,42 +1,73 @@
using System;
using SqlSugar;
using System;
namespace OrmTest
{
class Program
public class Program
{
static void Main(string[] args)
{
//Demo
Demo0_SqlSugarClient.Init();
DemoO_Fastest.Init();
Demo1_Queryable.Init();
Demo2_Updateable.Init();
Demo3_Insertable.Init();
DemoN_SplitTable.Init();
Demo4_Deleteable.Init();
Demo5_SqlQueryable.Init();
Demo6_Queue.Init();
Demo7_Ado.Init();
Demo8_Saveable.Init();
Demo9_EntityMain.Init();
DemoA_DbMain.Init();
DemoB_Aop.Init();
DemoC_GobalFilter.Init();
DemoD_DbFirst.Init(); ;
DemoE_CodeFirst.Init();
DemoF_Utilities.Init();
DemoG_SimpleClient.Init();
DemoJ_Report.Init();
//Unit test
//NewUnitTest.Init();
//Each example will automatically create a table and can run independently.
//每个例子都会自动建表 并且可以独立运行
//Rest Data
NewUnitTest.RestData();
Console.WriteLine("all successfully.");
Console.ReadKey();
_1_CodeFirst.Init();
_2_DbFirst.Init();
_3_EasyQuery.Init();
_4_JoinQuery.Init();
_4_Subquery.Init();
_5_PageQuery.Init();
_6_NavQuery.Init();
_7_GroupQuery.Init();
_8_Insert.Init();
_9_Update.Init();
_a1_Delete.Init();
_a2_Sql.Init();
_a3_Merge.Init();
_a4_SplitTable.Init();
_a5_GridSave.Init();
_a6_SqlPage.Init();
_a7_JsonType.Init();
_a8_SelectReturnType.Init();
}
}
}
/// <summary>
/// Helper class for database operations
/// 数据库操作的辅助类
/// </summary>
public class DbHelper
{
/// <summary>
/// Database connection string
/// 数据库连接字符串
/// </summary>
public readonly static string Connection = "server=localhost;Database=SqlSugar5xTest;Uid=root;Pwd=123456;AllowLoadLocalInfile=true";
/// <summary>
/// Get a new SqlSugarClient instance with specific configurations
/// 获取具有特定配置的新 SqlSugarClient 实例
/// </summary>
/// <returns>SqlSugarClient instance</returns>
public static SqlSugarClient GetNewDb()
{
var db = new SqlSugarClient(new ConnectionConfig()
{
IsAutoCloseConnection = true,
DbType = DbType.MySql,
ConnectionString = Connection,
LanguageType=LanguageType.Default//Set language
},
it => {
// Logging SQL statements and parameters before execution
// 在执行前记录 SQL 语句和参数
it.Aop.OnLogExecuting = (sql, para) =>
{
Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
};
});
return db;
}
}
}

View File

@ -0,0 +1,42 @@
using System;
namespace OrmTest
{
public class Cases
{
public static void Init()
{
//Demo
Demo0_SqlSugarClient.Init();
DemoO_Fastest.Init();
Demo1_Queryable.Init();
Demo2_Updateable.Init();
Demo3_Insertable.Init();
DemoN_SplitTable.Init();
Demo4_Deleteable.Init();
Demo5_SqlQueryable.Init();
Demo6_Queue.Init();
Demo7_Ado.Init();
Demo8_Saveable.Init();
Demo9_EntityMain.Init();
DemoA_DbMain.Init();
DemoB_Aop.Init();
DemoC_GobalFilter.Init();
DemoD_DbFirst.Init(); ;
DemoE_CodeFirst.Init();
DemoF_Utilities.Init();
DemoG_SimpleClient.Init();
DemoJ_Report.Init();
//Unit test
NewUnitTest.Init();
//Rest Data
NewUnitTest.RestData();
Console.WriteLine("all successfully.");
Console.ReadKey();
}
}
}

View File

@ -101,6 +101,19 @@ namespace OrmTest
names = $"as{it.Id}fd{it.Id}a"
})
.ToList();
var test49 = db.Queryable<Order>().Select(it => new
{
index = SqlFunc.RowNumber($"{it.Name} asc,{it.Id} desc", $"{it.Id},{it.Name}")
})
.ToList();
var test491 = db.Queryable<Order>().Select(it => new
{
index = SqlFunc.RowNumber($"{it.Name} asc,{it.Id} desc", $"{it.Id},{it.Name},{it.CustomId},{it.Price}")
})
.ToList();
var yy = "aa";
db.Queryable<Order>().Where(it => it.Name == $"a{yy}a").ToList();
Console.WriteLine("#### Examples End ####");
}

View File

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UnitDtoJsonafda.Init();
UnitSubToList002.Init();
UnitSubToList002.Init();
UnitDateTimeOffset.Init();

View File

@ -20,7 +20,7 @@ namespace OrmTest
var x5 = db.Queryable<Order>().Select(it => DateTime.Now.DayOfWeek.ToString() ).ToList();
if (x1.Any())
{
Check.Exception(x1.First()!=365, "unit error . UCustom011");
Check.Exception(x1.First()!=365&& x1.First() != 366, "unit error . UCustom011");
Check.Exception(x2.First() != 24, "unit error . UCustom011");
Check.Exception(x3.First() != 60, "unit error . UCustom011");
Check.Exception(!(x4.First() >=60&& x4.First() <= 61), "unit error . UCustom011");

View File

@ -63,8 +63,25 @@ namespace OrmTest
var list31 = db.Queryable<OrderAarray11>().ToList();
var list3=db.Queryable<OrderMain11>().LeftJoin<OrderAarray11>((t1, ti2) => t1.Id == ti2.fk)
.Select((t1, ti2) => new { t1.Id, t1.Name,json= ti2.Json }).ToList();
db.CodeFirst.InitTables<Unitaaar2>();
db.Insertable(new Unitaaar2() { arr = new string[] { "a", "c" } }).ExecuteCommand();
var list141 = db.Queryable<Unitaaar2>()
.Select(it => new {
x = SqlFunc.JsonIndex(it.arr, 0),
x2 = SqlFunc.JsonIndex(it.arr, 1)
}).ToList();
if (list141.First().x != "a" && list141.Last().x != "c")
{
throw new Exception("unit error");
}
}
public class OrderMain11
public class Unitaaar2
{
[SugarColumn(IsJson = true, IsNullable = true)]
public string[] arr { get; set; }
}
public class OrderMain11
{
[SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
public int Id { get; set; }

Some files were not shown because too many files have changed in this diff Show More