Add OrderByPropertyName

This commit is contained in:
sunkaixuan
2023-07-03 18:28:45 +08:00
parent b5356e0284
commit d089c14ec5
2 changed files with 21 additions and 0 deletions

View File

@@ -1044,6 +1044,26 @@ namespace SqlSugar
this.QueryBuilder.SampleBy = sql; this.QueryBuilder.SampleBy = sql;
return this; return this;
} }
public ISugarQueryable<T> OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null)
{
if (orderPropertyName != null)
{
if (this.Context.EntityMaintenance.GetEntityInfoWithAttr(typeof(T)).Columns.Any(it =>
it.DbColumnName?.EqualCase(orderPropertyName)==true
|| it.PropertyName?.EqualCase(orderPropertyName)==true))
{
var name = this.Context.EntityMaintenance.GetEntityInfoWithAttr(typeof(T)).Columns.FirstOrDefault(it =>
it.DbColumnName?.EqualCase(orderPropertyName) == true
|| it.PropertyName?.EqualCase(orderPropertyName) == true)?.DbColumnName;
return this.OrderBy(this.SqlBuilder.GetTranslationColumnName( name) + " "+orderByType);
}
else
{
Check.ExceptionEasy($"OrderByPropertyName error.{orderPropertyName} does not exist in the entity class", $"OrderByPropertyName出错实体类中不存在{orderPropertyName}");
}
}
return this;
}
public virtual ISugarQueryable<T> OrderBy(string orderFileds) public virtual ISugarQueryable<T> OrderBy(string orderFileds)
{ {
orderFileds = orderFileds.ToCheckField(); orderFileds = orderFileds.ToCheckField();

View File

@@ -105,6 +105,7 @@ namespace SqlSugar
ISugarQueryable<T> InIF<FieldType>(bool isWhere,Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression); ISugarQueryable<T> InIF<FieldType>(bool isWhere,Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
ISugarQueryable<T> OrderBy(string orderFileds); ISugarQueryable<T> OrderBy(string orderFileds);
ISugarQueryable<T> OrderByPropertyName(string orderPropertyName,OrderByType? orderByType=null);
ISugarQueryable<T> OrderBy(Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc); ISugarQueryable<T> OrderBy(Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc);
ISugarQueryable<T> OrderByDescending(Expression<Func<T, object>> expression); ISugarQueryable<T> OrderByDescending(Expression<Func<T, object>> expression);
ISugarQueryable<T> OrderByIF(bool isOrderBy, string orderFileds); ISugarQueryable<T> OrderByIF(bool isOrderBy, string orderFileds);