diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 957dd5289..942d0e036 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -147,7 +147,7 @@ namespace SqlSugar } public virtual void ExistLogic(EntityInfo entityInfo) { - if (entityInfo.Columns.HasValue()) + if (entityInfo.Columns.HasValue()&&entityInfo.IsDisabledUpdateAll==false) { //Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Multiple primary keys do not support modifications"); @@ -184,10 +184,13 @@ namespace SqlSugar this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item)); isChange = true; } - foreach (var item in dropColumns) + if (entityInfo.IsDisabledDelete) { - this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName); - isChange = true; + foreach (var item in dropColumns) + { + this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName); + isChange = true; + } } foreach (var item in alterColumns) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index ead07bae4..7d14b2fae 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -28,6 +28,8 @@ namespace SqlSugar var sugarTable = (SugarTable)sugarAttributeInfo; result.DbTableName = sugarTable.TableName; result.TableDescription = sugarTable.TableDescription; + result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll; + result.IsDisabledDelete = sugarTable.IsDisabledDelete; } if (this.Context.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService != null) { if (result.DbTableName == null) diff --git a/Src/Asp.Net/SqlSugar/Entities/EntityInfo.cs b/Src/Asp.Net/SqlSugar/Entities/EntityInfo.cs index f3241b098..da330a830 100644 --- a/Src/Asp.Net/SqlSugar/Entities/EntityInfo.cs +++ b/Src/Asp.Net/SqlSugar/Entities/EntityInfo.cs @@ -15,5 +15,7 @@ namespace SqlSugar public string TableDescription { get; set; } public Type Type { get; set; } public List Columns { get; set; } + public bool IsDisabledDelete { get; set; } + public bool IsDisabledUpdateAll { get; set; } } } diff --git a/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index 63c571f66..ee85b110f 100644 --- a/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.Net/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -11,6 +11,9 @@ namespace SqlSugar private SugarTable() { } public string TableName { get; set; } public string TableDescription { get; set; } + public bool IsDisabledDelete { get; set; } + public bool IsDisabledUpdateAll { get; set; } + public SugarTable(string tableName) { this.TableName = tableName; } @@ -19,6 +22,13 @@ namespace SqlSugar this.TableName = tableName; this.TableDescription = tableDescription; } + + public SugarTable(string tableName, string tableDescription,bool isDisabledDelete) + { + this.TableName = tableName; + this.TableDescription = tableDescription; + this.IsDisabledDelete = isDisabledDelete; + } } [AttributeUsage(AttributeTargets.Property , Inherited = true)] public class SugarColumn : Attribute diff --git a/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs b/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs index 59327c3f4..7375061fc 100644 --- a/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs +++ b/Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("5.0.2.6")] -[assembly: AssemblyFileVersion("5.0.2.6")] +[assembly: AssemblyVersion("5.0.2.7")] +[assembly: AssemblyFileVersion("5.0.2.7")] diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs index 57a1c3e02..59f9c8aa6 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/CodeFirst/SqliteCodeFirst.cs @@ -9,7 +9,7 @@ namespace SqlSugar { public override void ExistLogic(EntityInfo entityInfo) { - if (entityInfo.Columns.HasValue()) + if (entityInfo.Columns.HasValue()&&entityInfo.IsDisabledUpdateAll==false) { Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");