Skip
The Skip
feature in specifications behaves the same as LINQ’s Skip
method. It accepts an int count
parameter and skips the specified number of elements from the beginning of the query result.
public class CustomerSpec : Specification<Customer>
{
public CustomerSpec(int skip)
{
Query.Skip(skip);
}
}
Skip
is typically used together with Take to implement pagination but can also be used independently when needed.
public class CustomerSpec : Specification<Customer>
{
public CustomerSpec(PagingFilter filter)
{
Query.Skip(filter.Skip)
.Take(filter.Take);
}
}
Conditional Overloads
The Skip
method provides an overload that accepts a bool condition
. If the condition evaluates to false, the skip operation is not applied. This is useful for dynamic scenarios, such as optional paging.
public class CustomerSpec : Specification<Customer>
{
public CustomerSpec(PagingFilter filter)
{
Query.Skip(filter.Skip, filter.Skip > 0)
.Take(filter.Take, filter.Take > 0);
}
}