From 9afa6f853b7240d1a7ce48748a1b616025285b02 Mon Sep 17 00:00:00 2001 From: apgk Date: Thu, 14 Jul 2022 09:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B1=E4=BA=8E=E9=A1=B9=E7=9B=AE=E9=9C=80?= =?UTF-8?q?=E6=B1=82=EF=BC=8C=E9=83=A8=E7=BD=B2=E6=96=B0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E9=87=87=E7=94=A8codefirst=20,=E8=B7=9F=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE=E7=9A=84=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E8=A1=A8=E7=BB=93=E6=9E=84=E9=A1=BA=E5=BA=8F=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E9=80=A0=E6=88=90=E5=86=99=E5=85=A5=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E3=80=82=E6=89=80=E4=BB=A5=E5=8A=A0=E4=BA=86=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E9=A1=BA=E5=BA=8F=E7=94=9F=E6=88=90=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Abstract/CodeFirstProvider/CodeFirstProvider.cs | 7 ++++++- .../Abstract/EntityMaintenance/EntityMaintenance.cs | 3 ++- Src/Asp.NetCore2/SqlSugar/Entities/DbColumnInfo.cs | 1 + Src/Asp.NetCore2/SqlSugar/Entities/EntityColumnInfo.cs | 1 + Src/Asp.NetCore2/SqlSugar/Entities/EntityInfo.cs | 1 + .../SqlSugar/Entities/Mapping/SugarMappingAttribute.cs | 10 +++++++++- 6 files changed, 20 insertions(+), 3 deletions(-) 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; } }