mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update demo
This commit is contained in:
parent
8bdb8f67d4
commit
9d4565baf3
@ -1,5 +1,7 @@
|
|||||||
using System;
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,5 +10,56 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
internal class _8_Insert
|
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: 返回雪花ID(Return 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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,5 +8,9 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
internal class _9_Update
|
internal class _9_Update
|
||||||
{
|
{
|
||||||
|
internal static void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@ namespace OrmTest
|
|||||||
_5_PageQuery.Init();
|
_5_PageQuery.Init();
|
||||||
_6_NavQuery.Init();
|
_6_NavQuery.Init();
|
||||||
_7_GroupQuery.Init();
|
_7_GroupQuery.Init();
|
||||||
|
_8_Insert.Init();
|
||||||
|
_9_Update.Init();
|
||||||
|
_a1_Delete.Init();
|
||||||
|
_a2_Sql.Init();
|
||||||
|
_a3_Merge.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
<Compile Include="5_PageQuery.cs" />
|
<Compile Include="5_PageQuery.cs" />
|
||||||
<Compile Include="9_Update.cs" />
|
<Compile Include="9_Update.cs" />
|
||||||
<Compile Include="a2_Sql.cs" />
|
<Compile Include="a2_Sql.cs" />
|
||||||
|
<Compile Include="a3_Merge.cs" />
|
||||||
<Compile Include="UnitTest\Description.cs" />
|
<Compile Include="UnitTest\Description.cs" />
|
||||||
<Compile Include="3_EasyQuery.cs" />
|
<Compile Include="3_EasyQuery.cs" />
|
||||||
<Compile Include="7_GroupQuery.cs" />
|
<Compile Include="7_GroupQuery.cs" />
|
||||||
|
@ -6,7 +6,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace OrmTest
|
namespace OrmTest
|
||||||
{
|
{
|
||||||
internal class _10_Delete
|
internal class _a1_Delete
|
||||||
{
|
{
|
||||||
|
internal static void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace OrmTest
|
namespace OrmTest
|
||||||
{
|
{
|
||||||
internal class a2_Sql
|
internal class _a2_Sql
|
||||||
{
|
{
|
||||||
|
internal static void Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
Src/Asp.Net/SqlServerTest/a3_Merge.cs
Normal file
16
Src/Asp.Net/SqlServerTest/a3_Merge.cs
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user