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
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Setting up the environment4m 36s
-
(Locked)
Configuring the OData endpoint3m 25s
-
(Locked)
Creating the first OData controller2m 2s
-
(Locked)
Setting up a database4m 4s
-
(Locked)
Reading entities4m 39s
-
(Locked)
Creating and reading a single entity3m 37s
-
(Locked)
Updating and deleting an entity7m 4s
-
(Locked)
-
-
-