SlideShare una empresa de Scribd logo
1 de 21
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

Más contenido relacionado

La actualidad más candente (20)

Reactjs
Reactjs Reactjs
Reactjs
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
.Net Core
.Net Core.Net Core
.Net Core
 
React Native
React NativeReact Native
React Native
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Web development | Derin Dolen
Web development | Derin Dolen Web development | Derin Dolen
Web development | Derin Dolen
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
React Context API
React Context APIReact Context API
React Context API
 
Linq
LinqLinq
Linq
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Ppt of web development
Ppt of web developmentPpt of web development
Ppt of web development
 
Introduction to MERN Stack
Introduction to MERN StackIntroduction to MERN Stack
Introduction to MERN Stack
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
WEB DEVELOPMENT USING REACT JS
 WEB DEVELOPMENT USING REACT JS WEB DEVELOPMENT USING REACT JS
WEB DEVELOPMENT USING REACT JS
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
 

Destacado

The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#Md. Mahedee Hasan
 
Generic Unit Of Work Service & Repository
Generic Unit Of Work Service & RepositoryGeneric Unit Of Work Service & Repository
Generic Unit Of Work Service & RepositoryAbdulah Al Bahhar
 
Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...Christoffer Sabsay
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelSameer Poudel
 
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...Richelle Malapit
 
Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Naji El Kotob
 
Mailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетингMailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетингMailer
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository PatternBill Lin
 
Grudinkina EmailConf 2016
Grudinkina EmailConf 2016Grudinkina EmailConf 2016
Grudinkina EmailConf 2016Mailer
 
Elizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing toolElizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing toolepverar
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web FormsSAMIR BHOGAYTA
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)Chitrank Dixit
 

Destacado (20)

The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#
 
Generic Unit Of Work Service & Repository
Generic Unit Of Work Service & RepositoryGeneric Unit Of Work Service & Repository
Generic Unit Of Work Service & Repository
 
Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...
 
Oop principles
Oop principlesOop principles
Oop principles
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir Poudel
 
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
 
Site map
Site mapSite map
Site map
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1
 
Mailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетингMailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетинг
 
MailerLite Tutorial
MailerLite TutorialMailerLite Tutorial
MailerLite Tutorial
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository Pattern
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
A View about ASP .NET and their objectives
 
Grudinkina EmailConf 2016
Grudinkina EmailConf 2016Grudinkina EmailConf 2016
Grudinkina EmailConf 2016
 
Introduction to OMNeT++
Introduction to OMNeT++Introduction to OMNeT++
Introduction to OMNeT++
 
Elizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing toolElizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing tool
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web Forms
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 

Similar a Generic Repository Pattern with ASP.NET MVC and EF

Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerIntroduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerAgusto Sipahutar
 
Asp.net Overview and Controllers
Asp.net Overview and ControllersAsp.net Overview and Controllers
Asp.net Overview and ControllersMustafa Saeed
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncubeMalisa Ncube
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVMJiri Danihelka
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overviewumesh patil
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterPongsakorn U-chupala
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesUlrich Krause
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCSirwan Afifi
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCUlrich Krause
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Thomas Robbins
 

Similar a Generic Repository Pattern with ASP.NET MVC and EF (20)

Ps02 cint24 mvc in php
Ps02 cint24 mvc in phpPs02 cint24 mvc in php
Ps02 cint24 mvc in php
 
MVC 3.0 KU Day 1 v 1.1
MVC 3.0 KU Day 1 v 1.1MVC 3.0 KU Day 1 v 1.1
MVC 3.0 KU Day 1 v 1.1
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
 
Php Framework
Php FrameworkPhp Framework
Php Framework
 
Php framework
Php frameworkPhp framework
Php framework
 
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerIntroduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
 
Asp.net Overview and Controllers
Asp.net Overview and ControllersAsp.net Overview and Controllers
Asp.net Overview and Controllers
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVM
 
green
greengreen
green
 
Php and-mvc
Php and-mvcPhp and-mvc
Php and-mvc
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overview
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
ASP.NET MVC Zero to Hero
ASP.NET MVC Zero to HeroASP.NET MVC Zero to Hero
ASP.NET MVC Zero to Hero
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 

Más de Md. Mahedee Hasan

Chatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUISChatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUISMd. Mahedee Hasan
 
Chatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot FrameworkChatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot FrameworkMd. Mahedee Hasan
 
Introduction to Windows 10 IoT Core
Introduction to Windows 10 IoT CoreIntroduction to Windows 10 IoT Core
Introduction to Windows 10 IoT CoreMd. Mahedee Hasan
 
Whats new in visual studio 2017
Whats new in visual studio 2017Whats new in visual studio 2017
Whats new in visual studio 2017Md. Mahedee Hasan
 
Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017Md. Mahedee Hasan
 
Exciting features in visual studio 2017
Exciting features in visual studio 2017Exciting features in visual studio 2017
Exciting features in visual studio 2017Md. Mahedee Hasan
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkMd. Mahedee Hasan
 
Feature and Future of ASP.NET
Feature and Future of ASP.NETFeature and Future of ASP.NET
Feature and Future of ASP.NETMd. Mahedee Hasan
 
C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3Md. Mahedee Hasan
 

Más de Md. Mahedee Hasan (14)

Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
 
Chatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUISChatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUIS
 
Chatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot FrameworkChatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot Framework
 
Introduction to Windows 10 IoT Core
Introduction to Windows 10 IoT CoreIntroduction to Windows 10 IoT Core
Introduction to Windows 10 IoT Core
 
Whats new in visual studio 2017
Whats new in visual studio 2017Whats new in visual studio 2017
Whats new in visual studio 2017
 
Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017
 
Exciting features in visual studio 2017
Exciting features in visual studio 2017Exciting features in visual studio 2017
Exciting features in visual studio 2017
 
Introduction to TFS 2013
Introduction to TFS 2013Introduction to TFS 2013
Introduction to TFS 2013
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity Framework
 
Feature and Future of ASP.NET
Feature and Future of ASP.NETFeature and Future of ASP.NET
Feature and Future of ASP.NET
 
C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 

Último

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 

Último (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

Generic Repository Pattern with ASP.NET MVC and EF

  • 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

Notas del editor

  1. DRY – Object Oriented design Principle. Ex. Dept Info in several code
  2. DRY – Object Oriented design Principle. Ex. Dept Info in several code
  3. DRY – Object Oriented design Principle. Ex. Dept Info in several code
  4. Create Designation and Employee Model in model folder Describe model and annotation
  5. DbContext: Simplified alternative to ObjectContext and is the primary object for interacting with a database using a specified model. DbSet: Simplified alternative to ObjectSet and is used to perform CRUD operations against a specific type from the model
  6. It's a type constraint on T , specifying that it must be a class.
  7. Create Designation Controller and Employee Controller. First Add designation and then Employee. Look corresponding view