From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating the first OData controller

Creating the first OData controller

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

Creating the first OData controller

- [Instructor] Now that we have configured our OData endpoint, it is time to create our first OData controller. So, let's go to Visual Studio and see this in action. So here we go to Solution Explorer and then on the Controllers folder right click and add a new class. We are going to name this controller, the Students Controller. For the StudentsController class to be an OData controller, we need to inherit from the base class ODataController. Let us import the necessary namespace and to get the data to our controller we are going to use the AppDBContext class. So let's write in here, AppDBContext, db is equal to new AppDBContext. Let us import the necessary namespace, which is the OData.Models and now let us create an override of the dispose method. So we make sure that we dispose our AppDBContext. So db.Dispose. And now before we go to the next part, let us create a method that we are going to use in the upcoming…

Contents