I am using Repository pattern and i have a base repository and i use Entity Framework and web api; my question is I want to allow my clients to be able to query any data dynamically; something like query expressions and fetch xml used in Dynamics CRM; I tried specification pattern but it isn't enough as i want to allow client code to order data with different columns e.g. Name asc Address desc and also, allow pagination on the returned result;so my method requirements are
- Generic Filter that doesn't depend on ORM technology as i may change Entity Framework in the future
- Generic Sorting methodology; allow multiple sort columns e.g. Name asc Address desc
- The Client determine the returned columns or all columns e.g. columnSet to be "Address, Name and Id" or returned the entire record
- Allow Pagination e.g. Page Index and Page Size
- Support threshold on the number of returned records as large result may affect performance
this is my initial method but i don't know if it is better or not
IList<TEntity> AllMatching(ISpecification<TEntity> specification = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
IList<Expression<Func<TEntity, object>>> includes = null,
int? pageIndex = null, int? pageCount = null);