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:
- Using
@
as the prefix (as suggested at docs) the parameterfiltro
isn't being filled and get default values to all its properties. - Using no prefix it's not returning an error but the
$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.