diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 4f70dbf7f..019a51604 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -263,6 +263,10 @@ namespace SqlSugar DbColumnInfo dbColumnInfo = EntityColumnToDbColumn(entityInfo, tableName, item); columns.Add(dbColumnInfo); } + if (entityInfo.IsCreateTableFiledSort) + { + columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList(); + } } this.Context.DbMaintenance.CreateTable(tableName, columns, true); } @@ -433,7 +437,8 @@ namespace SqlSugar DefaultValue = item.DefaultValue, ColumnDescription = item.ColumnDescription, Length = item.Length, - DecimalDigits = item.DecimalDigits + DecimalDigits = item.DecimalDigits, + CreateTableFieldSort = item.CreateTableFieldSort }; GetDbType(item, propertyType, result); return result; diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs index 39c861763..1c1519acb 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/EntityMaintenance/EntityMaintenance.cs @@ -36,6 +36,7 @@ namespace SqlSugar result.TableDescription = sugarTable.TableDescription.ToSqlFilter(); result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll; result.IsDisabledDelete = sugarTable.IsDisabledDelete; + result.IsCreateTableFiledSort = sugarTable.IsCreateTableFiledSort; } var indexs = type.GetCustomAttributes(typeof(SugarIndexAttribute)); if (indexs != null && indexs.Any()) @@ -284,7 +285,7 @@ namespace SqlSugar column.IsArray = sugarColumn.IsArray; column.IsTreeKey = sugarColumn.IsTreeKey; column.SqlParameterDbType = sugarColumn.SqlParameterDbType; - + column.CreateTableFieldSort = sugarColumn.CreateTableFieldSort; if (sugarColumn.IsJson && String.IsNullOrEmpty(sugarColumn.ColumnDataType)) { if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL) diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/DbColumnInfo.cs b/Src/Asp.NetCore2/SqlSugar/Entities/DbColumnInfo.cs index 3bfff1ac9..9cc178a0c 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/DbColumnInfo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/DbColumnInfo.cs @@ -24,5 +24,6 @@ namespace SqlSugar public bool IsArray { get; set; } internal bool IsJson { get; set; } public bool? IsUnsigned { get; set; } + public int CreateTableFieldSort { get; set; } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/EntityColumnInfo.cs b/Src/Asp.NetCore2/SqlSugar/Entities/EntityColumnInfo.cs index 6f6627677..c8b9d7647 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/EntityColumnInfo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/EntityColumnInfo.cs @@ -39,5 +39,6 @@ namespace SqlSugar public bool IsArray { get; set; } public Type UnderType { get; set; } public Navigate Navigat { get; set; } + public int CreateTableFieldSort { get; set; } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs b/Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs index 9632d0095..46833ac66 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs @@ -18,5 +18,6 @@ namespace SqlSugar public bool IsDisabledDelete { get; set; } public bool IsDisabledUpdateAll { get; set; } public List Indexs { get; set; } + public bool IsCreateTableFiledSort { get; set; } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index cede16684..85d85b1b1 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -13,7 +13,7 @@ namespace SqlSugar public string TableDescription { get; set; } public bool IsDisabledDelete { get; set; } public bool IsDisabledUpdateAll { get; set; } - + public bool IsCreateTableFiledSort { get; set; } public SugarTable(string tableName) { this.TableName = tableName; } @@ -29,6 +29,13 @@ namespace SqlSugar this.TableDescription = tableDescription; this.IsDisabledDelete = isDisabledDelete; } + public SugarTable(string tableName, string tableDescription, bool isDisabledDelete, bool isCreateTableFieldSort) + { + this.TableName = tableName; + this.TableDescription = tableDescription; + this.IsDisabledDelete = isDisabledDelete; + this.IsCreateTableFiledSort = isCreateTableFieldSort; + } } [AttributeUsage(AttributeTargets.Property , Inherited = true)] public class SugarColumn : Attribute @@ -198,6 +205,7 @@ namespace SqlSugar } public object SqlParameterDbType { get; set; } + public int CreateTableFieldSort { get; set; } }