Update demo

This commit is contained in:
sunkaixuan 2023-11-06 19:12:46 +08:00
parent 8bdb8f67d4
commit 9d4565baf3
7 changed files with 92 additions and 5 deletions

View File

@ -1,5 +1,7 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -8,5 +10,56 @@ 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();
// 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

@ -8,5 +8,9 @@ namespace OrmTest
{
internal class _9_Update
{
internal static void Init()
{
}
}
}

View File

@ -15,6 +15,11 @@ namespace OrmTest
_5_PageQuery.Init();
_6_NavQuery.Init();
_7_GroupQuery.Init();
_8_Insert.Init();
_9_Update.Init();
_a1_Delete.Init();
_a2_Sql.Init();
_a3_Merge.Init();
}
}

View File

@ -71,6 +71,7 @@
<Compile Include="5_PageQuery.cs" />
<Compile Include="9_Update.cs" />
<Compile Include="a2_Sql.cs" />
<Compile Include="a3_Merge.cs" />
<Compile Include="UnitTest\Description.cs" />
<Compile Include="3_EasyQuery.cs" />
<Compile Include="7_GroupQuery.cs" />

View File

@ -6,7 +6,11 @@ using System.Threading.Tasks;
namespace OrmTest
{
internal class _10_Delete
internal class _a1_Delete
{
internal static void Init()
{
}
}
}

View File

@ -6,7 +6,11 @@ using System.Threading.Tasks;
namespace OrmTest
{
internal class a2_Sql
internal class _a2_Sql
{
internal static void Init()
{
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class _a3_Merge
{
internal static void Init()
{
}
}
}