From 4c76c2e5944e2d8982f067501fb6bb251d8db3d6 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 29 Sep 2022 19:55:27 +0800 Subject: [PATCH] Update demo --- Src/Asp.Net/DmTest/Config.cs | 2 +- Src/Asp.Net/DmTest/Demo/DemoE_CodeFirst.cs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/DmTest/Config.cs b/Src/Asp.Net/DmTest/Config.cs index 8ac3b3329..02dcd11f8 100644 --- a/Src/Asp.Net/DmTest/Config.cs +++ b/Src/Asp.Net/DmTest/Config.cs @@ -15,7 +15,7 @@ namespace OrmTest /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString = "Server=120.79.19.7:10374;User Id=SYSDBA;PWD=Ldkie#21;DATABASE=DAMENG"; + public static string ConnectionString = "Server=116.242.92.57:5511;User Id=S;PWD=S0718;DATABASE=DAMENG"; /// /// Account have permission to create database /// 用有建库权限的数据库账号 diff --git a/Src/Asp.Net/DmTest/Demo/DemoE_CodeFirst.cs b/Src/Asp.Net/DmTest/Demo/DemoE_CodeFirst.cs index cea14d83b..9f32b60f2 100644 --- a/Src/Asp.Net/DmTest/Demo/DemoE_CodeFirst.cs +++ b/Src/Asp.Net/DmTest/Demo/DemoE_CodeFirst.cs @@ -17,16 +17,35 @@ namespace OrmTest DbType = DbType.Dm, ConnectionString = Config.ConnectionString3, InitKeyType = InitKeyType.Attribute, - IsAutoCloseConnection = true + IsAutoCloseConnection = true, + AopEvents = new AopEvents + { + OnLogExecuting = (sql, p) => + { + Console.WriteLine(sql); + Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value))); + } + } }); // db.DbMaintenance.CreateDatabase(); + if (db.DbMaintenance.IsAnyTable("CodeFirstTable1", false)) + db.DbMaintenance.DropTable("CodeFirstTable1"); + if (db.DbMaintenance.IsAnyTable("CodeFirstLong", false)) + db.DbMaintenance.DropTable("CodeFirstLong"); db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1 db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand(); var list = db.Queryable().ToList(); + db.CodeFirst.InitTables(); + var tableInfo=db.DbMaintenance.GetColumnInfosByTableName("CodeFirstLong", false); Console.WriteLine("#### CodeFirst end ####"); } } + public class CodeFirstLong + { + [SugarColumn(IsPrimaryKey =true,IsIdentity =true)] + public long id { get; set; } + } public class CodeFirstTable1 { [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]