mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OrmTest
|
|
{
|
|
internal class UnitSplitTask
|
|
{
|
|
public static void Init()
|
|
{
|
|
var client = NewUnitTest.Db;
|
|
Console.WriteLine("Hello, World!");
|
|
List<Task> tasks = new List<Task>()
|
|
{
|
|
CreateTask(client.CopyNew()),
|
|
CreateTask(client.CopyNew()),
|
|
CreateTask(client.CopyNew())
|
|
};
|
|
|
|
Task.WhenAll(tasks).GetAwaiter().GetResult();
|
|
var table = client.SplitHelper<SpitDemoModel>().GetTableName(SplitType.Day);
|
|
client.DbMaintenance.DropTable(table);
|
|
}
|
|
|
|
|
|
private static Task CreateTask(ISqlSugarClient client)
|
|
{
|
|
return Task.Run(() => {
|
|
client.Insertable(new SpitDemoModel()).SplitTable().ExecuteCommand();
|
|
});
|
|
}
|
|
}
|
|
|
|
[SplitTable(SplitType.Day)]
|
|
[SugarTable("SpitDemo_{year}{month}{day}")]
|
|
public class SpitDemoModel
|
|
{
|
|
[SugarColumn(IsPrimaryKey = true)]
|
|
public Guid Id { get; set; } = Guid.NewGuid();
|
|
[SplitField]
|
|
public DateTime CreateTime { get; set; } = DateTime.Now;
|
|
|
|
}
|
|
}
|
|
|