VOOZH about

URL: https://www.nuget.org/packages/LinqBuilder/

⇱ NuGet Gallery | LinqBuilder 4.0.0




LinqBuilder 4.0.0

dotnet add package LinqBuilder --version 4.0.0
 
 
NuGet\Install-Package LinqBuilder -Version 4.0.0
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LinqBuilder" Version="4.0.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinqBuilder" Version="4.0.0" />
 
Directory.Packages.props
<PackageReference Include="LinqBuilder" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LinqBuilder --version 4.0.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LinqBuilder, 4.0.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LinqBuilder@4.0.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LinqBuilder&version=4.0.0
 
Install as a Cake Addin
#tool nuget:?package=LinqBuilder&version=4.0.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

LinqBuilder

Table of Contents

  1. LinqBuilder Specifications
  2. LinqBuilder OrderSpecifications

LinqBuilder Specifications

Usage

Specifications can be constructed in three different ways.

By extending Specification:

public class FirstnameIsFoo : Specification<Person>
{
 public override Expression<Func<Person, bool>> AsExpression()
 {
 return person => person.Firstname == "Foo";
 }
}

ISpecification<Person> firstnameIsFoo = new FirstnameIsFoo();

By extending DynamicSpecification:

public class FirstnameIs : DynamicSpecification<Person, string>
{
 public override Expression<Func<Person, bool>> AsExpression()
 {
 return person => person.Firstname == Value;
 }
}

ISpecification<Person> firstnameIsFoo = new FirstnameIs().Set("Foo");

By extending MultiSpecification:

public class FirstnameIsFoo : MultiSpecification<Person, OtherPerson>
{
 public override Expression<Func<Person, bool>> AsExpressionForEntity1()
 {
 return person => person.Firstname == "Foo";
 }

 public override Expression<Func<OtherPerson, bool>> AsExpressionForEntity2()
 {
 return person => person.Firstname == "Foo";
 }
}

ISpecification<Person> firstnameIsFoo = new FirstnameIsFoo(); // First generic is default
ISpecification<Person> firstnameIsFoo = new FirstnameIsFoo().For<Person>();
ISpecification<OtherPerson> firstnameIsFoo = new FirstnameIsFoo().For<OtherPerson>();

By static New method:

ISpecification<Person> firstnameIsFoo = Specification<Person>.New(p => p.Firstname == "Foo");
// Or by alias
ISpecification<Person> firstnameIsFoo = Spec<Person>.New(p => p.Firstname == "Foo");

Example

var collection = new List<Person>() { ... };

ISpecification<Person> firstnameIsFoo = Spec<Person>.New(p => p.Firstname == "Foo");
ISpecification<Person> firstnameIsBar = Spec<Person>.New(p => p.Firstname == "Bar");

ISpecification<Entity> specification = firstnameIsFoo.Or(firstnameIsBar);

var result = collection.ExeSpec(specification).ToList();
// result = Collection items satisfied by specification

The extension ExeSpec allows all types of ISpecification to be executed on IQueryable and IEnumerable.

Methods

ISpecification<Entity> specification = Spec<Entity>.All(
 new SomeSpecification(),
 new SomeOtherSpecification(),
 ...
);

ISpecification<Entity> specification = Spec<Entity>.None(
 new SomeSpecification(),
 new SomeOtherSpecification(),
 ...
);

ISpecification<Entity> specification = Spec<Entity>.Any(
 new SomeSpecification(),
 new SomeOtherSpecification(),
 ...
);

Extensions

ISpecification<TEntity> And<TEntity>(this ISpecification<TEntity> left, ISpecification<TEntity> right);
ISpecification<TEntity> Or<TEntity>(this ISpecification<TEntity> left, ISpecification<TEntity> right);
ISpecification<TEntity> Not<TEntity>(this ISpecification<TEntity> specification);
bool IsSatisfiedBy<TEntity>(this ISpecification<TEntity> specification, TEntity entity);
ISpecification<TEntity> Clone<TEntity>(this ISpecification<TEntity> specification);

LinqBuilder also extends the following extensions to support ISpecification on IQueryable and IEnumerable.

IEnumerable<Entity> collection = collection.Where(specification);
bool result = collection.Any(specification);
bool result = collection.All(specification);
int result = collection.Count(specification);
Entity result = collection.First(specification);
Entity result = collection.FirstOrDefault(specification);
Entity result = collection.Single(specification);
Entity result = collection.SingleOrDefault(specification);

LinqBuilder OrderSpecifications

Usage

Order specifications can be constructed in almost the same way as regular specifications.

By extending OrderSpecification:

public class FirstnameDescending : OrderSpecification<Person, string>
{
 public DescNumberOrderSpecification() : base(Sort.Descending) { }

 public override Expression<Func<Person, string>> AsExpression()
 {
 return person => person.Firstname;
 }
}

ISpecification<Person> firstnameDescending = new FirstnameDescending();

By static New method:

ISpecification<Person> firstnameDescending = OrderSpecification<Person, string>.New(p => p.Firstname, Sort.Descending);
// Or by alias
ISpecification<Person> firstnameDescending = OrderSpec<Person, string>.New(p => p.Firstname, Sort.Descending);

Example

var collection = new List<Person>() { ... };

ISpecification<Person> firstnameDescending = OrderSpec<Person, string>.New(p => p.Firstname, Sort.Descending);
ISpecification<Person> lastnameDescending = OrderSpec<Person, string>.New(p => p.Lastname, Sort.Descending);

ISpecification<Person> specification = firstnameDescending.ThenBy(lastnameDescending);

var result = collection.ExeSpec(specification).ToList();
// result = Collection ordered by descending number, then by other number

Methods

ISpecification<Person> specification = OrderSpec<Person, string>.New(p => p.Firstname)
 .Take(10);

ISpecification<Person> specification = OrderSpec<Person, string>.New(p => p.Firstname)
 .Skip(5);

ISpecification<Person> specification = OrderSpec<Person, string>.New(p => p.Firstname)
 .Paginate(2, 10); // Equals .Skip((2 - 1) * 10).Take(10)

Extensions

IOrderedEnumerable<Entity> collection = collection
 .OrderBy(specification);
 .ThenBy(otherSpecification);

Order specifications can also be chained with regular LinqBuilder specifications.

ISpecification<Person> firstnameIsFoo = Spec<Person>.New(p => p.Firstname == "Foo");
ISpecification<Person> firstnameAscending = OrderSpec<Person, string>.New(p => p.Firstname);

ISpecification<Entity> specification = firstnameIsFoo.OrderBy(firstnameAscending);

Chained OrderSpecification's can also be attatched to a specification later.

ISpecification<Person> firstnameIsFoo = Spec<Person>.New(p => p.Firstname == "Foo");
ISpecification<Person> firstnameAscending = OrderSpec<Person, string>.New(p => p.Firstname);
ISpecification<Person> lastnameAscending = OrderSpec<Person, string>.New(p => p.Firstname);

ISpecification<Person> orderSpecification = firstnameAscending.ThenBy(lastnameAscending);

ISpecification<Person> specification = firstnameIsFoo.UseOrdering(orderSpecification);

The following extensions will help to check what kind of ordering is applied.

ISpecification<Person> firstnameIsFoo = Spec<Person>.New(p => p.Firstname == "Foo");
ISpecification<Person> firstnameAscending = OrderSpec<Person, string>.New(p => p.Firstname);

firstnameIsFoo.IsOrdered(); // Returns false

ISpecification<Person> specification = firstnameIsFoo.OrderBy(firstnameAscending);
specification.IsOrdered(); // Returns true
ISpecification<Person> specification = Spec<Person>.New(p => p.Firstname == "Foo");
specification.HasSkip(); // Returns false

ISpecification<Person> specification = specification.Skip(10);
specification.HasSkip(); // Returns true
ISpecification<Person> specification = Spec<Person>.New(p => p.Firstname == "Foo");
specification.HasTake(); // Returns false

ISpecification<Person> specification = specification.Take(10);
specification.HasTake(); // Returns true
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on LinqBuilder:

Package Downloads
LinqBuilder.EFCore

Entity Framework Core extensions. Enables most async methods to use ISpecification.

LinqBuilder.EF6

Entity Framework 6 extensions. Enables most async methods to use ISpecification.

LinqBuilder.EF6.AutoMapper

Extensions for querying EF 6 with AutoMapper projections.

LinqBuilder.EFCore.AutoMapper

Extensions for querying EF Core with AutoMapper projections.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 675 1/8/2026
3.2.0 13,328 12/30/2024
3.1.0 14,357 5/5/2024
3.0.1 17,916 10/18/2023
3.0.0 328 10/17/2023
2.1.2 43,782 4/14/2022
2.1.1 1,076 4/13/2022
2.1.0 1,071 4/13/2022
2.0.0 1,821 1/19/2021
1.0.1 8,835 11/3/2020
1.0.0 1,088 11/3/2020
0.16.1 50,069 8/29/2019
0.15.0 4,779 12/4/2018
0.14.0 993 12/3/2018
0.13.0 4,727 9/17/2018
0.12.1 1,767 7/18/2018
0.12.0 1,252 7/18/2018
0.11.1 1,255 7/18/2018
0.11.0 1,756 6/24/2018
0.10.0 1,701 6/24/2018
Loading failed