From 4e36d6ca204921c3eb28908f0c20b111b9a74c55 Mon Sep 17 00:00:00 2001 From: d4ilys <963922242@qq.com> Date: Fri, 5 May 2023 11:19:09 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0DynamicEntity=20-=20Super?= =?UTF-8?q?Class=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DynamicEntity/DynamicEntityTest.cs | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/FreeSql.Tests/FreeSql.Tests/DynamicEntity/DynamicEntityTest.cs b/FreeSql.Tests/FreeSql.Tests/DynamicEntity/DynamicEntityTest.cs index 8b80a2fc..c3638f85 100644 --- a/FreeSql.Tests/FreeSql.Tests/DynamicEntity/DynamicEntityTest.cs +++ b/FreeSql.Tests/FreeSql.Tests/DynamicEntity/DynamicEntityTest.cs @@ -21,14 +21,14 @@ namespace FreeSql.Tests.DynamicEntity { Type type = DynamicCompileHelper.DynamicBuilder() .Class("NormalUsers") - .Property("Id", typeof(int)) + .Property("Id", typeof(string)) .Property("Name", typeof(string)) .Property("Address", typeof(string)) .Build(); var dict = new Dictionary { ["Name"] = "张三", - ["Id"] = 1, + ["Id"] = Guid.NewGuid().ToString(), ["Address"] = "北京市" }; var instance = DynamicCompileHelper.CreateObjectByType(type, dict); @@ -58,7 +58,46 @@ namespace FreeSql.Tests.DynamicEntity var instance = DynamicCompileHelper.CreateObjectByType(type, dict); //根据Type生成表 fsql.CodeFirst.SyncStructure(type); + var insertId = fsql.Insert().AsType(type).AppendData(instance).ExecuteIdentity(); + var select = fsql.Select().AsType(type).ToList(); + } + + [Fact] + public void SuperClassTest() + { + Type type = DynamicCompileHelper.DynamicBuilder() + .Class("Roles", new TableAttribute() { Name = "T_Role" }, + new IndexAttribute("Name_Index", "Name", false)) + .SuperClass(typeof(BaseModel)) + .Property("Id", typeof(int), + new ColumnAttribute() { IsPrimary = true, IsIdentity = true, Position = 1 }) + .Property("Name", typeof(string), + new ColumnAttribute() { StringLength = 20, Position = 2 }) + .Build(); + var dict = new Dictionary + { + ["Name"] = "系统管理员", + ["UpdateTime"] = DateTime.Now, + ["UpdatePerson"] = "admin" + }; + var instance = DynamicCompileHelper.CreateObjectByType(type, dict); + //根据Type生成表 + fsql.CodeFirst.SyncStructure(type); fsql.Insert().AsType(type).AppendData(instance).ExecuteAffrows(); } } + public class BaseModel + { + [Column(Position = 99)] + public DateTime UpdateTime + { + get; set; + } + + [Column(Position = 100, StringLength = 20)] + public string UpdatePerson + { + get; set; + } + } } \ No newline at end of file