Specifications
Structr.Specifications package provides .NET implementation of Specification pattern with set of simple operations with them.
Installation
Specifications package is available on NuGet.
Usage
Main class of package - Specification<T>
- should be inherited by your own classes in order to use its functionality and extensions.
Example of basic usage:
Use specifications to filter models collection:
The whole list of Specification<T>
extensions is provided below:
And<T>
Creates specification which will be satisfied only when both specifications will be satisfied by provided instance of type T
.
Or<T>
Creates specification which will be satisfied when at least one two specifications will be satisfied by provided instance of type T
.
Not<T>
Creates specification which will be satisfied when given specification won't be satisfied by provided instance of type T
.
AndNot<T>
Creates specification which will be satisfied when first specification will AND second will not be satisfied by provided instance of T
.
OrNot<T>
Creates specification which will be satisfied when first specification will OR second will not be satisfied by provided instance of T
.
Additionally two predefined specifications are available:
AnySpecification<T>
Specification to which all objects of T
will match.
NoneSpecification<T>
Specification to which none of objects of T
will match.
Entity Framework
Structr.Specifications may be helpful with Entity Framework 6 or Entity Framework Core. Use ToExpression()
method with Where()
for filtering entities in DbContext
:
Last updated