SqlSugar/Src/Asp.NetCore2/OracleTest/UserTestCases/UnitTest/UnitBulkMerge.cs

83 lines
2.9 KiB
C#
Raw Normal View History

2023-10-17 11:17:18 +08:00
using SqlSugar;
using System;
2023-10-04 18:38:48 +08:00
using System.Collections.Generic;
using System.Text;
namespace OrmTest
{
internal class UnitBulkMerge
{
public static void Init()
{
var db = NewUnitTest.Db;
db.CodeFirst.InitTables<UnitaafdsTest>();
db.DbMaintenance.TruncateTable<UnitaafdsTest>();
var count=db.Fastest<UnitaafdsTest>()
.BulkMerge(new List<UnitaafdsTest>() { new UnitaafdsTest() { Id=Guid.NewGuid()
, CreateTime=DateTime.Now, Name="a"} });
var list=db.Queryable<UnitaafdsTest>().ToList();
2023-10-04 18:49:26 +08:00
if (list[0].Name != "a") { throw new Exception("unit error"); }
2023-10-04 18:38:48 +08:00
list[0].Name = "j";
var count2 = db.Fastest<UnitaafdsTest>()
.BulkMerge(list);
var list2 = db.Queryable<UnitaafdsTest>().ToList();
2023-10-04 18:49:26 +08:00
if (list2[0].Name != "j"|| count2!=1) { throw new Exception("unit error"); }
list2.Add(new UnitaafdsTest()
{
Id = Guid.NewGuid() ,
CreateTime = DateTime.Now,
Name = "a"
});
list2.Add(new UnitaafdsTest()
{
Id = Guid.NewGuid() ,
CreateTime = DateTime.Now,
Name = "a"
});
db.Fastest<UnitaafdsTest>()
.BulkMerge(list2);
var count3 = db.Queryable<UnitaafdsTest>()
.Count();
if (count3 != 3)
{
throw new Exception("unit error");
}
2023-10-17 11:17:18 +08:00
for (int i = 0; i < 1; i++)
2023-10-04 18:38:48 +08:00
{
db.Fastest<UnitaafdsTest>()
2023-10-04 18:49:26 +08:00
.BulkMerge(list);
2023-10-04 18:38:48 +08:00
}
2023-10-17 11:17:18 +08:00
db.CodeFirst.InitTables<TableA>();
db.Insertable(new TableA() { key1 = Guid.NewGuid() + "" })
.ExecuteCommand();
db.Insertable(new TableA() { key1 = Guid.NewGuid() + "" })
.ExecuteCommand();
var datas = db.Queryable<TableA>().ToList();
db.Fastest<TableA>().PageSize(10000).BulkMerge(datas);
2023-10-04 18:38:48 +08:00
}
}
2023-10-17 11:17:18 +08:00
public class TableA
{
[SugarColumn(IsPrimaryKey = true)]
public string key1 { get; set; } = "a";
[SugarColumn(IsPrimaryKey = true)]
public string key2 { get; set; } = "b";
[SugarColumn(IsPrimaryKey = true)]
public string key3 { get; set; } = "c";
public string str1 { get; set; } = "c";
public string str2 { get; set; } = "c";
public DateTime? date1 { get; set; } = DateTime.Now;
public DateTime? date2 { get; set; } = DateTime.Now;
public decimal? num1 { get; set; } = 0;
public decimal? num2 { get; set; } = 0;
}
2023-10-04 18:38:48 +08:00
public class UnitaafdsTest
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime CreateTime{ get; set; }
}
}