From 189ed541c9f71e1769c67a0226e3ce4f51b6e2bd Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Sun, 5 Jun 2022 14:48:03 +0800 Subject: [PATCH] =?UTF-8?q?UpdateTable=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=A1=A8=E7=BB=93=E6=9E=84=E5=B9=B6=E5=9C=A8?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E5=88=9D=E5=A7=8B=E5=8C=96=E5=90=8E=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DatabaseDefinitions/SugarDbContext.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Falcon.SugarApi/DatabaseDefinitions/SugarDbContext.cs b/Falcon.SugarApi/DatabaseDefinitions/SugarDbContext.cs index a05dfc6..5f5dbb1 100644 --- a/Falcon.SugarApi/DatabaseDefinitions/SugarDbContext.cs +++ b/Falcon.SugarApi/DatabaseDefinitions/SugarDbContext.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace Falcon.SugarApi.DatabaseDefinitions { @@ -175,6 +176,20 @@ namespace Falcon.SugarApi.DatabaseDefinitions this.UpdateTableStructure(typeof(TableType)); } + /// + /// 升级表架构并在首次建表后插入初始化数据 + /// + /// 初始化表的模型 + /// 表名 + /// 表首次创建后执行的回调 + public void UpdateTable(string tableName, Action callbackWhenInitTable) { + var hasTable = this.DbMaintenance.IsAnyTable(tableName, false); + this.CodeFirst.InitTables(); + if (!hasTable) { + callbackWhenInitTable(this); + } + } + #endregion #region 执行存储过程