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.

Reading entities

Reading entities

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

Reading entities

- [Instructor] Now that we have set up the OData controller, and the AppDbContext file, and we also created the database and entered some dummy data, then I'll see how we can read these entities from our controller. So let's go to Visual Studio and see that in action. So on here, let us go to our Controller. And just after the AppDbContext, let us write the EnableQuery attribute. The EnableQuery enables clients to modify the query by using different query options such as filter, sort and page. Now in here, let us write public IQueryable of Student and let us name this method Get. What we want to do in here is that we want to just return the db.Students. That's it. Let us now run the app to see the result. We see that the OData controller is running fine and here have some metadata. So we have the main URL in here and we also have some values. Here is the value of the entity or the name of the entity. Here we…

Contents