问题
As it is been pointed in this article, with $query keyword you can solve the problem of long OData URLs after the version 7.5 of Microsoft.AspNetCore.OData
.
but in my project(I'm using version 8.preview3) I tried the use this but I keep getting 404 not found error. Here are my working URL examples:
https://localhost:44346/odata/WFC/APost/
https://localhost:44346/odata/WFC/APost/?$select=id
...
but when I use a POST request with $query I receive 404 error:
POST: https://localhost:44346/odata/WFC/APost/$query
Content-Type: text/plain
Request Body: $select=id
I wonder if I have to add any code to enable the $query functionality !?
Here are relevant pieces of my code :
// version 8.preview3 of Microsoft.AspNetCore.OData code
services.AddOData(
opt => opt.AddModel("odata", GetEdmModel()).Select().Count().Filter().OrderBy().SetAttributeRouting(true));
...
public IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
var s = builder.EntitySet<WeatherForecast>("WFC").EntityType;
s.Collection.Action("APost");
return builder.GetEdmModel();
}
and the controller :
[ODataRoutePrefix("WFC")]
public class WeatherForecast2Controller : ODataController
{
...
[HttpPost]
[EnableQuery]
[ODataRoute("APost")]
public IEnumerable<WeatherForecast> APost()
{
// this function just returns array of 10 WeatherForecast(s) .
...
}
}
来源:https://stackoverflow.com/questions/65611721/odata-aspnetcore-support-for-long-urls-useing-query-is-not-working