SlideShare a Scribd company logo
Generic Repository Pattern
with ASP.NET MVC and EF
Md. Mahedee Hasan
Microsoft MVP | Trainer | Speaker
Software Architect
LeadSoft Bangladesh Limited
Linkedin: http://www.linkedin.com/in/mahedee
Blog: http://mahedee.net/
1
• MVC Stands for Model – View – Controller
• It is Software Architectural pattern
MAHEDEE.NET 2
What is MVC?
• Is an open source web application framework
• It implements the model-view-controller pattern
• MVC design pattern aims to “Separation Of concern”
MAHEDEE.NET 3
What is ASP.NET MVC?
• Entity Framework is an ORM.
• Work with relational data using domain-specific
objects
• Eliminates the need for most of the data-access code
MAHEDEE.NET 4
What is ASP.NET EF?
DRY?
Don’t repeat yourself
-Means don't write duplicate code
Use generic repository pattern to
implement DRY
MAHEDEE.NET 5
• What is Design Pattern?
• Design pattern is a solution of known problems
• What is Software Design Pattern?
• Is a solution of known problems in Software.
• Strategies of solving commonly occurring problems.
• A design pattern is not a finish design.
• It is like a template to solve a problem.
MAHEDEE.NET 6
Software Design Pattern
Repository Pattern
• Mediator between BLL and DAL(Data Source)
• It’s a separation layer between Data and Domain
Layer
– Separates data and domain Layer
MAHEDEE.NET 7
Benefits of Repository Pattern
• Centralizes data logic or service logic.
• Provides a substitution point for the unit tests
– Both BLL and DAL
• Provides a flexible architecture
– Can adopt new change easily
• Domain driven development is easier
MAHEDEE.NET 8
What is Generic Repository Pattern?
• Generally - one repository for one model to access
data.
– Write similar code again and again
• What if Single Repository for all?
• Single repository for data access of all models.
MAHEDEE.NET 9
Benefits of Generic Repository Pattern
• Reduce redundancy of code
• Faster development
• Force developer to work same pattern
– Possibility of less error or no error
• Easy to maintain
– Centralize data access logic
MAHEDEE.NET 10
Implementation
• Tools and Technology used
– Visual Studio 2013
– Visual C#
– ASP.NET MVC 5
– Entity Framework 6
– Razor view engine
MAHEDEE.NET 11
Step 1: Create an ASP.NET MVC 5 application using
Visual Studio 2013
MAHEDEE.NET 12
Implementation…
Step 2: Configure connection string in web.config
MAHEDEE.NET 13
Implementation …
Step 3: Create Models
MAHEDEE.NET 14
Implementation …
Step 4: Create a DbContext in Repository folder.
MAHEDEE.NET 15
Implementation …
Step 5: Create IGenericRepository and
GenericRepository in Repository folder
MAHEDEE.NET 16
Implementation …
• Step 6:
– Create controllers of each models
– Select template “MVC5 Controller with views, using Entity
Framework”
– Modify Controllers and use Generic Repository in
Controller
MAHEDEE.NET 17
Implementation …
• Step 7: Add links to _Layout
MAHEDEE.NET 18
Implementation …
• Step 8: Write following command in package manager
console
– PM> Enable-Migrations -ContextTypeName
GenericRepoContext
– PM> Add-Migration initialcreate
– PM> Update-Database -Verbose -Force
MAHEDEE.NET 19
Implementation …
Step 9: Run Project
MAHEDEE.NET 20
Implementation …
21

More Related Content

What's hot (20)

PPTX
ASP .Net MVC 5
Nilachal sethi
 
PPT
ASP.NET MVC Presentation
ivpol
 
PPTX
Asp.net c# mvc Training: Day-3 of Day-9
AHM Pervej Kabir
 
PPTX
MVC4 framework
imarkovic
 
PPTX
Architecting ASP.NET MVC Applications
Gunnar Peipman
 
PPTX
Asp.net mvc 5 course module 1 overview
Sergey Seletsky
 
PPTX
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins
 
PPTX
ASP.NET MVC Best Practices malisa ncube
Malisa Ncube
 
PPTX
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
PPT
Php Frameworks
Ryan Davis
 
PDF
Asp 1a-aspnetmvc
Fajar Baskoro
 
PPTX
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
PDF
Php and-mvc
Manoj Sahoo
 
PPT
My cool new Slideshow!
netzwelt12345
 
PPTX
Asp.net MVC training session
Hrichi Mohamed
 
PDF
Kentico and MVC
Cheryl MacDonald
 
PPTX
PHP framework difference
iScripts
 
PPTX
Using MVC with Kentico 8
Thomas Robbins
 
PPT
Code igniter overview
umesh patil
 
PDF
Principles of MVC for PHP Developers
Edureka!
 
ASP .Net MVC 5
Nilachal sethi
 
ASP.NET MVC Presentation
ivpol
 
Asp.net c# mvc Training: Day-3 of Day-9
AHM Pervej Kabir
 
MVC4 framework
imarkovic
 
Architecting ASP.NET MVC Applications
Gunnar Peipman
 
Asp.net mvc 5 course module 1 overview
Sergey Seletsky
 
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins
 
ASP.NET MVC Best Practices malisa ncube
Malisa Ncube
 
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
Php Frameworks
Ryan Davis
 
Asp 1a-aspnetmvc
Fajar Baskoro
 
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
Php and-mvc
Manoj Sahoo
 
My cool new Slideshow!
netzwelt12345
 
Asp.net MVC training session
Hrichi Mohamed
 
Kentico and MVC
Cheryl MacDonald
 
PHP framework difference
iScripts
 
Using MVC with Kentico 8
Thomas Robbins
 
Code igniter overview
umesh patil
 
Principles of MVC for PHP Developers
Edureka!
 

Viewers also liked (20)

PPTX
Introduction the Repository Pattern
Bill Lin
 
PPTX
Dependency injection in asp.net core
Bill Lin
 
PPT
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Svetlin Nakov
 
PPTX
Layered Software Architecture
Lars-Erik Kindblad
 
PPTX
ASP.NET MVC and Entity Framework 4
James Johnson
 
DOCX
Generic Repository Pattern in MVC3 Application with Entity Framework
Akhil Mittal
 
PPTX
Generic Unit Of Work Service & Repository
Abdulah Al Bahhar
 
PDF
Object Oriented Programming
Md. Mahedee Hasan
 
PPTX
Domain Driven Design in Rails
Hans Yu
 
PPSX
C# - Part 1
Md. Mahedee Hasan
 
PPTX
Entity Framework Database and Code First
James Johnson
 
PPTX
Dapper performance
Suresh Loganatha
 
PDF
The world of enterprise solution development with asp.net and C#
Md. Mahedee Hasan
 
PPTX
EF6 or EF Core? How Do I Choose?
Julie Lerman
 
PPTX
A Tour of EF Core's (1.1) Most Interesting & Important Features
Julie Lerman
 
PPSX
MS SQL Server
Md. Mahedee Hasan
 
PDF
Introduction to OMNeT++
Md. Mahedee Hasan
 
PPTX
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
PDF
Introduction to TFS 2013
Md. Mahedee Hasan
 
PPTX
Repository design pattern in laravel - Samir Poudel
Sameer Poudel
 
Introduction the Repository Pattern
Bill Lin
 
Dependency injection in asp.net core
Bill Lin
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Svetlin Nakov
 
Layered Software Architecture
Lars-Erik Kindblad
 
ASP.NET MVC and Entity Framework 4
James Johnson
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Akhil Mittal
 
Generic Unit Of Work Service & Repository
Abdulah Al Bahhar
 
Object Oriented Programming
Md. Mahedee Hasan
 
Domain Driven Design in Rails
Hans Yu
 
C# - Part 1
Md. Mahedee Hasan
 
Entity Framework Database and Code First
James Johnson
 
Dapper performance
Suresh Loganatha
 
The world of enterprise solution development with asp.net and C#
Md. Mahedee Hasan
 
EF6 or EF Core? How Do I Choose?
Julie Lerman
 
A Tour of EF Core's (1.1) Most Interesting & Important Features
Julie Lerman
 
MS SQL Server
Md. Mahedee Hasan
 
Introduction to OMNeT++
Md. Mahedee Hasan
 
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
Introduction to TFS 2013
Md. Mahedee Hasan
 
Repository design pattern in laravel - Samir Poudel
Sameer Poudel
 
Ad

Similar to Generic repository pattern with ASP.NET MVC and Entity Framework (20)

DOCX
Repository Pattern in MVC3 Application with Entity Framework
Akhil Mittal
 
PPTX
La sql
James Johnson
 
PDF
An Introduction to Enterprise Design Patterns
Adam Stephensen
 
PPTX
Design patterns
Ahmed Elharouny
 
PPTX
Most Useful Design Patterns
Steven Smith
 
PPTX
Design pattern of software words computer .pptx
muslimpari2503
 
PPT
5 Design Patterns Explained
Prabhjit Singh
 
PPTX
Day5
madamewoolf
 
PPTX
Women Who Code Belfast: Introduction to Design patterns
Jackie Pollock
 
PPTX
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Steven Smith
 
PPTX
Structure mapping your way to better software
matthoneycutt
 
PPTX
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Steven Smith
 
PPTX
L09 Frameworks
Ólafur Andri Ragnarsson
 
PPTX
MVC and Entity Framework 4
James Johnson
 
PDF
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Akhil Mittal
 
PPTX
Some Cool Design Patterns, Practices, and Principles
itsarsalan
 
PPTX
L05 Frameworks
Ólafur Andri Ragnarsson
 
PPTX
Introduction to Design Patterns
Prageeth Sandakalum
 
PPTX
Design patterns - The Good, the Bad, and the Anti-Pattern
Barry O Sullivan
 
PPTX
MVC Website Pattern The Controller, Task, Repository, Command Pattern
andrewjutton
 
Repository Pattern in MVC3 Application with Entity Framework
Akhil Mittal
 
An Introduction to Enterprise Design Patterns
Adam Stephensen
 
Design patterns
Ahmed Elharouny
 
Most Useful Design Patterns
Steven Smith
 
Design pattern of software words computer .pptx
muslimpari2503
 
5 Design Patterns Explained
Prabhjit Singh
 
Women Who Code Belfast: Introduction to Design patterns
Jackie Pollock
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Steven Smith
 
Structure mapping your way to better software
matthoneycutt
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Steven Smith
 
L09 Frameworks
Ólafur Andri Ragnarsson
 
MVC and Entity Framework 4
James Johnson
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Akhil Mittal
 
Some Cool Design Patterns, Practices, and Principles
itsarsalan
 
L05 Frameworks
Ólafur Andri Ragnarsson
 
Introduction to Design Patterns
Prageeth Sandakalum
 
Design patterns - The Good, the Bad, and the Anti-Pattern
Barry O Sullivan
 
MVC Website Pattern The Controller, Task, Repository, Command Pattern
andrewjutton
 
Ad

More from Md. Mahedee Hasan (9)

PPTX
Azure Machine Learning
Md. Mahedee Hasan
 
PPTX
Chatbot development with Microsoft Bot Framework and LUIS
Md. Mahedee Hasan
 
PPTX
Chatbot development with Microsoft Bot Framework
Md. Mahedee Hasan
 
PPTX
ASP.NET MVC Zero to Hero
Md. Mahedee Hasan
 
PPTX
Introduction to Windows 10 IoT Core
Md. Mahedee Hasan
 
PPTX
Whats new in visual studio 2017
Md. Mahedee Hasan
 
PPTX
Increasing productivity using visual studio 2017
Md. Mahedee Hasan
 
PPSX
Exciting features in visual studio 2017
Md. Mahedee Hasan
 
PPSX
ASP.NET Web form
Md. Mahedee Hasan
 
Azure Machine Learning
Md. Mahedee Hasan
 
Chatbot development with Microsoft Bot Framework and LUIS
Md. Mahedee Hasan
 
Chatbot development with Microsoft Bot Framework
Md. Mahedee Hasan
 
ASP.NET MVC Zero to Hero
Md. Mahedee Hasan
 
Introduction to Windows 10 IoT Core
Md. Mahedee Hasan
 
Whats new in visual studio 2017
Md. Mahedee Hasan
 
Increasing productivity using visual studio 2017
Md. Mahedee Hasan
 
Exciting features in visual studio 2017
Md. Mahedee Hasan
 
ASP.NET Web form
Md. Mahedee Hasan
 

Recently uploaded (20)

PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 

Generic repository pattern with ASP.NET MVC and Entity Framework

  • 1. Generic Repository Pattern with ASP.NET MVC and EF Md. Mahedee Hasan Microsoft MVP | Trainer | Speaker Software Architect LeadSoft Bangladesh Limited Linkedin: http://www.linkedin.com/in/mahedee Blog: http://mahedee.net/ 1
  • 2. • MVC Stands for Model – View – Controller • It is Software Architectural pattern MAHEDEE.NET 2 What is MVC?
  • 3. • Is an open source web application framework • It implements the model-view-controller pattern • MVC design pattern aims to “Separation Of concern” MAHEDEE.NET 3 What is ASP.NET MVC?
  • 4. • Entity Framework is an ORM. • Work with relational data using domain-specific objects • Eliminates the need for most of the data-access code MAHEDEE.NET 4 What is ASP.NET EF?
  • 5. DRY? Don’t repeat yourself -Means don't write duplicate code Use generic repository pattern to implement DRY MAHEDEE.NET 5
  • 6. • What is Design Pattern? • Design pattern is a solution of known problems • What is Software Design Pattern? • Is a solution of known problems in Software. • Strategies of solving commonly occurring problems. • A design pattern is not a finish design. • It is like a template to solve a problem. MAHEDEE.NET 6 Software Design Pattern
  • 7. Repository Pattern • Mediator between BLL and DAL(Data Source) • It’s a separation layer between Data and Domain Layer – Separates data and domain Layer MAHEDEE.NET 7
  • 8. Benefits of Repository Pattern • Centralizes data logic or service logic. • Provides a substitution point for the unit tests – Both BLL and DAL • Provides a flexible architecture – Can adopt new change easily • Domain driven development is easier MAHEDEE.NET 8
  • 9. What is Generic Repository Pattern? • Generally - one repository for one model to access data. – Write similar code again and again • What if Single Repository for all? • Single repository for data access of all models. MAHEDEE.NET 9
  • 10. Benefits of Generic Repository Pattern • Reduce redundancy of code • Faster development • Force developer to work same pattern – Possibility of less error or no error • Easy to maintain – Centralize data access logic MAHEDEE.NET 10
  • 11. Implementation • Tools and Technology used – Visual Studio 2013 – Visual C# – ASP.NET MVC 5 – Entity Framework 6 – Razor view engine MAHEDEE.NET 11
  • 12. Step 1: Create an ASP.NET MVC 5 application using Visual Studio 2013 MAHEDEE.NET 12 Implementation…
  • 13. Step 2: Configure connection string in web.config MAHEDEE.NET 13 Implementation …
  • 14. Step 3: Create Models MAHEDEE.NET 14 Implementation …
  • 15. Step 4: Create a DbContext in Repository folder. MAHEDEE.NET 15 Implementation …
  • 16. Step 5: Create IGenericRepository and GenericRepository in Repository folder MAHEDEE.NET 16 Implementation …
  • 17. • Step 6: – Create controllers of each models – Select template “MVC5 Controller with views, using Entity Framework” – Modify Controllers and use Generic Repository in Controller MAHEDEE.NET 17 Implementation …
  • 18. • Step 7: Add links to _Layout MAHEDEE.NET 18 Implementation …
  • 19. • Step 8: Write following command in package manager console – PM> Enable-Migrations -ContextTypeName GenericRepoContext – PM> Add-Migration initialcreate – PM> Update-Database -Verbose -Force MAHEDEE.NET 19 Implementation …
  • 20. Step 9: Run Project MAHEDEE.NET 20 Implementation …
  • 21. 21