From a3c786d5b82e89464b7d8b1cd7444ed60679b7fe Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 1 Jul 2023 09:27:35 +0800 Subject: [PATCH] Update sqlServer default value --- .../DbMaintenance/SqlServerDbMaintenance.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs index 3a082a8c5..eb521edd2 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs @@ -321,6 +321,23 @@ namespace SqlSugar #endregion #region Methods + public override void AddDefaultValue(EntityInfo entityInfo) + { + var dbColumns = this.GetColumnInfosByTableName(entityInfo.DbTableName, false); + var db = this.Context; + var columns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList(); + foreach (var item in columns) + { + if (item.DefaultValue.HasValue() || (item.DefaultValue == "" && item.UnderType == UtilConstants.StringType)) + { + if (!IsAnyDefaultValue(entityInfo.DbTableName, item.DbColumnName, dbColumns)) + { + this.AddDefaultValue(entityInfo.DbTableName, item.DbColumnName, item.DefaultValue); + } + } + } + } + public override List GetIndexList(string tableName) { return this.Context.Ado.SqlQuery($"SELECT indexname = i.name FROM sys.indexes i\r\nJOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id\r\nJOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id\r\nWHERE i.object_id = OBJECT_ID('{tableName}')");