QueryR 0.1.0
dotnet add package QueryR --version 0.1.0
NuGet\Install-Package QueryR -Version 0.1.0
<PackageReference Include="QueryR" Version="0.1.0" />
paket add QueryR --version 0.1.0
#r "nuget: QueryR, 0.1.0"
// Install QueryR as a Cake Addin #addin nuget:?package=QueryR&version=0.1.0 // Install QueryR as a Cake Tool #tool nuget:?package=QueryR&version=0.1.0
QueryR
QueryR provides a simple interface for executing ad hoc queries against IQueryable<T>
implementations.
This is useful in situations where there is a need to provide end users with the ability to create custom queries without increasing the complexity of the solution.
In practice you will have your own domain query criteria object that collects what you want to query. You will perform a map to the QueryR.Query
object and send it to the IQueryable<T>.Query
method.
If you intend to use QueryR with EntityFrameworkCore, please use QueryR.EntityFrameworkCore.
Basic Functionality Example
var kerbals = new List<Kerbal>
{
new Kerbal { FirstName = "Bob", LastName = "Kerman" },
new Kerbal { FirstName = "Bill", LastName = "Kerman" },
new Kerbal { FirstName = "Jeb", LastName = "Kerman" },
new Kerbal { FirstName = "Val", LastName = "Kerman" },
};
//Note:
var queryResult = kerbals.AsQueryable().Query(new Filter
{
PropertyName = nameof(Kerbal.FirstName),
Operator = FilterOperators.StartsWith,
Value = "B"
}).ToList();
Console.WriteLine($"Filter matched {queryResult.Count} Kerbal(s). They are:");
foreach(var item in queryResult)
{
Console.WriteLine($" - {item.FirstName}");
}
// Expected Output :
// Filter matched 2 Kerbal(s). They are:
// - Bob
// - Bill
QueryR Full Functionality Example
QueryR can perform the following IQueryAction
s.
- Filter - Reduce the amount of records returned by specifying conditions. Does not support "OR", if you need "OR", run a seond query.
- Paging
- Sort
- Sparse Fieldsets - Restrict the fields returned for a specified entity.
var (Count, Items) = kerbals.AsQueryable().Query(new Query
{
Filters = new List<Filter>
{
new Filter
{
PropertyName = nameof(Kerbal.FirstName),
Operator = FilterOperators.Contains,
Value = "l"
},
},
PagingOptions = new PagingOptions
{
PageNumber = 2,
PageSize = 1
},
Sorts = new List<Sort>
{
new Sort
{
IsAscending = false,
PropertyName = nameof(Kerbal.FirstName)
},
},
SparseFields = new List<SparseField>
{
new SparseField
{
EntityName = nameof(Kerbal),
PropertyNames = new List<string> { nameof(Kerbal.FirstName) }
},
}
}).GetCountAndList();
Console.WriteLine($"{Count} Kerbal(s) match filter, {Items.Count} Kerbal(s) returned:");
foreach(var item in queryResult)
{
Console.WriteLine($" - {item.FirstName} {item.LastName} was found.");
}
// Expected output:
// 2 Kerbal(s) match filter, 1 Kerbal(s) returned:
// - Bill was found.
QueryR Filters
QueryR provides the following filters:
- Equal
- GreaterThan
- GreaterThanOrEqual
- LessThan
- LessThanOrEqual
- NotEqual
- Contains
- In
- StartsWith
- EndsWith
- CollectionContains
Extra filters can be defined and used as if they were a part of QueryR. For example, if a string length filter was needed.
We could do
public static class ExtendedFilterOperators
{
public static readonly FilterOperator LengthLessThan = new FilterOperator("llt", nameof(LengthLessThan),
(property, target) => Expression.LessThan(Expression.Property(property, nameof(string.Length)), target));
}
and use it like so
var queryResult = kerbals.AsQueryable().Query(new Filter
{
PropertyName = nameof(Kerbal.FirstName),
Operator = ExtendedFilterOperators.LengthLessThan,
Value = 4
}).ToList();
Console.WriteLine($"Filter matched {queryResult.Count} Kerbal(s). They are:");
foreach(var item in queryResult)
{
Console.WriteLine($" - {item.FirstName}");
}
// Expected Output :
// Filter matched 3 Kerbal(s). They are:
// - Bob
// - Jeb
// - Val
Working Example
For a working example of QueryR in action, check out the ConsoleApp example.
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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on QueryR:
Package | Downloads |
---|---|
QueryR.EntityFrameworkCore
This library simplifies performing queries against EntityFrameworkCore DbSet objects. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Maintenance required for QueryR.EntityFrameworkCore