Lab02 BookManagement Using OData
Lab02 BookManagement Using OData
Introduction
Imagine you're a librarian of an university, your leader has asked you to
develop an application for book management especially support the
querying data in many options. The book information includes id, ISBN,
title, author, price, press information and address information. The press
information includes press id, press name, the press information also has
category information such as book, ebook, magazine. The address
information will have city and country. The application has to support
adding, viewing, modifying, and removing books - a standardized usage
action verbs better known as Create, Read, Update, Delete (CRUD).
OData is an open protocol for operating data over HTTP. It also follows
REST architecture. Currently OData is widely used for exposing data, so
this is the suitable method to implement Book Management application.
This lab explores creating an application using OData to create service,
and ASP.NET Core Web Application with Model-View-Controller. An In-
Memory Database will be created to persist the book data that will be used
for reading and managing book data by Entity Framework Core.
1|Page
Lab Objectives
In this lab, you will:
Use the Visual Studio.NET to create OData Service using ASP.NET
Core Web Web API Project.
Develop Web application using MVC Pattern.
Use Entity Framework Core to create a In-Memory database
Develop Entity classes, DBContext class, DataSource class to
perform CRUD actions using Entity Framework Core
Run the project and test the services using Postman.
Run the project and test the application actions.
2|Page
Guidelines
Activity 01: Create a Blank Solution
Step 01. Create a Solution named Lab01_BookStoreOData8.
Step 05. Create ASP.NET Core Web Web API Project for OData Service.
Step 06. Create ASP.NET Core Web Application (Model-View-Controller)
Project.
3|Page
Activity 02: Creating an OData Service
Step 01. Create a skeleton of the ASP.NET Core OData service using
ASP.NET Core Web API.
Step 02. Install the following packages from NuGet:
Step 03. Add the model classes for building the Entity Data Model (EDM)
This steps will create 1 enum data named Category and 3 classes named
Address, Press and Book.
4|Page
Step 04. Build the Entity Data Model
OData uses the Entity Data Model (EDM) to describe the structure of data.
To build the EDM add a method in Startup.cs class.
5|Page
Step 05. Register the OData Services through Dependency Injection
6|Page
Note: Can use the below option Configure() method
app.UseEndpoints(endpoints =>
{
endpoints.MapODataRoute("odata", "odata", GetEdmModel());
});
7|Page
Add service with In-Memory Database to ConfigureServices() method of
Startup.cs
8|Page
Step 07. Add Controllers
9|Page
The details of constructor and functions in BooksController.
10 | P a g e
The details of functions in PressesController.
11 | P a g e
12 | P a g e
Activity 03: Testing OData Service
Step 01. Test $select option
The $select system query option allows clients to request a specific set of
properties for each entity or complex type. The set of properties will be
comma-separated while requesting.
http://localhost:50246/odata/Books?$select=Title,Author
eq - equals to.
ne - not equals to
gt - greater than
ge - greater than or equal
lt - less than
le - less than or equal
13 | P a g e
Step 03. Test $orderby option
The $orderby sorts the data using 'asc' and 'desc' keywords. We can do
sorting on multiple properties using comma separation.
http://localhost:50246/odata/Presses?$orderby=Name desc
14 | P a g e
Step 04. Test $top and $skip options
The $top fetches specified the count of top records in the collection. So to
work this operator, we must specify an extension method like
'SetMaxTo(specify_max_number)'.
http://localhost:50246/odata/Presses?$top=2&$skip=1
16 | P a g e
17 | P a g e
Step 03. Create View
18 | P a g e
19 | P a g e
Step 04. Test the function of Web Client
20 | P a g e
Activity 05: Build and run Project. Test all CRUD
actions
Note: Choose the option for multiple startup projects.
21 | P a g e