We have a controller which expects some parameters in a get route, but the OData functions like $top
isn't working.
According to the docs it (custom query options) should work fine just declaring the @
prefix at the custom options but it's not:
@
as the prefix (as suggested at docs) the parameter filtro
isn't being filled and get default values to all its properties.$top
function is being ignored and I'm getting too many records to show (2K+).There is another answer here on SO to something similar, but we are using OData V3 which has no explicit Edm Model Builders, it's inferred.
Have you guys solved such an issue?
Here is my code:
GET Request:
~/ProdutosRelevantes?$top=5&
filtro.Cnpjs[0]=00000000000001&
filtro.DataInicio=2018-01-01&
filtro.DataFim=2018-12-01&
filtro.IndMercado=2&
Controller method:
[HttpGet]
public IHttpActionResult ProdutosRelevantes([FromUri] ParametrosAnalise filtro)
{
var retorno = GetService().GetProdutosRelevantes(filtro);
return Content(HttpStatusCode.OK, retorno);
}
public class ParametrosAnalise { public Guid IdCliente { get; set; } public string[] Cnpjs { get; set; } public DateTime? DataInicio { get; set; } public DateTime? DataFim { get; set; } public EnumEscopoMercado? IndMercado { get; set; } // Enum declaration public enum EnumEscopoMercado { [Description("INCLUI NACIONAL")] InternoEExterno = 1, [Description("EXTERIOR")] Externo = 2 } }
Thanks.
A query option is a set of query string parameters applied to a resource that can help control the amount of data being returned for the resource in the URL.
Expand Service Implementation, then expand Products and right click on GetEntitySet (Query) and select Go to ABAP Workbench. This will open automatically open the method ZCL_GW_PRODUCT_DPC_EXT->PRODUCTS_GET_ENTITYSET in SE80. Replace the existing coding in the method by the coding below.
Do you have enabled oData with [EnableQuery] decorator in your action? Or in your HttpConfiguration => config.EnableQuerySupport()?
https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With