ReHackt.Linq.AutoMapperExtensions
2.0.0-alpha.2
Draft package removed
dotnet add package ReHackt.Linq.AutoMapperExtensions --version 2.0.0-alpha.2
NuGet\Install-Package ReHackt.Linq.AutoMapperExtensions -Version 2.0.0-alpha.2
<PackageReference Include="ReHackt.Linq.AutoMapperExtensions" Version="2.0.0-alpha.2" />
<PackageVersion Include="ReHackt.Linq.AutoMapperExtensions" Version="2.0.0-alpha.2" />
<PackageReference Include="ReHackt.Linq.AutoMapperExtensions" />
paket add ReHackt.Linq.AutoMapperExtensions --version 2.0.0-alpha.2
#r "nuget: ReHackt.Linq.AutoMapperExtensions, 2.0.0-alpha.2"
#:package ReHackt.Linq.AutoMapperExtensions@2.0.0-alpha.2
#addin nuget:?package=ReHackt.Linq.AutoMapperExtensions&version=2.0.0-alpha.2&prerelease
#tool nuget:?package=ReHackt.Linq.AutoMapperExtensions&version=2.0.0-alpha.2&prerelease
ReHackt.Linq.Extensions
Some useful System.Linq.IQueryable extensions such as filtering, ordering, paging...
Install
Get it on <a href="https://www.nuget.org/packages/ReHackt.Linq.Extensions"><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
orIList.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
OrderBy, OrderByDescending, ThenBy, ThenByDescending
These methods allow you to sort dynamically an input sequence according to a property from each element whose name is taken as a string. OrderBy
and OrderByDescending
can take a variable number of arguments in order to sort the sequence according to several properties in the order of the arguments.
For example
source.OrderBy("Score", "Year", "Title")
Is equivalent to
source
.OrderBy(x => x.Score)
.ThenBy(x => x.Year)
.ThenBy(x => x.Title)
Paging
PageBy
source.PageBy(page, pageSize)
Is syntactic sugar for
source.Skip(((page < 1 ? 1 : page) - 1) * pageSize).Take(pageSize)
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.1
- AutoMapper.Extensions.ExpressionMapping (>= 5.0.0)
- ReHackt.Linq.Extensions (>= 2.0.0-alpha.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|