From a1b1f7084afc3c8d6c6adf5246f403eb045069e1 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 13 Aug 2024 11:03:20 +0800 Subject: [PATCH] Add demo --- .../Net7Test/NET7Test/NET7Test/Program.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Src/Asp.NetCore2/Net7Test/NET7Test/NET7Test/Program.cs b/Src/Asp.NetCore2/Net7Test/NET7Test/NET7Test/Program.cs index 6b6ce0730..bc0f6bb67 100644 --- a/Src/Asp.NetCore2/Net7Test/NET7Test/NET7Test/Program.cs +++ b/Src/Asp.NetCore2/Net7Test/NET7Test/NET7Test/Program.cs @@ -53,6 +53,26 @@ static void MyTest() sqlugar.Updateable(new UnitDatez211afa2222()).WhereColumns(it=>it.timeOnly).ExecuteCommand(); sqlugar.Insertable(new UnitDatez211afa2222() { dateOnly=DateOnly.FromDateTime(DateTime.Now) }).ExecuteCommand(); var list2=sqlugar.Queryable().ToList(); + + var db = sqlugar; + // 建表 + var typeBilder = db.DynamicBuilder().CreateClass("stats_values", new()); + typeBilder.CreateProperty("date", typeof(DateOnly), new() { IsPrimaryKey = true }); + typeBilder.CreateProperty("d1", typeof(uint), new() { ColumnDataType = "INT UNSIGNED" }); + typeBilder.CreateProperty("d2", typeof(uint), new() { ColumnDataType = "INT UNSIGNED" }); + var type = typeBilder.BuilderType(); + db.CodeFirst.InitTables(type); + + // 保存数据 + var currentDate = DateOnly.FromDateTime(DateTime.Now); + var stats = new Dictionary + { + ["date"] = currentDate, + ["d1"] = 1, + ["d2"] = 2 + }; + var statsValue = db.DynamicBuilder().CreateObjectByType(type, stats); + db.StorageableByObject(statsValue).ExecuteCommand(); } static void ServerTest() {