SlideShare una empresa de Scribd logo
1 de 56
Entity Framework
Agenda
● ORM
● EF Modelling
● LINQ
● EF Inheritance
● EF Concurrency
Why Database Layer
Object Impedance Mismatch - RDBMS and OOP
Object Conversions - RDBMS to OOP and OOP to RDBMS
Needs Easy Conversion Process - Rise of ORM
ORM?
Many Frameworks - EF, NH, LINQ to SQL
RDBMS to NoSQL Support
Single RDBMS Support to Various RDBMS Support
DB Layer Uniformity Across the Organization
Entity Framework - Roadmap
EF - Key Terms
Entity
Context - Object Context, Db Context
Deferred Execution
POCO - Plain Old CLR Object
LINQ to Entities, Entity SQL
Mapping, Conceptual Model, Storage Model
Projections
EF - Resultant Objects
IEnumerable vs IQueryable
EF - Loading
Lazy, Eager Loading and Explicit Loading
Loading Navigation Properties
1. LazyLoadingEnabled = true
2. LazyLoadingEnabled = false & Include(“{Navigation Property}”)
3. LazyLoadingEnabled = false & {Navigation Property}.Load()
Modelling - .edmx
Modelling - .edmx - Types
Database First
Model First
Modelling - Database First
Reverse engineer model in EF Designer
Classes auto-generated from model
Preferred approach for existing database
Hands On
Database First - Tables, Stored Procedures, Views, Functions
Update Model
Modelling - Model First
Create model in EF Designer
Generate database from model
Classes auto-generated from model
Preferred approach for new database.
Hands On
Model First - Create Model, Generate Database
Update Model
Modelling - Code First
Define classes and mapping in code
Database created from code
Migrations apply model changes to database
Preferred approach for new database. Generally
preferred in Agile/Scrum
Modelling - Fluent Api, Configuration and Conventions
Fluent Api - Chaining Api
Configuration with Fluent Api
Conventions
Hands On
Code First - Create Classes with Conventions only
Database Generation
Database Migration
EF - CRUD
EF - Read Operation
EF - Create - Single Record
EF - Create - Multiple Records
EF - Update Record
EF - Delete Record
Homework
AddressBook - Design Db and Do CRUD operations on all entities
EF - LINQ
Filtering, Ordering
Joining
Grouping
EF - LINQ - Filtering, Ordering
EF - LINQ - Joining
EF - LINQ - Grouping
Homework
Full Outer Join Possible?
Use of “let” variable
EF - Code First
Conventions
Data Annotations
FluentApi
EF - Code First - Conventions
Convention: Table Name
Default: Entity + s (e.g Users)
Convention: Primary Key
Default: Id
Convention: Foreign Key Relation
Default: Entity + Id (e.g SubscriptionId)
EF - Code First - Data Annotations
Annotation: Table
=> Table(“{Name”})
Annotation: Key
=> Key
Annotation: ForeignKey
=> ForeignKey(“{Navigation Property”})
=> ForeignKey(“{Property”})
EF - Code First - Fluent Api
Homework
AddressBook - Design Db and Do CRUD operations on all entities
Executing Raw SQL - Plain, Stored Procedures
EF - Inheritance Strategy - TPH
EF - Inheritance Strategy - TPH
Needs a column, discriminator, that will used to identify exact type.
Retrieving Type in TPH
Code First Configuration
Gives better performance but there are many duplicate data and nullable columns.
EF - Inheritance Strategy - TPT
EF - Inheritance Strategy - TPT
Each entity maps to table. So CUD operations are faster
Code First Configuration
Retrieval is slower than TPH as it needs joins with base class/table.
EF - Inheritance Strategy - TPC
EF - Inheritance Strategy - TPC
Each concrete entity maps to table.
Code First Configuration
Properties of abstract entity are combined with concrete entity and many data/columns duplications.
EDMX designer does not support this mapping. Manual modification is required.
EF - Relationships
One to One
One to Many
Many to Many
EF - Relationships - One to One
EF - Relationships - One to Many
EF - Relationships - Many to Many
Hands On
One to One
One to Many
Many to Many
EF - Concurrency
Optimistic
Pessimistic
EF - Concurrency - Optimistic
None: Default and there is no concurrency
Fixed: Original value of concurrency column is included in where part while generating SQL
Rows are not locked. Read operation can be never locked
EF - Concurrency - Optimistic
Sample Code
EF - Concurrency - Pessimistic
Involves database locking operations. So it is slow
Use Transaction to achieve it
Read operation can be locked
Questions
Thank you
EF - Advance
Table Splitting
After little bit experience, it is worth
Bounded Contexts
After little bit experience, it is worth
EF - Unit Testing
After little bit experience, it is worth
EF - Patterns
After little bit experience, it is worth

Más contenido relacionado

La actualidad más candente

Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
Confiz
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
Samnang Chhun
 
Introduction to NHibernate
Introduction to NHibernateIntroduction to NHibernate
Introduction to NHibernate
Dublin Alt,Net
 
NHibernate for .NET
NHibernate for .NETNHibernate for .NET
NHibernate for .NET
Guo Albert
 

La actualidad más candente (20)

Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Entity Framework - Object Services
Entity Framework -  Object ServicesEntity Framework -  Object Services
Entity Framework - Object Services
 
Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
 
Object Relational model for SQLIite in android
Object Relational model for SQLIite  in android Object Relational model for SQLIite  in android
Object Relational model for SQLIite in android
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Introduction Of Linq , ASP.NET Training Ahmedabad, ASP.NET Course Ahmedabad
Introduction Of Linq , ASP.NET Training Ahmedabad, ASP.NET Course AhmedabadIntroduction Of Linq , ASP.NET Training Ahmedabad, ASP.NET Course Ahmedabad
Introduction Of Linq , ASP.NET Training Ahmedabad, ASP.NET Course Ahmedabad
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
 
Introduction to NHibernate
Introduction to NHibernateIntroduction to NHibernate
Introduction to NHibernate
 
.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15
 
NHibernate for .NET
NHibernate for .NETNHibernate for .NET
NHibernate for .NET
 
Core Data
Core DataCore Data
Core Data
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
 
AAC Room
AAC RoomAAC Room
AAC Room
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 
Advanced Core Data
Advanced Core DataAdvanced Core Data
Advanced Core Data
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 

Destacado (12)

Maven ii
Maven iiMaven ii
Maven ii
 
Simple web service vm
Simple web service vmSimple web service vm
Simple web service vm
 
Mi cerebro y yo – el dinero
Mi cerebro y yo – el dineroMi cerebro y yo – el dinero
Mi cerebro y yo – el dinero
 
El marginalismo
El marginalismoEl marginalismo
El marginalismo
 
SREEJITH_CV
SREEJITH_CVSREEJITH_CV
SREEJITH_CV
 
Recursamiento diseña-y-administra-plataformas-e-learning
Recursamiento diseña-y-administra-plataformas-e-learningRecursamiento diseña-y-administra-plataformas-e-learning
Recursamiento diseña-y-administra-plataformas-e-learning
 
Jenkins3
Jenkins3Jenkins3
Jenkins3
 
Moss-Adams_2012-Corp-Social-Responsibility-Report
Moss-Adams_2012-Corp-Social-Responsibility-ReportMoss-Adams_2012-Corp-Social-Responsibility-Report
Moss-Adams_2012-Corp-Social-Responsibility-Report
 
Trabajo de cultura ciudadana
Trabajo de cultura ciudadanaTrabajo de cultura ciudadana
Trabajo de cultura ciudadana
 
John keynes
John keynesJohn keynes
John keynes
 
Shamal Solutions resume
Shamal Solutions resumeShamal Solutions resume
Shamal Solutions resume
 
Caching and invalidating with managed store
Caching and invalidating with managed storeCaching and invalidating with managed store
Caching and invalidating with managed store
 

Similar a Entity Framework

Ado.net entity framework_4.0
Ado.net entity framework_4.0Ado.net entity framework_4.0
Ado.net entity framework_4.0
Rishu Mehra
 
Cakefest higher education
Cakefest higher educationCakefest higher education
Cakefest higher education
therealphpdiddy
 
Ling to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysisLing to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysis
Alexander Konduforov
 

Similar a Entity Framework (20)

Using entity framework core in .net
Using entity framework core in .netUsing entity framework core in .net
Using entity framework core in .net
 
Applying EF Code First at Your Job
Applying EF Code First at Your JobApplying EF Code First at Your Job
Applying EF Code First at Your Job
 
Ado.net entity framework_4.0
Ado.net entity framework_4.0Ado.net entity framework_4.0
Ado.net entity framework_4.0
 
Exceptions are the Norm: Dealing with Bad Actors in ETL
Exceptions are the Norm: Dealing with Bad Actors in ETLExceptions are the Norm: Dealing with Bad Actors in ETL
Exceptions are the Norm: Dealing with Bad Actors in ETL
 
.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16
 
Efficient processing of large and complex XML documents in Hadoop
Efficient processing of large and complex XML documents in HadoopEfficient processing of large and complex XML documents in Hadoop
Efficient processing of large and complex XML documents in Hadoop
 
Cakefest higher education
Cakefest higher educationCakefest higher education
Cakefest higher education
 
Using Apache Spark as ETL engine. Pros and Cons
Using Apache Spark as ETL engine. Pros and Cons          Using Apache Spark as ETL engine. Pros and Cons
Using Apache Spark as ETL engine. Pros and Cons
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0
 
PDI data vault framework #pcmams 2012
PDI data vault framework #pcmams 2012PDI data vault framework #pcmams 2012
PDI data vault framework #pcmams 2012
 
Presentation pdi data_vault_framework_meetup2012
Presentation pdi data_vault_framework_meetup2012Presentation pdi data_vault_framework_meetup2012
Presentation pdi data_vault_framework_meetup2012
 
PostgREST Design Philosophy
PostgREST Design PhilosophyPostgREST Design Philosophy
PostgREST Design Philosophy
 
Tomáš Herceg "Entity Framework Core 2.1 – what’s new?"
Tomáš Herceg "Entity Framework Core 2.1 – what’s new?"Tomáš Herceg "Entity Framework Core 2.1 – what’s new?"
Tomáš Herceg "Entity Framework Core 2.1 – what’s new?"
 
Ling to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysisLing to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysis
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?
 
Application architecture
Application architectureApplication architecture
Application architecture
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 

Último

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
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
VictorSzoltysek
 

Último (20)

10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
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
 
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...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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 kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
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...
 
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
 
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
 
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
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
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 ...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 

Entity Framework

Notas del editor

  1. http://www.codeproject.com/Articles/114262/ways-of-doing-locking-in-NET-Pessimistic-and-opt