OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
854 stars 476 forks source link

Example Documentation Extension Does Not Filter on 7.x (Beta 4) #1456

Closed keithnicholson closed 6 years ago

keithnicholson commented 6 years ago

I have gone to http://odata.github.io/WebApi/#14-01-netcore-beta1 to see where the OData/WebApi provides some examples down at the bottom of the page for 7.X in section 14. I have done the example project and it works as provided. However the beauty of OData is to call parameters and get different results. That does not seem to work here for even filter.

Assemblies affected

Microsoft.AspNetCore.OData(7.0.0-beta4)

Reproduce steps

To the ProductsController class I added an additional Product:

, new Product() { ID = 2, Name="Jelly" }

Then my query in the browser is: http://host:port/odata/Products?$filter=ID eq 1

Expected result

{"@odata.context":"http://host:port/odata/$metadata#Products","value":[{"ID":1,"Name":"Bread"}]}

Actual result

{"@odata.context":"http://host:port/odata/$metadata#Products","value":[{"ID":1,"Name":"Bread"},{"ID":2,"Name":"Jelly"}]}

xuzhg commented 6 years ago

@keithnicholson

Thanks for trying beta4. Yes, documentation is a little bit behind the release.

For your problem, please add the following line codes in the "UseMvc"

app.UseMvc(builder =>
     {
            builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
            ...
     }

And please remove the routeBuilder.EnableDependencyInjection();.

xuzhg commented 6 years ago

@keithnicholson I updated the corresponding docs. Thanks your input.

Close it. if you have further concerns or questions, please file new issue for us. Thanks.