From 124c8bd09fc346cf518788088852b54e7fa045de Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 12 Aug 2024 17:39:58 +0800 Subject: [PATCH] Add user test case --- .../UserTestCases/UnitTest/Main.cs | 1 + .../UnitTest/Unitasf1/UnitSplitadfaf1.cs | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitasf1/UnitSplitadfaf1.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs index d8ae4294c..a406150ab 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Main.cs @@ -33,6 +33,7 @@ namespace OrmTest } public static void Init() { + UnitSplitadfaf1.Init(); Unitaadfas1.Init(); Unitadfasda.Init(); Unita3affafa.Init(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitasf1/UnitSplitadfaf1.cs b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitasf1/UnitSplitadfaf1.cs new file mode 100644 index 000000000..8be42123f --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitasf1/UnitSplitadfaf1.cs @@ -0,0 +1,52 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + internal class UnitSplitadfaf1 + { + public static void Init() + { + var db = NewUnitTest.Db; + db.CodeFirst.InitTables(); + + db.Insertable(new SplitTableDemo() { Name = "a", Time = DateTime.Now, Pk = Guid.NewGuid() }) + .SplitTable().ExecuteCommand(); + + var list=db.Queryable().SplitTable() + .Select().ToList(); + if (list.First().Time == DateTime.MinValue) + { + throw new Exception("unit eror"); + } + } + // Entity class representing the split table + // 代表分表的实体类 + [SplitTable(SplitType.Day)] // Specify the split type as "Day" + // 指定分表类型为“Day” + [SqlSugar.SugarTable("UnitSplit1231_{year}{month}{day}")] // Specify the table name pattern + // 指定表名模式 + public class SplitTableDemo + { + [SugarColumn(IsPrimaryKey = true)] // Specify primary key + // 指定主键 + public Guid Pk { get; set; } + [SugarColumn(IsNullable = true, ColumnName = "x_name")] + public string Name { get; set; } + + [SugarColumn(IsNullable = true,ColumnName ="x_time")] + [SplitField] // Mark the field as a split field + // 将字段标记为分表字段 + public DateTime Time { get; set; } + } + public class SplitTableDemoDto + { + public DateTime Time { get; set; } + + } + } +}