Browse Source

Add OrderByPropertyName

pull/40/head
sunkaixuan 1 year ago
parent
commit
d089c14ec5
  1. 20
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

20
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -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();

1
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -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);

Loading…
Cancel
Save