SlideShare a Scribd company logo
ASP.NET Core MVC
with
EF Core Code-First
About Me
Md. Aftab Uddin Kajal
Software Engineer
SELISE rockin' software
linkedin: @iamkajal || github: @iamkajal || kajal.alpha@gmail.com
Agenda
● Get started
● Create, Read, Update, and Delete operations
● Sorting, filtering
● Migrations
● Create a complex data model
● Reading related data
● Updating related data
● Implementing Repository Pattern
● Implementing Clean Architecture
EMS web app
Get started with EF Core in an ASP.NET MVC web app
This lesson teaches ASP.NET Core MVC and Entity Framework Core with controllers and views.
The EMS sample web application demonstrates how to create ASP.NET Core 2.2 MVC web
applications using Entity Framework (EF) Core 2.0 and Visual Studio 2017.
The sample application is a web site for a EMS. It includes functionality such as employee add,
salary creation, and task assignments.
In this lesson, you:
● Create ASP.NET Core MVC web app
● Set up the site style
● Learn about EF Core NuGet packages
● Create the data model
● Create the database context
● Register the SchoolContext
● Initialize DB with test data
● Create controller and views
● View the database
Create ASP.NET Core MVC web app
Open Visual Studio and create a new ASP.NET Core C# web project named
"EmployeeManagementSystem".
1. From the File menu, select New > Project.
2. From the left pane, select Installed > Visual C# > Web.
3. Select the ASP.NET Core Web Application project template.
4. Enter EmployeeManagementSystem as the name and click OK.
● Wait for the New ASP.NET Core Web
Application (.NET Core) dialog to
appear
● Select ASP.NET Core 2.2 and the
Web Application
(Model-View-Controller) template.
● Note: This tutorial requires ASP.NET
Core 2.2 and EF Core 2.0 or later.
● Make sure Authentication is set to No
Authentication and Click OK
Set up the site style
A few simple changes will set up the site menu, layout, and home page.
Open Views/Shared/_Layout.cshtml and make the following changes:
● Change each occurrence of "EmployeeManagementSystem" to "EMS". There are three
occurrences.
● Add menu entries for About, Employees, Salary Sheet, Task, and Departments, and delete the
Privacy menu entry.
Coding
Create the
BaseEntity
In the Models folder, create
a folder named
“SharedKernel” and create
file named BaseEntity.cs
and replace the template
code with the following
code.
public abstract class BaseEntity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
}
Create the data
model
In the Models folder, create
a class file named
Emplyee.cs and replace the
template code with the
following code.
public class Employee : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Designation { get; set; }
public string Gender { get; set; }
public int DepartmentId { get; set; }
public Department Department { get; set; }
public double Salary { get; set; }
[DataType(DataType.Date)]
public DateTime? DateOfBirth { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string ShortCode { get; set; }
public string ImageUrl { get; set; }
}
Create the data
model
In the Models folder, create
a class file named
Department.cs and replace
the template code with the
following code.
public class Department : BaseEntity
{
public string Name { get; set; }
public List<Employee> Employees { get; set; }
}
Create the
database context
Create this class by deriving from the
Microsoft.EntityFrameworkCore.DbContext
public class EmployeeDbContext : DbContext
{
Public EmployeeDbContext(
DbContextOptions<EmployeeDbContext> options) : base(options)
{ }
public DbSet<Department> Departments { get; set; }
public DbSet<Employee> Employees { get; set; }
}
Register the EmployeeDbContext
Coding
Add Employee Controller
Coding
Implement Index action method in Employee
Controller
Coding
Implement Index View for Index method
Coding
Implement Create, Edit, details and delete
action method and View
Coding
Implement sorting, searching
Repository Pattern
The repository pattern is mediator
between database and application
business logic. repository pattern have
two purposes; first it is an abstraction
of the data layer and second it is a way
of centralising the handling of the
domain objects.
Repository
Pattern
Implementation
Coding
ASP.NET Core MVC with EF Core code first
Resources
● ASP.NET Core
● ASP.NET Core in MVA
● Patterns In Model-View-Controller Architectures
● Principles Take pride in your code.
●
ASP.NET Core MVC with EF Core code first
Ad

More Related Content

What's hot (20)

Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
Raed Aldahdooh
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
Rohit Gupta
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
Piyush Aggarwal
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Jennifer Estrada
 
도메인 주도 설계의 본질
도메인 주도 설계의 본질도메인 주도 설계의 본질
도메인 주도 설계의 본질
Young-Ho Cho
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
asif290119
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
Rana Muhammad Asif
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
Sanjeev Kumar
 
DOT Net overview
DOT Net overviewDOT Net overview
DOT Net overview
chandrasekhardesireddi
 
Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
Shivanand Arur
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
.NET Core, ASP.NET Core Course, Session 6
.NET Core, ASP.NET Core Course, Session 6.NET Core, ASP.NET Core Course, Session 6
.NET Core, ASP.NET Core Course, Session 6
Amin Mesbahi
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity Framework
James Johnson
 
jQuery
jQueryjQuery
jQuery
Jay Poojara
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
NAVER Engineering
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
Srikanth R Vaka
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
Christoffer Noring
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
Raed Aldahdooh
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
Rohit Gupta
 
도메인 주도 설계의 본질
도메인 주도 설계의 본질도메인 주도 설계의 본질
도메인 주도 설계의 본질
Young-Ho Cho
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
.NET Core, ASP.NET Core Course, Session 6
.NET Core, ASP.NET Core Course, Session 6.NET Core, ASP.NET Core Course, Session 6
.NET Core, ASP.NET Core Course, Session 6
Amin Mesbahi
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity Framework
James Johnson
 

Similar to ASP.NET Core MVC with EF Core code first (20)

Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Sony Suci
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
Akhil Mittal
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
Alfa Gama Omega
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
Rich Helton
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
Mădălin Ștefîrcă
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
sonia merchant
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
Pooja Gaikwad
 
Mvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senjaMvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senja
alifha12
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
laxmi.katkar
 
Pratk kambe rac
Pratk kambe racPratk kambe rac
Pratk kambe rac
Pratik Kambe
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
Alicia Buske
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
Suzanne Simmons
 
FSD PPT.pptx sfdb sfcdevc funcrv cf. Aaaf
FSD PPT.pptx sfdb sfcdevc funcrv cf.  AaafFSD PPT.pptx sfdb sfcdevc funcrv cf.  Aaaf
FSD PPT.pptx sfdb sfcdevc funcrv cf. Aaaf
SudeepNM
 
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
Entity Framework Core Cookbook 2nd Edition Ricardo PeresEntity Framework Core Cookbook 2nd Edition Ricardo Peres
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
yuvejulpah
 
Part 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdf
Part 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdfPart 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdf
Part 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdf
Facile Technolab
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
Diluka99999
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Sony Suci
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
Akhil Mittal
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
Alfa Gama Omega
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
Rich Helton
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
sonia merchant
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
Pooja Gaikwad
 
Mvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senjaMvc4 crud operations.-kemuning senja
Mvc4 crud operations.-kemuning senja
alifha12
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5  Building Your First Web Application (A Beginner S GuideASP.NET MVC 5  Building Your First Web Application (A Beginner S Guide
ASP.NET MVC 5 Building Your First Web Application (A Beginner S Guide
Alicia Buske
 
FSD PPT.pptx sfdb sfcdevc funcrv cf. Aaaf
FSD PPT.pptx sfdb sfcdevc funcrv cf.  AaafFSD PPT.pptx sfdb sfcdevc funcrv cf.  Aaaf
FSD PPT.pptx sfdb sfcdevc funcrv cf. Aaaf
SudeepNM
 
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
Entity Framework Core Cookbook 2nd Edition Ricardo PeresEntity Framework Core Cookbook 2nd Edition Ricardo Peres
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
yuvejulpah
 
Part 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdf
Part 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdfPart 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdf
Part 4 How to use EF Core with MongoDb in Blazor Server Web Application.pdf
Facile Technolab
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
Diluka99999
 
Ad

Recently uploaded (20)

IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Ad

ASP.NET Core MVC with EF Core code first

  • 1. ASP.NET Core MVC with EF Core Code-First
  • 2. About Me Md. Aftab Uddin Kajal Software Engineer SELISE rockin' software linkedin: @iamkajal || github: @iamkajal || [email protected]
  • 3. Agenda ● Get started ● Create, Read, Update, and Delete operations ● Sorting, filtering ● Migrations ● Create a complex data model ● Reading related data ● Updating related data ● Implementing Repository Pattern ● Implementing Clean Architecture
  • 5. Get started with EF Core in an ASP.NET MVC web app This lesson teaches ASP.NET Core MVC and Entity Framework Core with controllers and views. The EMS sample web application demonstrates how to create ASP.NET Core 2.2 MVC web applications using Entity Framework (EF) Core 2.0 and Visual Studio 2017. The sample application is a web site for a EMS. It includes functionality such as employee add, salary creation, and task assignments. In this lesson, you: ● Create ASP.NET Core MVC web app ● Set up the site style ● Learn about EF Core NuGet packages ● Create the data model ● Create the database context ● Register the SchoolContext ● Initialize DB with test data ● Create controller and views ● View the database
  • 6. Create ASP.NET Core MVC web app Open Visual Studio and create a new ASP.NET Core C# web project named "EmployeeManagementSystem". 1. From the File menu, select New > Project. 2. From the left pane, select Installed > Visual C# > Web. 3. Select the ASP.NET Core Web Application project template. 4. Enter EmployeeManagementSystem as the name and click OK.
  • 7. ● Wait for the New ASP.NET Core Web Application (.NET Core) dialog to appear ● Select ASP.NET Core 2.2 and the Web Application (Model-View-Controller) template. ● Note: This tutorial requires ASP.NET Core 2.2 and EF Core 2.0 or later. ● Make sure Authentication is set to No Authentication and Click OK
  • 8. Set up the site style A few simple changes will set up the site menu, layout, and home page. Open Views/Shared/_Layout.cshtml and make the following changes: ● Change each occurrence of "EmployeeManagementSystem" to "EMS". There are three occurrences. ● Add menu entries for About, Employees, Salary Sheet, Task, and Departments, and delete the Privacy menu entry.
  • 10. Create the BaseEntity In the Models folder, create a folder named “SharedKernel” and create file named BaseEntity.cs and replace the template code with the following code. public abstract class BaseEntity { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } }
  • 11. Create the data model In the Models folder, create a class file named Emplyee.cs and replace the template code with the following code. public class Employee : BaseEntity { public string FirstName { get; set; } public string LastName { get; set; } public string Designation { get; set; } public string Gender { get; set; } public int DepartmentId { get; set; } public Department Department { get; set; } public double Salary { get; set; } [DataType(DataType.Date)] public DateTime? DateOfBirth { get; set; } [DataType(DataType.EmailAddress)] public string Email { get; set; } public string PhoneNumber { get; set; } public string ShortCode { get; set; } public string ImageUrl { get; set; } }
  • 12. Create the data model In the Models folder, create a class file named Department.cs and replace the template code with the following code. public class Department : BaseEntity { public string Name { get; set; } public List<Employee> Employees { get; set; } }
  • 13. Create the database context Create this class by deriving from the Microsoft.EntityFrameworkCore.DbContext public class EmployeeDbContext : DbContext { Public EmployeeDbContext( DbContextOptions<EmployeeDbContext> options) : base(options) { } public DbSet<Department> Departments { get; set; } public DbSet<Employee> Employees { get; set; } }
  • 16. Coding Implement Index action method in Employee Controller
  • 17. Coding Implement Index View for Index method
  • 18. Coding Implement Create, Edit, details and delete action method and View
  • 20. Repository Pattern The repository pattern is mediator between database and application business logic. repository pattern have two purposes; first it is an abstraction of the data layer and second it is a way of centralising the handling of the domain objects.
  • 24. Resources ● ASP.NET Core ● ASP.NET Core in MVA ● Patterns In Model-View-Controller Architectures ● Principles Take pride in your code. ●