it:ad:asp.net:webapi:howto:odata:install:home

IT:AD:ASP.NET:WebAPI:HowTo:OData:Install

Summary

Installation of OData is relatively straight forward.

  • Install the OData v4 package into your presentation assembly: Install-Package Microsoft.AspNet.OData (not the OData V3 one: Microsoft.AspNet.WebApi.OData)
  • Create a Controller:
    • That inherits from System.Web.OData.ODataController
    • Whose GET method returns an IQueryable or IHttpActionResult
    • Whose class – or specific method – is decorated with using [EnableQuery]

The key part is to inherit from ODataController:

namespace Demo.Controllers
{
    [EnableQuery]
    public class FooController : ODataController
    {
        public IHttpActionResult Get()
        {
            return Ok(FooService.Items.AsQueryable());
        }
    }
}

  • /home/skysigal/public_html/data/pages/it/ad/asp.net/webapi/howto/odata/install/home.txt
  • Last modified: 2023/11/04 03:01
  • by 127.0.0.1