ReHackt.Linq 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ReHackt.Linq --version 1.0.1                
NuGet\Install-Package ReHackt.Linq -Version 1.0.1                
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="ReHackt.Linq" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReHackt.Linq --version 1.0.1                
#r "nuget: ReHackt.Linq, 1.0.1"                
#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.
// Install ReHackt.Linq as a Cake Addin
#addin nuget:?package=ReHackt.Linq&version=1.0.1

// Install ReHackt.Linq as a Cake Tool
#tool nuget:?package=ReHackt.Linq&version=1.0.1                

ReHackt.Linq

Some useful System.Linq.IQueryable extensions such as filtering, ordering, paging...

Install

Get it on <a href="https://www.nuget.org/packages/ReHackt.Linq"><img src="https://www.nuget.org/Content/gallery/img/default-package-icon.svg" height=18 style="height:18px;" /> NuGet</a>

QueryableFilter

QueryableFilter<T> allows to dynamically filter an IQueryable<T> with a query string. For example, this can be useful for an API whose clients can filter a collection of entities on any of its properties, or create complex logical queries.

For example

string query = @"Name eq ""Bond"" and (""james"" in Email or (Status in [1, 2] and ""007"" in Codes)) and (Amount lt 1000 or IsEnabled eq false)";

if(QueryableFilter.TryParse(query, out QueryableFilter<Agent> filter) {
    IQueryable<Agent> agents = _agentManager.Agents.Filter(filter);
}
else { /* Handle invalid query */ };

Is equivalent to

IQueryable<Agent> agents = _agentManager.Agents
    .Where(u => u.Name == "Bond"
        && (u.Email.Contains("james")
            || (new int[] { 1, 2 }.Contains(Status) && u.Codes.Contains("007")))
        && (u.Amount < 1000 || u.IsEnabled == false);

Supported in query

  • Boolean operators: and, or
  • Comparison operators: eq, gt, gte, lt, lte, in (string.Contains or IList.Contains)
  • Value types: bool?, DateTimeOffset?, double?, int?, enum, null, string, DateTimeOffset?[], double?[], int?[], string[]
  • Parentheses
  • Property names (nested properties and collection properties supported)

Not yet supported (planned)

  • Boolean operators: not

IQueryable extensions

Filtering

Filter

Filter allows to apply a QueryableFilter<T> to the input sequence using LINQ method syntax.

source.Filter(filter) // filter is a QueryableFilter<T>

Is syntactic sugar for

filter.Apply(source)

This method also allows you to directly filter the input sequence with a query string (implicitly creating a QueryableFilter<T>). Be careful, this can throw an argument exception if the query string is not valid.

source.Filter(filterQuery) // filterQuery is a string

Is syntactic sugar for

QueryableFilter.TryParse(filterQuery, out QueryableFilter<T> filter) ?
    source.Filter(filter) :
    throw new ArgumentException("Invalid filter query", nameof(filterQuery))
WhereIf
source.WhereIf(condition, predicate)

Is syntactic sugar for

condition ? source.Where(predicate) : source

This allows you to keep the LINQ method syntax to apply filters according to a condition that does not depend on the element being tested.

For example

return source
            .Join(...)
            .Where(...)
            .WhereIf(condition1, predicate1)
            .WhereIf(condition2, predicate2)
            .OrderBy(...)
            .Select(...);

Is equivalent to

source = source            
            .Join(...)
            .Where(...);

if(condition1) {
    source = source.Where(predicate1);
} 

if(condition2) {
    source = source.Where(predicate2);
}

return source
            .OrderBy(...)
            .Select(...);

Ordering

// TODO Write documentation of Sort(...)

Paging

PageBy
source.PageBy(page, pageSize)

Is syntactic sugar for

source.Skip(((page < 1 ? 1 : page) - 1) * pageSize).Take(pageSize)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ReHackt.Linq:

Package Downloads
ReHackt.AspNetCore.Abstractions

Package Description

ReHackt.Linq.AutoMapper

Extends ReHackt.Linq with object-object mapping using AutoMapper profiles.

ReHackt.Linq.Benchmarks

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.49 33 11/14/2024
8.0.48 35 11/14/2024
8.0.47 44 11/13/2024
8.0.46 224 10/13/2024
8.0.45 144 10/11/2024
8.0.44 134 10/11/2024
8.0.43 142 10/10/2024
8.0.42 139 10/10/2024
8.0.41 136 10/8/2024
8.0.40 135 10/7/2024
8.0.39 147 10/7/2024
8.0.38 130 10/7/2024
8.0.37 133 10/7/2024
8.0.36 143 10/3/2024
8.0.35 148 10/3/2024
8.0.34 145 10/2/2024
8.0.33 162 10/2/2024
8.0.32 175 9/27/2024
8.0.31 197 9/12/2024
8.0.30 182 9/12/2024
8.0.29 172 9/12/2024
8.0.28 184 9/3/2024
8.0.27 202 8/26/2024
8.0.26 148 8/4/2024
8.0.25 124 8/4/2024
8.0.24 126 8/4/2024
8.0.23 127 8/3/2024
8.0.22 118 8/3/2024
8.0.21 193 7/9/2024
8.0.20 177 7/6/2024
8.0.19 168 7/4/2024
8.0.18 254 6/17/2024
8.0.17 186 6/3/2024
8.0.16 158 6/3/2024
8.0.15 186 5/29/2024
8.0.14 168 5/15/2024
8.0.13 270 4/16/2024
8.0.12 198 4/10/2024
8.0.11 293 3/14/2024
8.0.10 351 2/21/2024
8.0.9 407 2/15/2024
8.0.8 398 2/8/2024
8.0.7 412 2/6/2024
8.0.6 518 1/29/2024
8.0.5 454 1/18/2024
8.0.4 446 1/16/2024
8.0.3 498 1/15/2024
8.0.2 484 1/14/2024
8.0.1 459 1/12/2024
8.0.0 513 12/19/2023
7.3.13 665 11/14/2023
7.3.12 575 11/13/2023
7.3.11 1,060 9/16/2023
7.3.10 697 9/15/2023
7.3.9 848 8/16/2023
7.3.8 892 7/12/2023
7.3.7 812 7/12/2023
7.3.6 798 7/10/2023
7.3.5 879 7/3/2023
7.3.4 970 6/8/2023
7.3.3 995 5/29/2023
7.3.2 1,108 4/27/2023
7.3.1 1,012 4/27/2023
7.3.0 1,016 4/17/2023
7.2.1 1,006 4/7/2023
7.2.0 1,010 4/6/2023
7.1.4 1,055 3/30/2023
7.1.3 1,012 3/29/2023
7.1.2 1,076 3/29/2023
7.1.0 1,230 3/28/2023
7.0.1 2,225 2/1/2023
7.0.0 1,537 12/2/2022
1.1.2 5,075 6/23/2022
1.1.1 2,211 6/23/2022
1.1.0 2,854 6/9/2022
1.0.9 1,800 6/9/2022
1.0.8 1,897 6/8/2022
1.0.7 3,273 5/13/2022
1.0.6 2,104 5/5/2022
1.0.5 5,951 4/8/2022
1.0.4 2,754 3/23/2022
1.0.3 2,791 3/9/2022
1.0.2 1,282 3/7/2022
1.0.1 1,326 3/7/2022
1.0.0 1,525 2/27/2022
1.0.0-alpha.14 142 2/24/2022
1.0.0-alpha.13 132 2/24/2022
1.0.0-alpha.12 131 2/24/2022
1.0.0-alpha.11 190 2/21/2022