From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Creating and reading a single entity

Creating and reading a single entity

From the course: Advanced ASP.NET Web API 2.2

Creating and reading a single entity

- [Instructor] On this part we are going to learn how to create or read a single entity. So let us go to Visual Studio and see this in action. Let us start with the single entity. Let us first write in here EnableQuery. Then next we want to return a single result so let us write in here public SingleResult of type student. Let's import the necessary name space, which is the system.web.http. Let's enter get, it takes as a parameter the int key, but it will take this parameter from the URL, so From00ataUri. What we want to do is that we want to first find this entity. So let us write in here Iqueryable host student. Then result is equal to db.students.where. And that goes to n.Id is equal to the key value. So now that we have the result let us return that result so return SingleResult.Create. And we want to use the result to create a response. Let us run our application. So in here let us go to the students and let's say…

Contents