0% found this document useful (0 votes)
2 views

Models in web API

The document explains the concept of models in ASP.NET Core MVC, highlighting their role in representing data and business logic. It outlines a 3-layer application architecture consisting of the Presentation Layer, Business Layer, and Data Access Layer, along with examples of different model types such as Request, Business, Entity, Response, and View Models. Additionally, it introduces Entity Framework Core (EF Core) as an Object-Relational Mapping (ORM) tool that facilitates database interactions in .NET applications.

Uploaded by

Bảo Cao Thiên
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Models in web API

The document explains the concept of models in ASP.NET Core MVC, highlighting their role in representing data and business logic. It outlines a 3-layer application architecture consisting of the Presentation Layer, Business Layer, and Data Access Layer, along with examples of different model types such as Request, Business, Entity, Response, and View Models. Additionally, it introduces Entity Framework Core (EF Core) as an Object-Relational Mapping (ORM) tool that facilitates database interactions in .NET applications.

Uploaded by

Bảo Cao Thiên
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Home Content Sign Out

Models in web API


Home Content Sign Out

What is a Model
in ASP.NET Core MVC?
Home Content Sign Out

What is Model data (properties)

is a class that represents

business logic (methods)


Home Content Sign Out

data (properties)

business logic (methods)


Home Content Sign Out

data (properties)

No data = No model
business logic (methods)
Home Content Sign Out

3-Layer Application
. Architecture
3-Layer Architecture
01 Presentation Layer: User interaction.

02 Business Layer: Business logic.


Presentation Layer Business Layer Data Access Layer
03 Data Access Layer: CRUD
(Controller, View) (Service) (Repository)
Home Content Sign Out

Example. project

An E-commerce platform where customers can place orders for products.


Home Content Sign Out

Models example
1. Request Model 2. Business Model 3. Entity Model

4. Response Model 5. View Model


Home Content Sign Out

Models example

1. Request Model

Validates incoming data


from the client
Protects the system from
invalid or harmful input.
Home Content Sign Out

Models example

2. Business Model

Holds data used by the


service layer.
Applies business rules (e.g.,
pricing, stock verification).
Home Content Sign Out

Models example

3. Entity Model

Used for interacting with the


database.
Direct mapping to database
tables (CRUD operations).
Home Content Sign Out

Models example

4. Response Model

Provides simplified output to


the client.
Protects sensitive internal
details.
Home Content Sign Out

Models example
5. View Model

Format data in UI
Home Content Sign Out

Models example
1. Request Model 2. Business Model 3. Entity Model

4. Response Model 5. View Model


Home Content Sign Out
Home Content Sign Out

1. Request Model

Controller

1. Request Model
Home Content Sign Out

1. Request Model 2. Business Model

Controller Service

1. Request Model
Home Content Sign Out

1. Request Model 2. Business Model

Controller Service

1. Request Model 2. Business Model


Home Content Sign Out

1. Request Model 2. Business Model

Controller Service

2. Business Model 3. Entity Model


Home Content Sign Out

1. Request Model 2. Business Model 3. Entity Model

Controller Service Repository

3. Entity Model
Home Content Sign Out

1. Request Model 2. Business Model 3. Entity Model

Controller Service Repository

3. Entity Model
Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

3. Entity Model
Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

3. Entity Model
Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

4. Response Model 3. Entity Model


Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

4. Response Model
Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

4. Response Model
Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

5. View Model 2. Business Model


Home Content Sign Out

4. Response Model 2. Business Model 3. Entity Model

Controller Service Repository

5. View Model
5. View Model

View
Home Content Sign Out

Object ORM links code objects to database tables

Relational
Maping Lets you use code instead of SQL.

(ORM) Converts data between objects and


database rows automatically.
Home Content Sign Out

EF Core is an ORM for .NET


Entity
Framework
Itegrate well with LINQ
Core
Cross-platform support (Windows, Linux, (EF Core)
Mac).
Home Content Sign Out

EF Core design workflows


Database first Code first
Home Content Sign Out

Thank You!

You might also like