Web API and OData- Pass Multiple Parameters

前端 未结 2 941
生来不讨喜
生来不讨喜 2020-12-01 14:43

Is it possible to get OData to do the following? I would like to be able to query a REST call by passing on parameters than may not be the primary key. Can I call a REST met

2条回答
  •  生来不讨喜
    2020-12-01 14:59

    For OData v4.0 endpoints, you don't have to make it a function, you can simply do...

    public class ReportsController : ODataController
    {
        [EnableQuery]
        [ODataRoute("Reports({id}, {year})")]
        public IQueryable Get([FromODataUri] int id, [FromODataUri] int year)
        {
            ...
        }
    }
    

    Then you can call it like...

    /Reports(42, 2019)
    

提交回复
热议问题