UpdateTable方法支持升级表结构并在首次初始化后插入初始化数据

This commit is contained in:
falcon 2022-06-05 14:48:03 +08:00
parent df23896b4d
commit 189ed541c9

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
namespace Falcon.SugarApi.DatabaseDefinitions namespace Falcon.SugarApi.DatabaseDefinitions
{ {
@ -175,6 +176,20 @@ namespace Falcon.SugarApi.DatabaseDefinitions
this.UpdateTableStructure(typeof(TableType)); this.UpdateTableStructure(typeof(TableType));
} }
/// <summary>
/// 升级表架构并在首次建表后插入初始化数据
/// </summary>
/// <typeparam name="TTable">初始化表的模型</typeparam>
/// <param name="tableName">表名</param>
/// <param name="callbackWhenInitTable">表首次创建后执行的回调</param>
public void UpdateTable<TTable>(string tableName, Action<SugarDbContext> callbackWhenInitTable) {
var hasTable = this.DbMaintenance.IsAnyTable(tableName, false);
this.CodeFirst.InitTables<TTable>();
if (!hasTable) {
callbackWhenInitTable(this);
}
}
#endregion #endregion
#region #region