diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs index 3d0acb158..03db7a8ff 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -1229,6 +1229,30 @@ namespace SqlSugar #region Other + private void orderPropertyNameByJoin(string orderPropertyName, OrderByType? orderByType) + { + var shortName = orderPropertyName.Split('.').FirstOrDefault(); + orderPropertyName = orderPropertyName.Split('.').Last(); + var entityType = this.QueryBuilder.JoinQueryInfos.FirstOrDefault(it => it.ShortName.EqualCase(shortName))?.EntityType; + if (entityType == null) + { + entityType=this.EntityInfo.Type; + } + if (this.Context.EntityMaintenance.GetEntityInfoWithAttr(entityType).Columns.Any(it => + it.DbColumnName?.EqualCase(orderPropertyName) == true + || it.PropertyName?.EqualCase(orderPropertyName) == true)) + { + var name = this.Context.EntityMaintenance.GetEntityInfoWithAttr(entityType).Columns.FirstOrDefault(it => + it.DbColumnName?.EqualCase(orderPropertyName) == true + || it.PropertyName?.EqualCase(orderPropertyName) == true)?.DbColumnName; + this.OrderBy(this.SqlBuilder.GetTranslationColumnName(shortName)+"."+this.SqlBuilder.GetTranslationColumnName(name) + " " + orderByType); + } + else + { + Check.ExceptionEasy($"OrderByPropertyName error.{orderPropertyName} does not exist in the entity class", $"OrderByPropertyName出错实体类中不存在{orderPropertyName}"); + } + } + private void OutIntoTableSql(string TableName, out KeyValuePair> sqlInfo, out string sql,Type tableInfo) { var columnList = this.Context.EntityMaintenance.GetEntityInfo(tableInfo).Columns; diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index fba86509b..b21a64cea 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -1088,6 +1088,11 @@ namespace SqlSugar } return this; } + if (this.QueryBuilder.IsSingle() == false && orderPropertyName.Contains(".")) + { + orderPropertyNameByJoin(orderPropertyName, orderByType); + return this; + } if (this.Context.EntityMaintenance.GetEntityInfoWithAttr(typeof(T)).Columns.Any(it => it.DbColumnName?.EqualCase(orderPropertyName)==true || it.PropertyName?.EqualCase(orderPropertyName)==true)) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs index 765b8cf83..3e6b95209 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs @@ -16,6 +16,11 @@ namespace SqlSugar #region T2 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public new ISugarQueryable SampleBy(int timeNumber, SampleByUnit timeType) { base.SampleBy(timeNumber, timeType); @@ -643,6 +648,11 @@ namespace SqlSugar #region T3 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public new ISugarQueryable SampleBy(int timeNumber, SampleByUnit timeType) { base.SampleBy(timeNumber, timeType); @@ -1376,6 +1386,11 @@ namespace SqlSugar #region T4 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public new ISugarQueryable SampleBy(int timeNumber, SampleByUnit timeType) { base.SampleBy(timeNumber, timeType); @@ -2130,6 +2145,11 @@ namespace SqlSugar #region T5 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public new ISugarQueryable SampleBy(int timeNumber, SampleByUnit timeType) { base.SampleBy(timeNumber, timeType); diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs index 4acfaec6f..ba80db455 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs @@ -15,6 +15,11 @@ namespace SqlSugar #region T6 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); @@ -732,6 +737,11 @@ namespace SqlSugar #region T7 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); @@ -1451,6 +1461,11 @@ namespace SqlSugar #region T8 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); @@ -2170,6 +2185,11 @@ namespace SqlSugar #region T9 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); @@ -2849,6 +2869,11 @@ namespace SqlSugar #region T10 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs index 728b394ad..15279d7f1 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs @@ -15,6 +15,11 @@ namespace SqlSugar #region T11 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); @@ -727,6 +732,11 @@ namespace SqlSugar #region T12 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { + public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) + { + base.OrderByPropertyName(orderPropertyName, orderByType); + return this; + } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); diff --git a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs index 2015a9951..24deac413 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs @@ -328,6 +328,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); new ISugarQueryable OrderBy(string orderFileds); @@ -452,6 +453,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); @@ -592,6 +594,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); @@ -739,6 +742,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); @@ -873,6 +877,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); @@ -1016,6 +1021,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); @@ -1153,6 +1159,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); ISugarQueryable OrderByDescending(Expression> expression); @@ -1285,6 +1292,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderBy(string orderFileds); new ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); @@ -1411,6 +1419,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderBy(string orderFileds); new ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); @@ -1545,6 +1554,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderBy(string orderFileds); new ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); @@ -1669,6 +1679,7 @@ namespace SqlSugar #endregion #region OrderBy + new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null); new ISugarQueryable OrderBy(string orderFileds); new ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc); ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc);