romaklayt.DynamicFilter.Extensions.Async
1.7.2
See the version list below for details.
dotnet add package romaklayt.DynamicFilter.Extensions.Async --version 1.7.2
NuGet\Install-Package romaklayt.DynamicFilter.Extensions.Async -Version 1.7.2
<PackageReference Include="romaklayt.DynamicFilter.Extensions.Async" Version="1.7.2" />
paket add romaklayt.DynamicFilter.Extensions.Async --version 1.7.2
#r "nuget: romaklayt.DynamicFilter.Extensions.Async, 1.7.2"
// Install romaklayt.DynamicFilter.Extensions.Async as a Cake Addin #addin nuget:?package=romaklayt.DynamicFilter.Extensions.Async&version=1.7.2 // Install romaklayt.DynamicFilter.Extensions.Async as a Cake Tool #tool nuget:?package=romaklayt.DynamicFilter.Extensions.Async&version=1.7.2
romaklayt.DynamicFilter
Simple filter for .net WebApi that enables your endpoint to query your requests by url.
It provides ways to query, order and page your webapi and mvc.
.Net Core and .Net
First, download the packages into your project from nuget
nuget install romaklayt.DynamicFilter.Extensions
nuget install romaklayt.DynamicFilter.Binder.Net
and, if you need, add to your ConfigureServices Startup.cs class for register value provider (JSON) for body JSON POST request support (providers for form-data, x-www-form-urlencoded work them by default)
services.AddControllers(options => options.ValueProviderFactories.Add(new JsonBodyValueProviderFactory()));
.Net Framework (>=4.6.1)
First, download the packages into your project from nuget
nuget install romaklayt.DynamicFilter.Extensions
If you need to add a filter to the web api controller use the package
nuget install romaklayt.DynamicFilter.Binder.NetFramework.WebApi
and, if you need, add to your WebApiConfig class for register value providers (form-data, x-www-form-urlencoded and JSON) for body POST request
config.AddDynamicFilterProviders();
If you need to add a filter to the MVC controller use the package
nuget install romaklayt.DynamicFilter.Binder.NetFramework.Mvc
and, if you need, add to your Application_Start Global.asax.cs class for register value providers (form-data, x-www-form-urlencoded and JSON) for body POST request
DynamicFilterProviders.AddProviders();
If you need to use DynamicFilter with IAsyncEnumerable or IAsyncQueryable use the package
nuget install romaklayt.DynamicFilter.Extensions.Async
After downloaded, go to your webapi and create an get or post endpoint receiving DynamicComplexModel
as parameter.
[HttpGet]
public Task<List<User>> Get(DynamicComplexModel filter)
Now you can query your endpoint with the DynamicFilter properties. Check "tests" folder on the Api projects for examples.
[HttpGet]
public Task<List<User>> Get(DynamicComplexModel filter)
{
var result = this.users.UseFilter(filter);
return Task.FromResult(result.ToList());
}
DynamicFilter.Parser will transform your URI Queries into .Net Expressions. That way, you can use these expressions to filter your values into your database repository.
Simple Query
You can use a DynamicComplexModel model for filtering. A DynamicFilterModel model without additional properties is also available.
public Task<List<User>> Get(DynamicComplexModel filter) #or DynamicFilterModel
{
var result = users.UseFilter(filter);
return Task.FromResult(result.ToList());
}
Example Uri:
GET http://url?query=name=Bruno
Expression generated by Uri:
x => x.Name == "Bruno"
Filters are also supported for nested collections.
GET http://url?query=roles.name=admin
Your request will be converted to:
users.Where(x => x.Roles.Any(y => y.Name == "admin"))
Complex Query
Example Uri:
GET http://url?query=name=Bruno,lastname%r,age>=27
Expression generated by Uri:
x => x.Name == "Bruno"
&& x.LastName.ToLower().Contains("r")
&& x.Age >= 27
You can add conditions to your query sorting your filters with a comma (,), as shown above.
Nested Query
Example Uri:
GET http://url?query=address.number=23
Expression generated by Uri:
x => x.Address.Number == 23
Ordering
You can also order your queries via DynamicFilter. You simply need to add an order parameter on your query, where you specify the property you'll use for order.
GET http://url?query=name=Bruno&order=name
Default order type is Ascending. You can specify the order type with an equals (=) Asc or Desc after the property.
GET http://url?query=name=Bruno&order=name=Asc
GET http://url?query=name=Bruno&order=name=Desc
To sort by multiple properties:
GET http://url?query=name=Bruno&order=name=asc,firstname=asc
GET http://url?query=name=Bruno&order=name=desc,firstname
If you do not specify the sort type, asc is used by default.
On your DynamicFilter object received on the endpoint, you'll get the orderType as an Enum, this way you can order by the type specified on enum.
public Task<List<User>> Get(DynamicComplexModel filter)
{
var result = users.UseFilter(filter);
return Task.FromResult(result.ToList());
}
Pagging
GET http://url?query=name%b&order=name&page=1&pagesize=10
In romaklayt.DynamicFilter.Extensions and romaklayt.DynamicFilter.Extensions.Async there is a method of expanding the ToPagedList which returns PageModel with info about page and your filtered data.
var page = users.ToPagedList(filterModel);
If you no need page info, you simply needs to add the parameters page and pagesize on your get request.
result = result.UseFilter(filter); #page mode without info
If you specify the page number and size in the filter model, pagination is disabled when using UseFilter. You can also disable pagination by forcibly calling:
result = result.UseFilter(filter, false); #only filtering without pagination
Example:
[HttpGet("page")]
public async Task<PageModel<User>> GetPage(DynamicComplexModel filterModel)
{
var filteredUsers = await Data.Users.UseFilter(filterModel);
return await filteredUsers.ToPagedList(filterModel);
}
Select
To select, you simply needs to add the parameter select with the properties you want to select from. It will render either an linq select and a plain string select.
GET http://url?select=name,age
If you select a nested property, from default, the properties from the root model will be ignored, to select all the root properties, use the word root.
GET http://url?select=address.zip,root #select Address.Zip and all root properties
If you don't want to send model properties that are not included in your Select request, you can use the GetOnlySelectedProperties extension method, which will render you only the selected properties. Example:
result = items.UseFilter(filter).Result.GetOnlySelectedProperties(filterModelModel);
If you need to select properties from only one model (the GetById method, for example), you can also use the method UseFilter.
[HttpGet("{id}")]
public async Task<object> GetById(DynamicSelectModel dynamicSelectModel, Guid id)
{
var user = await Data.Users.UseSelect(dynamicSelectModel).FirstOrDefaultAsync(user => user.Id == id);
return user.RenderOnlySelectedProperties(dynamicSelectModel);
}
Filter operator support
- Equals (=)
GET http://url?query=name=Bruno
- Contains Invariant Case (%)
GET http://url?query=name%b
- Contains Case Sensitive (%%)
GET http://url?query=name%%B
- GreaterThan (>)
GET http://url?query=age>15
- GreaterOrEqual (>=)
GET http://url?query=age>=15
- LessThan (<)
GET http://url?query=age<15
- LessOrEqual (<=)
GET http://url?query=age<=15
- NotEquals (!=)
GET http://url?query=age!=15
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 is compatible. |
.NET Framework | net461 is compatible. 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. |
-
.NETFramework 4.6.1
- Microsoft.Bcl.AsyncInterfaces (>= 6.0.0)
- romaklayt.DynamicFilter.Parser (>= 1.7.2)
- System.Linq.Async (>= 5.1.0)
- System.Linq.Async.Queryable (>= 5.1.0)
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 6.0.0)
- romaklayt.DynamicFilter.Parser (>= 1.7.2)
- System.Linq.Async (>= 5.1.0)
- System.Linq.Async.Queryable (>= 5.1.0)
-
.NETStandard 2.1
- Microsoft.Bcl.AsyncInterfaces (>= 6.0.0)
- romaklayt.DynamicFilter.Parser (>= 1.7.2)
- System.Linq.Async (>= 5.1.0)
- System.Linq.Async.Queryable (>= 5.1.0)
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 |
---|---|---|
2.5.9 | 68 | 9/24/2024 |
2.5.8 | 448 | 8/11/2024 |
2.5.7 | 675 | 4/27/2024 |
2.5.6 | 104 | 4/18/2024 |
2.5.5 | 105 | 4/10/2024 |
2.5.4 | 116 | 4/2/2024 |
2.5.3 | 122 | 4/1/2024 |
2.5.2 | 124 | 3/8/2024 |
2.5.1 | 116 | 3/3/2024 |
2.5.0 | 173 | 1/6/2024 |
2.4.5 | 160 | 8/14/2023 |
2.4.4 | 155 | 8/14/2023 |
2.4.3 | 161 | 6/18/2023 |
2.4.2 | 186 | 6/18/2023 |
2.4.1 | 163 | 6/7/2023 |
2.4.0 | 134 | 6/5/2023 |
2.3.5 | 149 | 6/2/2023 |
2.3.4 | 208 | 4/19/2023 |
2.3.3 | 186 | 4/18/2023 |
2.3.2 | 202 | 4/16/2023 |
2.3.1 | 211 | 4/9/2023 |
2.3.0 | 208 | 4/9/2023 |
2.2.1 | 199 | 4/8/2023 |
2.2.0 | 178 | 4/8/2023 |
2.2.0-tags-2-2-0-beta-1.1 | 88 | 4/8/2023 |
2.1.2 | 361 | 11/4/2022 |
2.1.1 | 355 | 11/4/2022 |
2.1.0 | 407 | 9/24/2022 |
2.1.0-beta.1 | 102 | 9/9/2022 |
2.0.0 | 418 | 9/2/2022 |
2.0.0-beta.3 | 113 | 7/28/2022 |
2.0.0-beta.2 | 102 | 7/26/2022 |
2.0.0-beta.1 | 103 | 7/19/2022 |
1.9.3 | 488 | 4/21/2022 |
1.9.2 | 458 | 4/10/2022 |
1.9.1 | 448 | 4/6/2022 |
1.9.0 | 462 | 4/5/2022 |
1.8.1 | 437 | 3/27/2022 |
1.8.0 | 454 | 3/7/2022 |
1.7.12 | 367 | 10/5/2022 |
1.7.11 | 456 | 2/8/2022 |
1.7.10 | 460 | 2/8/2022 |
1.7.9 | 466 | 1/11/2022 |
1.7.8 | 457 | 1/11/2022 |
1.7.7 | 461 | 1/11/2022 |
1.7.6 | 481 | 1/11/2022 |
1.7.5 | 498 | 1/10/2022 |
1.7.4 | 289 | 12/26/2021 |
1.7.3 | 288 | 12/17/2021 |
1.7.2 | 326 | 12/12/2021 |
1.7.1 | 320 | 12/3/2021 |
1.7.0 | 329 | 11/14/2021 |
1.6.5 | 412 | 11/6/2021 |
1.6.4 | 422 | 10/26/2021 |
1.6.3 | 378 | 10/12/2021 |
1.6.2 | 384 | 10/12/2021 |
1.6.1 | 362 | 10/12/2021 |
1.6.0 | 367 | 10/11/2021 |
1.5.5 | 358 | 10/6/2021 |
1.5.4 | 367 | 10/6/2021 |
1.5.3 | 375 | 9/27/2021 |
1.5.2 | 319 | 9/27/2021 |
1.5.1 | 352 | 9/27/2021 |
1.5.0 | 357 | 9/27/2021 |
1.4.1 | 370 | 9/24/2021 |
1.4.0 | 417 | 9/24/2021 |
1.3.1 | 390 | 9/22/2021 |
1.3.0 | 353 | 9/20/2021 |
1.2.0 | 341 | 9/17/2021 |
1.1.4 | 377 | 9/17/2021 |
1.1.3 | 381 | 9/17/2021 |
1.1.2 | 323 | 9/17/2021 |
1.1.1 | 348 | 9/16/2021 |
1.1.0 | 346 | 9/13/2021 |
1.0.2 | 389 | 9/10/2021 |
1.0.1 | 445 | 9/10/2021 |
1.0.0 | 432 | 9/10/2021 |