mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Add OrderByPropertyName
This commit is contained in:
@@ -1044,6 +1044,26 @@ namespace SqlSugar
|
||||
this.QueryBuilder.SampleBy = sql;
|
||||
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)
|
||||
{
|
||||
orderFileds = orderFileds.ToCheckField();
|
||||
|
@@ -105,6 +105,7 @@ namespace SqlSugar
|
||||
ISugarQueryable<T> InIF<FieldType>(bool isWhere,Expression<Func<T, object>> expression, ISugarQueryable<FieldType> childQueryExpression);
|
||||
|
||||
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> OrderByDescending(Expression<Func<T, object>> expression);
|
||||
ISugarQueryable<T> OrderByIF(bool isOrderBy, string orderFileds);
|
||||
|
Reference in New Issue
Block a user