Update CodeFirst

This commit is contained in:
skx
2021-02-11 18:03:38 +08:00
parent 9f40c93c4e
commit d858510bc2
6 changed files with 24 additions and 7 deletions

View File

@@ -147,7 +147,7 @@ namespace SqlSugar
} }
public virtual void ExistLogic(EntityInfo entityInfo) 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"); //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)); this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
isChange = true; isChange = true;
} }
foreach (var item in dropColumns) if (entityInfo.IsDisabledDelete)
{ {
this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName); foreach (var item in dropColumns)
isChange = true; {
this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName);
isChange = true;
}
} }
foreach (var item in alterColumns) foreach (var item in alterColumns)
{ {

View File

@@ -28,6 +28,8 @@ namespace SqlSugar
var sugarTable = (SugarTable)sugarAttributeInfo; var sugarTable = (SugarTable)sugarAttributeInfo;
result.DbTableName = sugarTable.TableName; result.DbTableName = sugarTable.TableName;
result.TableDescription = sugarTable.TableDescription; 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 (this.Context.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService != null) {
if (result.DbTableName == null) if (result.DbTableName == null)

View File

@@ -15,5 +15,7 @@ namespace SqlSugar
public string TableDescription { get; set; } public string TableDescription { get; set; }
public Type Type { get; set; } public Type Type { get; set; }
public List<EntityColumnInfo> Columns { get; set; } public List<EntityColumnInfo> Columns { get; set; }
public bool IsDisabledDelete { get; set; }
public bool IsDisabledUpdateAll { get; set; }
} }
} }

View File

@@ -11,6 +11,9 @@ namespace SqlSugar
private SugarTable() { } private SugarTable() { }
public string TableName { get; set; } public string TableName { get; set; }
public string TableDescription { get; set; } public string TableDescription { get; set; }
public bool IsDisabledDelete { get; set; }
public bool IsDisabledUpdateAll { get; set; }
public SugarTable(string tableName) { public SugarTable(string tableName) {
this.TableName = tableName; this.TableName = tableName;
} }
@@ -19,6 +22,13 @@ namespace SqlSugar
this.TableName = tableName; this.TableName = tableName;
this.TableDescription = tableDescription; 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)] [AttributeUsage(AttributeTargets.Property , Inherited = true)]
public class SugarColumn : Attribute public class SugarColumn : Attribute

View File

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.0.2.6")] [assembly: AssemblyVersion("5.0.2.7")]
[assembly: AssemblyFileVersion("5.0.2.6")] [assembly: AssemblyFileVersion("5.0.2.7")]

View File

@@ -9,7 +9,7 @@ namespace SqlSugar
{ {
public override void ExistLogic(EntityInfo entityInfo) 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"); Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");