Open sphildreth opened 6 years ago
That's quite odd, what happens if you look at the contents of sieveModel
? Have a look at this for a working project.
This should work
[HttpGet]
public ActionResult<IEnumerable<Publisher>> Get([FromQuery] SieveModel sieveModel)
{
var data = this._repository.List();
return _sieveProcessor.Apply(sieveModel, data).ToArray();
}
@sphildreth Please make sure below configuration,
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Give me the 2.1 behaviors
use @diezsenn code, asp.net core MVC tries to bind classes(complex types) from the body by default, you need to add [FromQuery]
before.
Few other tips: use sieve directly on IQueryable
if you use ORM, then it will translate it to appropriate SQL query, use async methods for DB calls and I/O calls. If you have repository abstraction created, use Sieve inside your repository, it is repository responsibility, to filter, sort and paginate.
@Biarity I think it would be reasonable to provide custom IBindingMetadataProvider
to tell ASP.NET Core MVC to bind SieveModel
from query by default globally so people won't forget to use [FromQuery]
see: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-2.1#customize-model-binding-and-validation-globally but don't do it if it adds dependency, then optionally some nuget package for MVC could be provided
would you add an asynchronous version for Apply method in the SieveProcessor class?
I try to use the default code using ASP.NET Core 2.1 Web API and anytime I put SieveModel as a post parameter I get "The Input was not valid." as a result.