SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
ENTITY FRAMEWORK
Mr. Hasan Baloch
Mr. Jibran Rasheed Khan
Mr. Sehan Ahmed Farooqui
OUTLINE
• Introduction to Entity Framework (EF)
• Architecture
• What’s new!
• Different approaches to work with
• Choosing right work model
• Pictorial Tour to each model
• Features & Advantages
• Question & Answer
WHAT IS ENTITY FRAMEWORK???
• EF is a data access framework from Microsoft that helps to bridge the
gap between data structures and objects in your applications.
• It is an ORM framework.
• Enhancement to ADO.NET that gives automated mechanism for accessing
& storing in the database.
• Microsoft’s latest and recommended way for data access for .NET
applications.
ENTITY FRAMEWORK ARCHITECTURE
• EDM, Consists of Conceptual model, Mapping and Storage model.
• LINQ to Entities, Used to write queries against the object
model.
• Entity SQL, like L2E, but little more difficult.
• Object Service, Responsible for materialization.
• ECDP, Responsible to convert L2E or Entity SQL queries into a SQL
query.
• ADO.net, Communicates with the database using standard ADO
What’s new in EF 5
• Become Open Source
• Enum Support
• Spatial Data Types using DbGeography and DbGeometry classes.
• Table-Valued functions support
• Performance Enhancements
• Designer Improvement
• Better Query Performance
• Code First to add new tables to existing Db
ENTITY FRAMEWORK APPROACHES
DATABASE FIRST
Model the database artifacts
(tables, views, primary keys,
foreign keys, etc.)
Allows you to use legacy database
in your ORM application
Low level control over the
database
Entity Data Model can be updated
whenever database schema
changes.
Database-first approach supports
stored procedure, view, etc.
MODEL FIRST
Creating a model using the Entity
Framework designer tools
Designer can generate DDL
statements to create the database
An easy-to-use UI allows quickly
create new entities
Separation of code and database in
a declarative format
Dropping and re-creating the
database is not a choice
This uses an .EDMX file to store
model and mapping information.
CODE FIRST
The primary focus is getting the
code and logic
Define entity model with classes
and mappings in code..
Entity Framework create (and
recreate) the database for you.
Does not use Entity Framework
visual design tool, neither to design
entities
There is no XML file – no EDMX file –
to represent model and storage
schemas
CHOOSING
RIGHT WORK
MODEL
DATABASE FIRST
PICTORIAL TOUR
HOW TOs
The steps involved in this example are as follows:
Create the new SQL Server database
Create the database objects
Create a new C# Class Library Project in Visual Studio 2012 Solution
Add a new ADO.NET Entity Data Model to project
Create a new Database Connection
Import the database objects into the EDM
Modify the EDM to accommodate the scalar-valued functions
01
02
03
04 05
06
07 08
09
12
11
10
MODEL FIRST
PICTORIAL TOUR
HOW TOs
The steps involved in this example are as follows:
Creating the model
Creating entities in the .edmx
Editing entity properties
Applying relationships to the entities
 Name DatabaseSchema
Generating the database from the model
01 03
02
06
05
04
090807
10
11
12
1514
13
16 17 18
19 20 21
CODE FIRST
PICTORIAL TOUR
HOW TOs
The steps involved in this example are as follows:
Create a new Class Library
Create POCO (Plain Old CLR Object) classes
Add data annotations to the POCO classes.
Create enum classes (if required)
Add Entity Framework to the Solution
Add a DbContext class
Add ‘Code First Migrations’
Updates the database (if needed/made changes)
01 02
0304
04 05
06
07
FEATURES
• Works with a variety of database servers (including Microsoft SQL server, oracle,
and DB2)
• Rich mapping engine handle real-world database and work with stored procedure
• Generates strongly-typed entity objects that can be customized beyond 1-1
mapping
• Generates mapping/plumbing code
• Translates LINQ queries to database queries
• Materializes objects from data store calls
• Tracks changes, generating updates/inserts
Advantages
• Reduced development time
• Developers can work more application-centric
• Free from hard-coded dependencies on a particular data engine
• Mappings can be change without changing the application code
• L2Eprovides validation for writing queries against a conceptual model
• Integrates with all the .NET application programming models
• Worked well with ASP.NET, WPF, WCF, and WCF Data Services
Question & Answer
“A wise man can learn more from a foolish question than a fool can
learn from a wise answer.”
Bruce Lee
THANK YOU
Have Great Time

Más contenido relacionado

La actualidad más candente

Java Servlets
Java ServletsJava Servlets
Java Servlets
Nitin Pai
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
Faysal Shaarani (MBA)
 

La actualidad más candente (20)

Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | Edureka
 
MSDN - ASP.NET MVC
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Oracle Forms Introduction
Oracle Forms IntroductionOracle Forms Introduction
Oracle Forms Introduction
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 

Destacado

Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
Beyond Gamification: designing the player journey
Beyond Gamification: designing the player journeyBeyond Gamification: designing the player journey
Beyond Gamification: designing the player journey
Amy Jo Kim
 
.NET Framework Overview
.NET Framework Overview.NET Framework Overview
.NET Framework Overview
Doncho Minkov
 

Destacado (17)

Nakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - EnglishNakov - .NET Framework Overview - English
Nakov - .NET Framework Overview - English
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)
 
Beyond Gamification: designing the player journey
Beyond Gamification: designing the player journeyBeyond Gamification: designing the player journey
Beyond Gamification: designing the player journey
 
.net framework from 1.0 -> 4.0
.net framework from 1.0 -> 4.0.net framework from 1.0 -> 4.0
.net framework from 1.0 -> 4.0
 
Deep-dive building solutions on the SharePoint Framework
Deep-dive building solutions on the SharePoint FrameworkDeep-dive building solutions on the SharePoint Framework
Deep-dive building solutions on the SharePoint Framework
 
Introducing Entity Framework 4.0
Introducing Entity Framework 4.0Introducing Entity Framework 4.0
Introducing Entity Framework 4.0
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
.NET Framework Overview
.NET Framework Overview.NET Framework Overview
.NET Framework Overview
 
Data modelling 101
Data modelling 101Data modelling 101
Data modelling 101
 
A Comparison of .NET Framework vs. Java Virtual Machine
A Comparison of .NET Framework vs. Java Virtual MachineA Comparison of .NET Framework vs. Java Virtual Machine
A Comparison of .NET Framework vs. Java Virtual Machine
 
Beautiful Mind: iPhone Anatomy & Architecture
Beautiful Mind: iPhone Anatomy & ArchitectureBeautiful Mind: iPhone Anatomy & Architecture
Beautiful Mind: iPhone Anatomy & Architecture
 
Евгений Напрягло ".NET Framework Hosting API Overview"
Евгений Напрягло ".NET Framework Hosting API Overview"Евгений Напрягло ".NET Framework Hosting API Overview"
Евгений Напрягло ".NET Framework Hosting API Overview"
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Entity Framework
Entity FrameworkEntity Framework
Entity Framework
 
Components of .NET Framework
Components of .NET FrameworkComponents of .NET Framework
Components of .NET Framework
 

Similar a Learn Entity Framework in a day with Code First, Model First and Database First

Be04 introduction to ef 6.0
Be04   introduction to ef 6.0Be04   introduction to ef 6.0
Be04 introduction to ef 6.0
DotNetCampus
 

Similar a Learn Entity Framework in a day with Code First, Model First and Database First (20)

70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Ef overview
Ef overviewEf overview
Ef overview
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
Entity Framework Core 1.0
Entity Framework Core 1.0Entity Framework Core 1.0
Entity Framework Core 1.0
 
05 entity framework
05 entity framework05 entity framework
05 entity framework
 
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
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Be04 introduction to ef 6.0
Be04   introduction to ef 6.0Be04   introduction to ef 6.0
Be04 introduction to ef 6.0
 
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 Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
Microsoft Data Access Technologies
Microsoft Data Access TechnologiesMicrosoft Data Access Technologies
Microsoft Data Access Technologies
 
Data virtualization, Data Federation & IaaS with Jboss Teiid
Data virtualization, Data Federation & IaaS with Jboss TeiidData virtualization, Data Federation & IaaS with Jboss Teiid
Data virtualization, Data Federation & IaaS with Jboss Teiid
 
ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4
 
Building a Testable Data Access Layer
Building a Testable Data Access LayerBuilding a Testable Data Access Layer
Building a Testable Data Access Layer
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Learn Entity Framework in a day with Code First, Model First and Database First

  • 1. ENTITY FRAMEWORK Mr. Hasan Baloch Mr. Jibran Rasheed Khan Mr. Sehan Ahmed Farooqui
  • 2. OUTLINE • Introduction to Entity Framework (EF) • Architecture • What’s new! • Different approaches to work with • Choosing right work model • Pictorial Tour to each model • Features & Advantages • Question & Answer
  • 3. WHAT IS ENTITY FRAMEWORK??? • EF is a data access framework from Microsoft that helps to bridge the gap between data structures and objects in your applications. • It is an ORM framework. • Enhancement to ADO.NET that gives automated mechanism for accessing & storing in the database. • Microsoft’s latest and recommended way for data access for .NET applications.
  • 4. ENTITY FRAMEWORK ARCHITECTURE • EDM, Consists of Conceptual model, Mapping and Storage model. • LINQ to Entities, Used to write queries against the object model. • Entity SQL, like L2E, but little more difficult. • Object Service, Responsible for materialization. • ECDP, Responsible to convert L2E or Entity SQL queries into a SQL query. • ADO.net, Communicates with the database using standard ADO
  • 5. What’s new in EF 5 • Become Open Source • Enum Support • Spatial Data Types using DbGeography and DbGeometry classes. • Table-Valued functions support • Performance Enhancements • Designer Improvement • Better Query Performance • Code First to add new tables to existing Db
  • 6. ENTITY FRAMEWORK APPROACHES DATABASE FIRST Model the database artifacts (tables, views, primary keys, foreign keys, etc.) Allows you to use legacy database in your ORM application Low level control over the database Entity Data Model can be updated whenever database schema changes. Database-first approach supports stored procedure, view, etc. MODEL FIRST Creating a model using the Entity Framework designer tools Designer can generate DDL statements to create the database An easy-to-use UI allows quickly create new entities Separation of code and database in a declarative format Dropping and re-creating the database is not a choice This uses an .EDMX file to store model and mapping information. CODE FIRST The primary focus is getting the code and logic Define entity model with classes and mappings in code.. Entity Framework create (and recreate) the database for you. Does not use Entity Framework visual design tool, neither to design entities There is no XML file – no EDMX file – to represent model and storage schemas
  • 9. HOW TOs The steps involved in this example are as follows: Create the new SQL Server database Create the database objects Create a new C# Class Library Project in Visual Studio 2012 Solution Add a new ADO.NET Entity Data Model to project Create a new Database Connection Import the database objects into the EDM Modify the EDM to accommodate the scalar-valued functions
  • 15. HOW TOs The steps involved in this example are as follows: Creating the model Creating entities in the .edmx Editing entity properties Applying relationships to the entities  Name DatabaseSchema Generating the database from the model
  • 21. 16 17 18 19 20 21
  • 23. HOW TOs The steps involved in this example are as follows: Create a new Class Library Create POCO (Plain Old CLR Object) classes Add data annotations to the POCO classes. Create enum classes (if required) Add Entity Framework to the Solution Add a DbContext class Add ‘Code First Migrations’ Updates the database (if needed/made changes)
  • 26. 07
  • 27. FEATURES • Works with a variety of database servers (including Microsoft SQL server, oracle, and DB2) • Rich mapping engine handle real-world database and work with stored procedure • Generates strongly-typed entity objects that can be customized beyond 1-1 mapping • Generates mapping/plumbing code • Translates LINQ queries to database queries • Materializes objects from data store calls • Tracks changes, generating updates/inserts
  • 28. Advantages • Reduced development time • Developers can work more application-centric • Free from hard-coded dependencies on a particular data engine • Mappings can be change without changing the application code • L2Eprovides validation for writing queries against a conceptual model • Integrates with all the .NET application programming models • Worked well with ASP.NET, WPF, WCF, and WCF Data Services
  • 29. Question & Answer “A wise man can learn more from a foolish question than a fool can learn from a wise answer.” Bruce Lee