SlideShare a Scribd company logo
Prepared By:
Mr. Dhrumil Patel
iFour ConsultancyEntity Framework
 Writing and managing ADO.Net code for data access is a tedious and monotonous job.
Microsoft has provided an O/RM framework called "Entity Framework" to automate
database related activities for your application.
 The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM)
framework that enables developers to work with relational data as domain-specific
objects, eliminating the need for most of the data access plumbing code that developers
usually need to write. Using the Entity Framework, developers issue queries using LINQ,
then retrieve and manipulate data as strongly typed objects. The Entity Framework's ORM
implementation provides services like change tracking, identity resolution, lazy loading,
and query translation so that developers can focus on their application-specific business
logic rather than the data access fundamentals.
Entity Framework
Application Development Company Indiahttp://www.ifourtechnolab.com
 The Entity Framework is a mature ORM from Microsoft and can be used with a wide
variety of databases.
 There are three approaches to modeling entities using Entity Framework:
 Code First
 Database First
 Model First
Entity Framework Approaches
Application Development Company Indiahttp://www.ifourtechnolab.com
 The Code First approach helps you to create the entities in your application by focusing on
the domain requirements.
 In essence, you can follow Domain Driven Design (DDD) using this approach. Once your
entities have been defined and the configurations specified, you can create the database
on the fly using both.
 The Code First approach gives you more control over your code -- you don't need to work
with auto generated code anymore.
 If you have the domain classes ready, you can easily create your database from the domain
classes.
Code First
Application Development Company Indiahttp://www.ifourtechnolab.com
 The downside to this approach is that any changes to the underlying database schema
would be lost; in this approach your code defines and creates the database.
 The Code First approach allows you to use Entity Framework and define the entity model
sans the designer or XML files.
 You can use the POCO (Plain Old CLR Objects) approach to define the model and generate
your database.
 In this approach you would typically create the entity classes. Here's an example; a typical
entity class is given below:
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public float Price { get; set; }
}
Code First (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
 Next, you should define a custom data context by extending the DbContext class as shown
below:
public class IDGContext : DbContext
{
public DbSet<Product> Products { get; set; }
}
 Lastly, you should specify the connection string in the configuration file.
Code First (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
 You can use the Database First approach if the database is already designed and is ready.
 In this approach, the Entity Data Model (EDM) is created from the underlying database.
 As an example, you use the database first approach when you generate the edmx files in
the Visual Studio IDE from the database.
 Manual changes to the database is possible easily and you can always update the EDM if
need be (for example, if the schema of the underlying database changes).
 To do this, simply update the EDM from the database in the Visual Studio IDE.
Database First
Application Development Company Indiahttp://www.ifourtechnolab.com
 In the Model First approach you can create the EDM first, then generate the database
from it.
 You would typically create an empty EDM using the Entity Data Model Wizard in Visual
Studio, define the entities and their relationships in Visual Studio, then generate the
database from this defined model.
 You can easily create entities and define their relationships and associations in the
designer in Visual Studio. You can also specify the Key property and the data types for the
properties for your entities using the designer. You can use partial classes to implement
additional features in your entities.
Model First
Application Development Company Indiahttp://www.ifourtechnolab.com
 OK, but when should you use the Model First approach? Well, if neither the domain
classes nor the database is ready and you would rather define the data model using a
visual designer, this approach is for you. However, like in the Code First approach, in the
Model First approach manual changes to the database would be lost as the model defines
the database.
Model First (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
 Entity framework supports three types of relationships, same as database:
 One to One
 One to Many
 Many to Many
Entity Relationships
Application Development Company Indiahttp://www.ifourtechnolab.com
 As you can see in the above figure, Student and StudentAddress have a One-to-One
relationship (zero or one).
 A student can have only one or zero address. Entity framework adds Student navigation
property into StudentAddress entity and StudentAddress navigation entity into Student
entity.
 Also, StudentAddress entity has StudentId property as PrimaryKey which makes it a
One-to-One relationship.
 As you can see in the below code, Student entity class includes StudentAddress navigation
property and StudentAddress includes Student navigation property with foreign key
property StudentId. This way EF handles one-to-one relationship between entities.
One-To-One Relationship
Application Development Company Indiahttp://www.ifourtechnolab.com
 Example:
public partial class Student
{
public Student()
{
this.Courses = new HashSet<Course>();
}
public int StudentID { get; set; }
public string StudentName { get; set; }
public Nullable<int> StandardId { get; set; }
public byte[] RowVersion { get; set; }
public virtual Standard Standard { get; set; }
public virtual StudentAddress StudentAddress { get; set; }
public virtual ICollection<Course> Courses { get; set; }
}
One-To-One Relationship (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
public partial class StudentAddress
{
public int StudentID { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public virtual Student Student { get; set; }
}
One-To-One Relationship (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
 The Standard and Teacher entities have a One-to-Many relationship marked by multiplicity
where 1 is for One and * is for many. This means that Standard can have many Teachers
whereas Teacher can associate with only one Standard.
 To represent this, The Standard entity has the collection navigation property Teachers
(please notice that it's plural), which indicates that one Standard can have a collection of
Teachers (many teachers). And Teacher entity has a Standard navigation property (Not a
Collection) which indicates that Teacher is associated with one Standard. Also, it contains
StandardId foreign key (StandardId is a PK in Standard entity). This makes it One-to-Many
relationship.
One-To-Many Relationship
Application Development Company Indiahttp://www.ifourtechnolab.com
 Example:
public partial class Standard
{
public Standard()
{
this.Students = new HashSet<Student>();
this.Teachers = new HashSet<Teacher>();
}
public int StandardId { get; set; }
public string StandardName { get; set; }
public string Description { get; set; }
public virtual ICollection<Student> Students { get; set; }
public virtual ICollection<Teacher> Teachers { get; set; }
}
One-To-Many Relationship (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
public partial class Teacher
{
public Teacher()
{
this.Courses = new HashSet<Course>();
}
public int TeacherId { get; set; }
public string TeacherName { get; set; }
public Nullable<int> StandardId { get; set; }
public Nullable<int> TeacherType { get; set; }
public virtual ICollection<Course> Courses { get; set; }
public virtual Standard Standard { get; set; }
}
One-To-Many Relationship (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
 Student and Course have Many-to-Many relationships marked by * multiplicity. It means
one Student can enrol for many Courses and also, one Course can be be taught to many
Students.
 The database design includes StudentCourse joining table which includes the primary key
of both the tables (Student and Course table). Entity Framework represents many-to-many
relationships by not having entityset for the joining table in CSDL, instead it manages this
through mapping.
Many-to-Many Relationship
Application Development Company Indiahttp://www.ifourtechnolab.com
 Example:
public partial class Student
{
public Student()
{
this.Courses = new HashSet<Course>();
}
public int StudentID { get; set; }
public string StudentName { get; set; }
public Nullable<int> StandardId { get; set; }
public byte[] RowVersion { get; set; }
public virtual Standard Standard { get; set; }
public virtual StudentAddress StudentAddress { get; set; }
public virtual ICollection<Course> Courses { get; set; }
}
Many-To-Many Relationship (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
public partial class Course
{
public Course()
{
this.Students = new HashSet<Student>();
}
public int CourseId { get; set; }
public string CourseName { get; set; }
public System.Data.Entity.Spatial.DbGeography Location { get; set; }
public Nullable<int> TeacherId { get; set; }
public virtual Teacher Teacher { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
Many-To-Many Relationship (Cont.)
Application Development Company Indiahttp://www.ifourtechnolab.com
Thank you
Software development company indiahttp://www.ifourtechnolab.com

More Related Content

What's hot

Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
bantamlak dejene
 
Spring FrameWork Tutorials Java Language
Spring FrameWork Tutorials Java Language Spring FrameWork Tutorials Java Language
Spring FrameWork Tutorials Java Language
Mahika Tutorials
 
CSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - ClassesCSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - Classes
DanWooster1
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
Shipra Swati
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
MUHAMMAD FARHAN ASLAM
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
Soba Arjun
 
OOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | IntroductionOOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | Introduction
ADITYATANDONKECCSE
 
Chapter1
Chapter1Chapter1
Chapter1
jammiashok123
 
ObjectRelationalMappingSEPerspective
ObjectRelationalMappingSEPerspectiveObjectRelationalMappingSEPerspective
ObjectRelationalMappingSEPerspectiveTyler Smith
 
Pursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHPPursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHP
Giorgio Sironi
 
7-clean-code
7-clean-code7-clean-code
7-clean-code
Morteza Zakeri
 
Car Showroom management System in c++
Car Showroom management System in c++Car Showroom management System in c++
Car Showroom management System in c++
PUBLIVE
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
Eyal Vardi
 
How to implement dependency injection in c#
How to implement dependency injection in c#How to implement dependency injection in c#
How to implement dependency injection in c#
Priyank Mittal
 
Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)
Eyal Vardi
 
Design patterns
Design patternsDesign patterns
Design patterns
mudabbirwarsi
 

What's hot (20)

Oops Concepts
Oops ConceptsOops Concepts
Oops Concepts
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
 
Spring FrameWork Tutorials Java Language
Spring FrameWork Tutorials Java Language Spring FrameWork Tutorials Java Language
Spring FrameWork Tutorials Java Language
 
CSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - ClassesCSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - Classes
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
 
Technical interview questions
Technical interview questionsTechnical interview questions
Technical interview questions
 
My c++
My c++My c++
My c++
 
JAVA PROGRAMMINGD
JAVA PROGRAMMINGDJAVA PROGRAMMINGD
JAVA PROGRAMMINGD
 
OOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | IntroductionOOPS with C++ | Concepts of OOPS | Introduction
OOPS with C++ | Concepts of OOPS | Introduction
 
Chapter1
Chapter1Chapter1
Chapter1
 
ObjectRelationalMappingSEPerspective
ObjectRelationalMappingSEPerspectiveObjectRelationalMappingSEPerspective
ObjectRelationalMappingSEPerspective
 
Pursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHPPursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHP
 
Birasa 1
Birasa 1Birasa 1
Birasa 1
 
7-clean-code
7-clean-code7-clean-code
7-clean-code
 
Car Showroom management System in c++
Car Showroom management System in c++Car Showroom management System in c++
Car Showroom management System in c++
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
How to implement dependency injection in c#
How to implement dependency injection in c#How to implement dependency injection in c#
How to implement dependency injection in c#
 
Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)
 
Design patterns
Design patternsDesign patterns
Design patterns
 

Viewers also liked

Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
brada
 
Nimble framework
Nimble frameworkNimble framework
Nimble framework
tusjain
 
Domain Driven Design Framework
Domain Driven Design FrameworkDomain Driven Design Framework
Domain Driven Design Framework
Bien Hoang
 
Process Design on Prabandhan Framework
Process Design on Prabandhan FrameworkProcess Design on Prabandhan Framework
Process Design on Prabandhan Framework
Anil Mande
 
Framework for the analysis and design of encryption strategies based on d...
Framework for the analysis and design of encryption strategies     based on d...Framework for the analysis and design of encryption strategies     based on d...
Framework for the analysis and design of encryption strategies based on d...darg0001
 
E learning analysis and design framework
E learning analysis and design frameworkE learning analysis and design framework
E learning analysis and design framework
Eric Kluijfhout
 
OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015
Ryan A. Pavlik
 
Software Engineering - 02. Framework
Software Engineering - 02. FrameworkSoftware Engineering - 02. Framework
Software Engineering - 02. Framework
Arry Arman
 
Design Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex SystemsDesign Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex Systems
drjanroodt
 
Software Frameworks for Music Information Retrieval
Software Frameworks for Music Information RetrievalSoftware Frameworks for Music Information Retrieval
Software Frameworks for Music Information Retrieval
Xavier Amatriain
 
Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014
Luisa Mich
 
How UI Framework improves design process
How UI Framework improves design processHow UI Framework improves design process
How UI Framework improves design process
Marian Mota
 
ADUF - Adaptable Design Up Front
ADUF -  Adaptable Design Up FrontADUF -  Adaptable Design Up Front
ADUF - Adaptable Design Up Front
Hayim Makabee
 
A modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE frameworkA modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE framework
Roberto Dillon
 
Using Environment as a Framework for Urban Design
Using Environment as a Framework for Urban DesignUsing Environment as a Framework for Urban Design
Using Environment as a Framework for Urban Design
Rutgers University
 
How UI Framework improves design process - 2015 (Dribbble meetup)
How UI Framework improves design process - 2015  (Dribbble meetup)How UI Framework improves design process - 2015  (Dribbble meetup)
How UI Framework improves design process - 2015 (Dribbble meetup)
Marian Mota
 
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
shailesh.bohra
 
Frameworks Are The Future of Design
Frameworks  Are The Future of DesignFrameworks  Are The Future of Design
Frameworks Are The Future of Design
Joe Lamantia
 

Viewers also liked (20)

Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
 
Nimble framework
Nimble frameworkNimble framework
Nimble framework
 
Domain Driven Design Framework
Domain Driven Design FrameworkDomain Driven Design Framework
Domain Driven Design Framework
 
Process Design on Prabandhan Framework
Process Design on Prabandhan FrameworkProcess Design on Prabandhan Framework
Process Design on Prabandhan Framework
 
DRE REPORT- 2014 (1)
DRE REPORT- 2014 (1)DRE REPORT- 2014 (1)
DRE REPORT- 2014 (1)
 
Framework for the analysis and design of encryption strategies based on d...
Framework for the analysis and design of encryption strategies     based on d...Framework for the analysis and design of encryption strategies     based on d...
Framework for the analysis and design of encryption strategies based on d...
 
E learning analysis and design framework
E learning analysis and design frameworkE learning analysis and design framework
E learning analysis and design framework
 
OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015OSVR Software Framework - Core - April 2015
OSVR Software Framework - Core - April 2015
 
Software Engineering - 02. Framework
Software Engineering - 02. FrameworkSoftware Engineering - 02. Framework
Software Engineering - 02. Framework
 
Design Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex SystemsDesign Frameworks for Analysis and Synthesis of Complex Systems
Design Frameworks for Analysis and Synthesis of Complex Systems
 
Software Frameworks for Music Information Retrieval
Software Frameworks for Music Information RetrievalSoftware Frameworks for Music Information Retrieval
Software Frameworks for Music Information Retrieval
 
Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014Teaching requirements analysis REET 2014 at RE2014
Teaching requirements analysis REET 2014 at RE2014
 
How UI Framework improves design process
How UI Framework improves design processHow UI Framework improves design process
How UI Framework improves design process
 
ADUF - Adaptable Design Up Front
ADUF -  Adaptable Design Up FrontADUF -  Adaptable Design Up Front
ADUF - Adaptable Design Up Front
 
A modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE frameworkA modern approach to game analysis and design: the AGE framework
A modern approach to game analysis and design: the AGE framework
 
Using Environment as a Framework for Urban Design
Using Environment as a Framework for Urban DesignUsing Environment as a Framework for Urban Design
Using Environment as a Framework for Urban Design
 
How UI Framework improves design process - 2015 (Dribbble meetup)
How UI Framework improves design process - 2015  (Dribbble meetup)How UI Framework improves design process - 2015  (Dribbble meetup)
How UI Framework improves design process - 2015 (Dribbble meetup)
 
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
A Comparative study of Rational Unified process( RUP ), Agile & Microsoft Fra...
 
Frameworks Are The Future of Design
Frameworks  Are The Future of DesignFrameworks  Are The Future of Design
Frameworks Are The Future of Design
 
Design engineering
Design engineeringDesign engineering
Design engineering
 

Similar to Overview of entity framework by software outsourcing company india

Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
Robert J. Stein
 
Data access
Data accessData access
Data access
Joshua Yoon
 
PowerPoint
PowerPointPowerPoint
PowerPointVideoguy
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
Stefano Paluello
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
Brian Lyttle
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
Mahmoud Tolba
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
Darwin Biler
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
James Phillips
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 
C#Portfolio
C#PortfolioC#Portfolio
C#Portfolio
Jeriel_Mikell
 
Design patterns fast track
Design patterns fast trackDesign patterns fast track
Design patterns fast track
Binu Bhasuran
 
Onine exam 1
Onine exam 1Onine exam 1
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
James Johnson
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Enea Gabriel
 

Similar to Overview of entity framework by software outsourcing company india (20)

Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
 
Data access
Data accessData access
Data access
 
PowerPoint
PowerPointPowerPoint
PowerPoint
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
C#Portfolio
C#PortfolioC#Portfolio
C#Portfolio
 
Design patterns fast track
Design patterns fast trackDesign patterns fast track
Design patterns fast track
 
Onine exam 1
Onine exam 1Onine exam 1
Onine exam 1
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 

Overview of entity framework by software outsourcing company india

  • 1. Prepared By: Mr. Dhrumil Patel iFour ConsultancyEntity Framework
  • 2.  Writing and managing ADO.Net code for data access is a tedious and monotonous job. Microsoft has provided an O/RM framework called "Entity Framework" to automate database related activities for your application.  The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write. Using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as strongly typed objects. The Entity Framework's ORM implementation provides services like change tracking, identity resolution, lazy loading, and query translation so that developers can focus on their application-specific business logic rather than the data access fundamentals. Entity Framework Application Development Company Indiahttp://www.ifourtechnolab.com
  • 3.  The Entity Framework is a mature ORM from Microsoft and can be used with a wide variety of databases.  There are three approaches to modeling entities using Entity Framework:  Code First  Database First  Model First Entity Framework Approaches Application Development Company Indiahttp://www.ifourtechnolab.com
  • 4.  The Code First approach helps you to create the entities in your application by focusing on the domain requirements.  In essence, you can follow Domain Driven Design (DDD) using this approach. Once your entities have been defined and the configurations specified, you can create the database on the fly using both.  The Code First approach gives you more control over your code -- you don't need to work with auto generated code anymore.  If you have the domain classes ready, you can easily create your database from the domain classes. Code First Application Development Company Indiahttp://www.ifourtechnolab.com
  • 5.  The downside to this approach is that any changes to the underlying database schema would be lost; in this approach your code defines and creates the database.  The Code First approach allows you to use Entity Framework and define the entity model sans the designer or XML files.  You can use the POCO (Plain Old CLR Objects) approach to define the model and generate your database.  In this approach you would typically create the entity classes. Here's an example; a typical entity class is given below: public class Product { public int ProductId { get; set; } public string ProductName { get; set; } public float Price { get; set; } } Code First (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 6.  Next, you should define a custom data context by extending the DbContext class as shown below: public class IDGContext : DbContext { public DbSet<Product> Products { get; set; } }  Lastly, you should specify the connection string in the configuration file. Code First (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 7.  You can use the Database First approach if the database is already designed and is ready.  In this approach, the Entity Data Model (EDM) is created from the underlying database.  As an example, you use the database first approach when you generate the edmx files in the Visual Studio IDE from the database.  Manual changes to the database is possible easily and you can always update the EDM if need be (for example, if the schema of the underlying database changes).  To do this, simply update the EDM from the database in the Visual Studio IDE. Database First Application Development Company Indiahttp://www.ifourtechnolab.com
  • 8.  In the Model First approach you can create the EDM first, then generate the database from it.  You would typically create an empty EDM using the Entity Data Model Wizard in Visual Studio, define the entities and their relationships in Visual Studio, then generate the database from this defined model.  You can easily create entities and define their relationships and associations in the designer in Visual Studio. You can also specify the Key property and the data types for the properties for your entities using the designer. You can use partial classes to implement additional features in your entities. Model First Application Development Company Indiahttp://www.ifourtechnolab.com
  • 9.  OK, but when should you use the Model First approach? Well, if neither the domain classes nor the database is ready and you would rather define the data model using a visual designer, this approach is for you. However, like in the Code First approach, in the Model First approach manual changes to the database would be lost as the model defines the database. Model First (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 10.  Entity framework supports three types of relationships, same as database:  One to One  One to Many  Many to Many Entity Relationships Application Development Company Indiahttp://www.ifourtechnolab.com
  • 11.  As you can see in the above figure, Student and StudentAddress have a One-to-One relationship (zero or one).  A student can have only one or zero address. Entity framework adds Student navigation property into StudentAddress entity and StudentAddress navigation entity into Student entity.  Also, StudentAddress entity has StudentId property as PrimaryKey which makes it a One-to-One relationship.  As you can see in the below code, Student entity class includes StudentAddress navigation property and StudentAddress includes Student navigation property with foreign key property StudentId. This way EF handles one-to-one relationship between entities. One-To-One Relationship Application Development Company Indiahttp://www.ifourtechnolab.com
  • 12.  Example: public partial class Student { public Student() { this.Courses = new HashSet<Course>(); } public int StudentID { get; set; } public string StudentName { get; set; } public Nullable<int> StandardId { get; set; } public byte[] RowVersion { get; set; } public virtual Standard Standard { get; set; } public virtual StudentAddress StudentAddress { get; set; } public virtual ICollection<Course> Courses { get; set; } } One-To-One Relationship (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 13. public partial class StudentAddress { public int StudentID { get; set; } public string Address1 { get; set; } public string Address2 { get; set; } public string City { get; set; } public string State { get; set; } public virtual Student Student { get; set; } } One-To-One Relationship (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 14.  The Standard and Teacher entities have a One-to-Many relationship marked by multiplicity where 1 is for One and * is for many. This means that Standard can have many Teachers whereas Teacher can associate with only one Standard.  To represent this, The Standard entity has the collection navigation property Teachers (please notice that it's plural), which indicates that one Standard can have a collection of Teachers (many teachers). And Teacher entity has a Standard navigation property (Not a Collection) which indicates that Teacher is associated with one Standard. Also, it contains StandardId foreign key (StandardId is a PK in Standard entity). This makes it One-to-Many relationship. One-To-Many Relationship Application Development Company Indiahttp://www.ifourtechnolab.com
  • 15.  Example: public partial class Standard { public Standard() { this.Students = new HashSet<Student>(); this.Teachers = new HashSet<Teacher>(); } public int StandardId { get; set; } public string StandardName { get; set; } public string Description { get; set; } public virtual ICollection<Student> Students { get; set; } public virtual ICollection<Teacher> Teachers { get; set; } } One-To-Many Relationship (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 16. public partial class Teacher { public Teacher() { this.Courses = new HashSet<Course>(); } public int TeacherId { get; set; } public string TeacherName { get; set; } public Nullable<int> StandardId { get; set; } public Nullable<int> TeacherType { get; set; } public virtual ICollection<Course> Courses { get; set; } public virtual Standard Standard { get; set; } } One-To-Many Relationship (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 17.  Student and Course have Many-to-Many relationships marked by * multiplicity. It means one Student can enrol for many Courses and also, one Course can be be taught to many Students.  The database design includes StudentCourse joining table which includes the primary key of both the tables (Student and Course table). Entity Framework represents many-to-many relationships by not having entityset for the joining table in CSDL, instead it manages this through mapping. Many-to-Many Relationship Application Development Company Indiahttp://www.ifourtechnolab.com
  • 18.  Example: public partial class Student { public Student() { this.Courses = new HashSet<Course>(); } public int StudentID { get; set; } public string StudentName { get; set; } public Nullable<int> StandardId { get; set; } public byte[] RowVersion { get; set; } public virtual Standard Standard { get; set; } public virtual StudentAddress StudentAddress { get; set; } public virtual ICollection<Course> Courses { get; set; } } Many-To-Many Relationship (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 19. public partial class Course { public Course() { this.Students = new HashSet<Student>(); } public int CourseId { get; set; } public string CourseName { get; set; } public System.Data.Entity.Spatial.DbGeography Location { get; set; } public Nullable<int> TeacherId { get; set; } public virtual Teacher Teacher { get; set; } public virtual ICollection<Student> Students { get; set; } } Many-To-Many Relationship (Cont.) Application Development Company Indiahttp://www.ifourtechnolab.com
  • 20. Thank you Software development company indiahttp://www.ifourtechnolab.com

Editor's Notes

  1. Application Development Company India - http://www.ifourtechnolab.com/
  2. Application Development Company India - http://www.ifourtechnolab.com/
  3. Application Development Company India - http://www.ifourtechnolab.com/
  4. Application Development Company India - http://www.ifourtechnolab.com/
  5. Application Development Company India - http://www.ifourtechnolab.com/
  6. Application Development Company India - http://www.ifourtechnolab.com/
  7. Application Development Company India - http://www.ifourtechnolab.com/
  8. Application Development Company India - http://www.ifourtechnolab.com/
  9. Application Development Company India - http://www.ifourtechnolab.com/
  10. Application Development Company India - http://www.ifourtechnolab.com/
  11. Application Development Company India - http://www.ifourtechnolab.com/
  12. Application Development Company India - http://www.ifourtechnolab.com/
  13. Application Development Company India - http://www.ifourtechnolab.com/
  14. Application Development Company India - http://www.ifourtechnolab.com/
  15. Application Development Company India - http://www.ifourtechnolab.com/
  16. Application Development Company India - http://www.ifourtechnolab.com/
  17. Application Development Company India - http://www.ifourtechnolab.com/
  18. Application Development Company India - http://www.ifourtechnolab.com/
  19. Software Outsourcing Company India - http://www.ifourtechnolab.com/