using System;
using System.Linq;
using System.Linq.Expressions;
using Abp.Application.Services.Dto;
namespace Abp.Linq.Extensions
{
///
/// Some useful extension methods for .
///
public static class QueryableExtensions
{
///
/// Used for paging. Can be used as an alternative to Skip(...).Take(...) chaining.
///
public static IQueryable PageBy(this IQueryable query, int skipCount, int maxResultCount)
{
if (query == null)
{
throw new ArgumentNullException("query");
}
return query.Skip(skipCount).Take(maxResultCount);
}
///
/// Used for paging with an object.
///
/// Queryable to apply paging
/// An object implements interface
public static IQueryable PageBy(this IQueryable query, IPagedResultRequest pagedResultRequest)
{
return query.PageBy(pagedResultRequest.SkipCount, pagedResultRequest.MaxResultCount);
}
///
/// Filters a by given predicate if given condition is true.
///
/// Queryable to apply filtering
/// A boolean value
/// Predicate to filter the query
/// Filtered or not filtered query based on
public static IQueryable WhereIf(this IQueryable query, bool condition, Expression> predicate)
{
return condition
? query.Where(predicate)
: query;
}
///
/// Filters a by given predicate if given condition is true.
///
/// Queryable to apply filtering
/// A boolean value
/// Predicate to filter the query
/// Filtered or not filtered query based on
public static IQueryable WhereIf(this IQueryable query, bool condition, Expression> predicate)
{
return condition
? query.Where(predicate)
: query;
}
}
}