2018-02-11 20:55:29 -05:00
|
|
|
|
using PoweredSoft.DynamicLinq.Fluent;
|
|
|
|
|
using PoweredSoft.DynamicLinq.Helpers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-03-06 20:59:17 -05:00
|
|
|
|
namespace PoweredSoft.DynamicLinq
|
2018-02-11 20:55:29 -05:00
|
|
|
|
{
|
|
|
|
|
public static class QueryableExtensions
|
|
|
|
|
{
|
2018-02-12 04:30:55 -05:00
|
|
|
|
public static IQueryable<T> Where<T>(this IQueryable<T> query, string path, ConditionOperators conditionOperator, object value,
|
2018-03-06 20:56:43 -05:00
|
|
|
|
QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField,
|
|
|
|
|
QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
|
2018-02-11 20:55:29 -05:00
|
|
|
|
{
|
2018-03-06 20:56:43 -05:00
|
|
|
|
query = query.Query(qb => qb.Compare(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision));
|
2018-02-11 20:55:29 -05:00
|
|
|
|
return query;
|
|
|
|
|
}
|
2018-03-07 21:16:15 -05:00
|
|
|
|
|
|
|
|
|
public static IQueryable<T> Where<T>(this IQueryable<T> query, Action<QueryBuilder<T>> callback)
|
|
|
|
|
=> query.Query(callback);
|
2018-02-12 05:18:44 -05:00
|
|
|
|
|
2018-02-11 20:55:29 -05:00
|
|
|
|
public static IQueryable<T> Query<T> (this IQueryable<T> query, Action<QueryBuilder<T>> callback)
|
|
|
|
|
{
|
|
|
|
|
var queryBuilder = new QueryBuilder<T>(query);
|
|
|
|
|
callback(queryBuilder);
|
|
|
|
|
var ret = queryBuilder.Build();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-02-12 05:18:44 -05:00
|
|
|
|
|
2018-02-20 22:21:23 -05:00
|
|
|
|
public static IQueryable<T> Sort<T>(this IQueryable<T> query, string path, QuerySortDirection sortDirection, bool appendSort)
|
2018-02-12 05:18:44 -05:00
|
|
|
|
{
|
|
|
|
|
var qb = new QueryBuilder<T>(query);
|
2018-02-20 22:21:23 -05:00
|
|
|
|
qb.Sort(path, sortDirection, appendSort);
|
2018-02-12 05:18:44 -05:00
|
|
|
|
var ret = qb.Build();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IQueryable<T> OrderBy<T>(this IQueryable<T> query, string path)
|
|
|
|
|
{
|
|
|
|
|
var qb = new QueryBuilder<T>(query);
|
|
|
|
|
qb.OrderBy(path);
|
|
|
|
|
var ret = qb.Build();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IQueryable<T> OrderByDescending<T>(this IQueryable<T> query, string path)
|
|
|
|
|
{
|
|
|
|
|
var qb = new QueryBuilder<T>(query);
|
|
|
|
|
qb.OrderByDescending(path);
|
|
|
|
|
var ret = qb.Build();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IQueryable<T> ThenBy<T>(this IQueryable<T> query, string path)
|
|
|
|
|
{
|
|
|
|
|
var qb = new QueryBuilder<T>(query);
|
|
|
|
|
qb.ThenBy(path);
|
|
|
|
|
var ret = qb.Build();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IQueryable<T> ThenByDescending<T>(this IQueryable<T> query, string path)
|
|
|
|
|
{
|
|
|
|
|
var qb = new QueryBuilder<T>(query);
|
|
|
|
|
qb.ThenByDescending(path);
|
|
|
|
|
var ret = qb.Build();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-03-09 00:22:12 -05:00
|
|
|
|
|
2018-03-08 22:59:18 -05:00
|
|
|
|
public static IQueryable GroupBy<T>(this IQueryable<T> query, string path)
|
2018-03-09 00:22:12 -05:00
|
|
|
|
=> QueryableHelpers.GroupBy(query, typeof(T), path);
|
2018-03-08 22:59:18 -05:00
|
|
|
|
|
|
|
|
|
public static IQueryable GroupBy(this IQueryable query, Type type, string path)
|
2018-03-09 00:22:12 -05:00
|
|
|
|
=> QueryableHelpers.GroupBy(query, type, path);
|
|
|
|
|
|
|
|
|
|
public static IQueryable GroupBy<T>(this IQueryable<T> query, Action<GroupBuilder> callback)
|
|
|
|
|
=> query.GroupBy(typeof(T), callback);
|
|
|
|
|
|
|
|
|
|
public static IQueryable GroupBy(this IQueryable query, Type type, Action<GroupBuilder> callback)
|
2018-03-08 22:59:18 -05:00
|
|
|
|
{
|
2018-03-09 00:22:12 -05:00
|
|
|
|
var groupBuilder = new GroupBuilder();
|
|
|
|
|
callback(groupBuilder);
|
|
|
|
|
if (groupBuilder.Empty)
|
|
|
|
|
throw new Exception("No group specified, please specify at least one group");
|
|
|
|
|
|
|
|
|
|
return QueryableHelpers.GroupBy(query, type, groupBuilder.Parts);
|
2018-03-08 22:59:18 -05:00
|
|
|
|
}
|
2018-02-11 20:55:29 -05:00
|
|
|
|
}
|
|
|
|
|
}
|