Tutorial by Examples

From the Tools menu, select NuGet Package Manager > Package Manager Console. In the Package Manager Console window, type: Install-Package Microsoft.AspNet.Odata This command installs the latest OData NuGet packages.
For this tutorial, we'll use Entity Framework (EF) Code First to create the back-end database. Web API OData does not require EF. Use any data-access layer that can translate database entities into models. First, install the NuGet package for EF. From the Tools menu, select NuGet Package Mana...
Open the file App_Start/WebApiConfig.cs. Add the following using statements: using ProductService.Models; using System.Web.OData.Builder; using System.Web.OData.Extensions; Then add the following code to the Register method: public static class WebApiConfig { public static void Register...
A controller is a class that handles HTTP requests. You create a separate controller for each entity set in your OData service. In this tutorial, you will create one controller, for the Product entity. In Solution Explorer, right-click the Controllers folder and select Add > Class. Name the clas...
Querying the Entity Set Add the following methods to ProductsController. [EnableQuery] public IQueryable<Product> Get() { return db.Products; } [EnableQuery] public SingleResult<Product> Get([FromODataUri] int key) { IQueryable<Product> result = db.Products.Wher...

Page 1 of 1