OData AspNetCore support for long URLs useing $query is not working

孤街浪徒 提交于 2021-01-27 21:30:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!