EfCore.Filtering.Mvc
1.0.0
See the version list below for details.
dotnet add package EfCore.Filtering.Mvc --version 1.0.0
NuGet\Install-Package EfCore.Filtering.Mvc -Version 1.0.0
<PackageReference Include="EfCore.Filtering.Mvc" Version="1.0.0" />
paket add EfCore.Filtering.Mvc --version 1.0.0
#r "nuget: EfCore.Filtering.Mvc, 1.0.0"
// Install EfCore.Filtering.Mvc as a Cake Addin
#addin nuget:?package=EfCore.Filtering.Mvc&version=1.0.0
// Install EfCore.Filtering.Mvc as a Cake Tool
#tool nuget:?package=EfCore.Filtering.Mvc&version=1.0.0
For full documentation and explanation on usage see https://github.com/AndyCC/EfCore.Filtering
Setup services:
services.AddControllers(opts =>
{
opts.ModelBinderProviders.Insert(0, new FilterModelBinderProvider());
}).AddJsonOptions(opts => opts.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
services.AddQueryBuilder();
Inject IQueryBuilder
into the required controllers
Setup endpoints, for example
private MyDbContext _context;
[HttpGet]
public async Task<IActionResult> Get([FromQuery] Filter<MyEntity> filter)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
IList<Product> results;
if (filter != null)
{
var query = QueryBuilder.BuildQuery<MyEntity>(filter);
results = await query(_context.MyEntities).AsNoTracking().ToListAsync();
}
else
results = await _context.MyEntities.AsNoTracking().ToListAsync();
if (results.Count == 0)
return NotFound();
return Ok(results);
}
and/or
[HttpPost("query")]
public async Task<IActionResult> Query(Filter<MyEntity> filter)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
var query = QueryBuilder.BuildQuery<MyEntity>(filter);
var results = await query( _context.MyEntities).AsNoTracking().ToListAsync();
if (results.Count == 0)
return NotFound();
return Ok(results);
}
Call the endpoint with a json filter
{
"Skip": 1,
"Take": 2,
"WhereClause": {
"LogicalOperator": "AND",
"Rules": [{
"Path": "Product.Name",
"ComparisonOperator": "eq",
"Value": "Cat Dispenser"
}, {
"Path": "Shop.Id",
"ComparisonOperator": "gte",
"Value": 1
}],
"RuleSets": null
},
"Ordering": [{
"Path": "Id",
"Order": "asc"
}],
"Includes": [{
"Path": "Product",
"Filter": null
},{
"Path": "Shop",
"Filter": null
}]
}
or a shortened json filter
{
"O": [
"Id"
],
"W": {
"L": "O",
"R": [
{
"P": "Name",
"C": "eq",
"V": "Everythings 10 Shop"
}
],
"S": [
{
"L": "A",
"R": [
{
"P": "ProductListings.Price",
"C": "gt",
"V": 14
},
{
"P": "ShippingRegions.Region",
"C": "in",
"V": [
"UK",
"EU"
]
}
]
}
]
},
"I": [
{
"P": "ProductListings",
"F": {
"T": 1,
"S": 1
}
}
]
}
used with GET method like myapi/Shop?filter={"O":["Id"],"W":{"L":"O","R":[{"P":"Name","C":"eq","V":"Everythings 10 Shop"}],"S":[{"L":"A","R":[{"P":"ProductListings.Price","C":"gt","V":14},{"P":"ShippingRegions.Region","C":"in","V":["UK","EU"]}]}]},"I":[{"P":"ProductListings", "F":{"T":1,"S":1}}]}
or a query string
myapi/Shop?O[0]=Id
&W.L=O
&W.R[0].P=Name
&W.R[0].C=eq
&W.R[0].V=Everythings%2010%20Shop
&W.S[0].L=A
&W.S[0].R[0].P=ProductListings.Price
&W.S[0].R[0].C=gt
&W.S[0].R[0].V=14
&W.S[0].R[1].P=ShippingRegions.Region
&W.S[0].R[1].C=in
&W.S[0].R[1].V=[UK,EU]
&I[0].P=ProductListings
&I[0].F.T=1
&I[0].F.S=1
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. |
-
net5.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial Release