/// <summary> /// Returns a list of distinct column values that can be used for select filters. /// </summary> /// <param name="column">The column.</param> public virtual IList <string> GetDistinctColumnValues(DataTablesColumn <TEntity, TEntityViewModel> column) { var parameterExp = ExpressionHelper.BuildParameterExpression <TEntity>(); var propertyExp = ExpressionHelper.BuildPropertyExpression(parameterExp, column.PrivatePropertyName); var stringExp = Expression.Call(propertyExp, ExpressionHelper.Object_ToString); var lambda = Expression.Lambda <Func <TEntity, string> >(stringExp, parameterExp); return(GetDistinctColumnValues(lambda)); }
/// <summary> /// Orders the given <see cref="IQueryable{TEntity}"/> by the given <paramref name="propertyName"/>. /// The method will consider the given <paramref name="direction"/> and if the order should be applied /// with <paramref name="caseInsensitive"/> logic. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="query">The query.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="direction">The direction.</param> /// <param name="caseInsensitive">if set to <c>true</c>, the order logic is case insensitive.</param> /// <param name="alreadyOrdered">if set to <c>true</c>, follow-up order logic will be used.</param> internal static IQueryable <TEntity> OrderBy <TEntity>(this IQueryable <TEntity> query, string propertyName, ListSortDirection direction, bool caseInsensitive, bool alreadyOrdered) { var type = typeof(TEntity); var parameterExp = Expression.Parameter(type, "e"); var propertyExp = ExpressionHelper.BuildPropertyExpression(parameterExp, propertyName); Expression exp = propertyExp; if (caseInsensitive && propertyExp.Type == typeof(string)) { exp = Expression.Call(exp, ExpressionHelper.String_ToLower); } var methodName = GetOrderMethodName(direction, alreadyOrdered); var orderByExp = Expression.Lambda(exp, parameterExp); var typeArguments = new Type[] { type, propertyExp.Type }; var resultExpr = Expression.Call(typeof(Queryable), methodName, typeArguments, query.Expression, Expression.Quote(orderByExp)); return(query.Provider.CreateQuery <TEntity>(resultExpr)); }