본문 바로가기

Backend/.NET

Relational DB - Getting Data Asynchronous

반응형

Let's see how we can get data asynchronously using Entity Framework.

Setting Up a Project

Creating an Application

 

How to create .NET web-API

Setting up development tools When working with .NET, we need tools to create a web application. We can download them in the link below.다. .NET | Free. Cross-platform. Open Source. (microsoft.com) .NET | Free. Cross-platform. Open Source. .NET is a develo

jin-co.tistory.com

Adding Relationship

 

Adding Relation to DB

Entity framework makes adding a relationship between tables easy. Let's see how it is done. Creating an Application First, let's create a .NET application. How to create a .NET web-API application (tistory.com) How to create .NET web-API Setting up develop

jin-co.tistory.com

For better demonstration, I have created three entities

Adding Repository Pattern

 

Application Architecture - Repository with Service

An Interface is a kind of contract that specifies what the application needs. Let's see how we can use an interface with the repository pattern. Project Configurations Creating a Project with MVC Pattern Server Architecture - Distributing Projects Server S

jin-co.tistory.com

Adding Generic Repository Pattern

 

Application Architecture - Generic Repository

The repository pattern has a static type so whenever we create an entity, we have to create a repository as well. A generic is a way to restrict to a type or to dynamically change types. Let's see how we can use a generic repository for multiple entities P

jin-co.tistory.com

Setting Up Asynchronous

Asynchronous uses a type called Task

Updating the Controller with Asynchronous Methods

Open the controller class and add Task type with async and await to the methods

Updating the Interface with Asynchronous Methods

Move to the repository interface and update methods with Task

Updating the Repository with Asynchronous Methods

In the implementation class, update implemented methods to Task type with async and await to the methods

Run

Move to the API folder

cd /API

And run the app

dotnet watch

You will see added endpoints right away like below if you are using Swagger

Open each and try

 

 

We have seen how we can get data asynchronously using the Entity Framework

 

728x90
반응형