Skip to main content

Get Started with Entity Framework (EF)

Past & Future Versions

This page provides information on the latest version of Entity Framework (EF5), although much of it also applies to past versions. Check out the Version History for a complete list of versions and the features they introduced. The Past Versions page contains a snapshot of the documentation relating to each previous version of Entity Framework. The Future Versions page contains documentation we are creating for the next version of Entity Framework.

Get Started with Entity Framework

Which workflow should I use video Which workflow should I use?
Entity Framework allows you to create a model by writing code or using boxes and lines in the EF Designer. Both of these approaches can be used to target an existing database or create a new database. This short video explains the differences and how to find the one that is right for you.

 

I just want to write code...

I am creating a new database video I am creating a new database
Use Code First to define your model in code and then generate a database.
  
I need to access an existing database video I need to access an existing database
Use Code First to create a code based model that maps to an existing database.

 

I want to use a designer...

I am creating a new database video I am creating a new database
Use Model First to define your model using boxes and lines and then generate a database.
  
I need to access an existing database video I need to access an existing database
Use Database First to create a boxes and lines model that maps to an existing database.

 

New Features in EF5

EF5 is the newest version of Entity Framework. These short videos and step-by-step walkthroughs will get you started with the new EF5 features

Enum Support in Code First Video Enum Support in Code First
The domain classes that make up your Code First model can now contain enum properties that will be mapped to the database.
  
Enum Support in EF Designer Video Enum Support in EF Designer
Using the EF Designer you can now add enum properties to your entities.
  
Spatial Data Types in Code First Video Spatial Data Types in Code First
Spatial data types can now be exposed in your Code First model using the new DbGeography and DbGeometry types. Also see the information about provider support for spatial types.
  
Spatial Data Types in EF Designer Video Spatial Data Types in EF Designer
Spatial data types can now be used in the EF Designer using the new DbGeography and DbGeometry types. Also see the information about provider support for spatial types.
  
Table-Valued Functions Video Table-Valued Functions
Table-valued functions (TVFs) in your database can now be used with Database First models created using the EF Designer.
  
Multiple Diagrams per Model Video Multiple Diagrams per Model
The EF Designer now allows you to have several diagrams that visualize subsections of your overall model. This allows larger models to be broken up into multiple smaller diagrams. You can also add color to the entities to help identify sections of your model.

 

Learn More About Setting Up Your Model

Which Workflow Should I Use
Find out about the EF Designer and Code First and which one is best for you.
Connections and Models
Learn how EF works out which database to connect to and how to calculate the model.
Performance Considerations
Find out how to get the best performance out of Entity Framework.
Working with Microsoft SQL Azure
There are a number of characteristics of SQL Azure that need to be taken into account when using EF.
Entity Framework Power Tools
The EF Power Tools provide a preview of features that are being considered for the main EF tooling.
Configuration File Settings
EF allows a number of settings to be configured from your applications configuration file.
Glossary
Definition of terms that are commonly used when talking about Entity Framework.
Creating a Model with Code First

These topics are specific to models created using EF Code First.

Code First to a New Database
Use Code First to define your model in code and then generate a database.
Code First to an Existing Database
Use Code First to create a code based model that maps to an existing database.
Conventions
Find out about the conventions Code First uses to build your model.
Data Annotations
Data Annotations provide a simple way to configure your model by applying attributes to your classes.
Fluent API - Configuring/Mapping Properties & Types
Learn how to configure properties/types and the columns/tables they map to using the Fluent API.
Fluent API - Configuring Relationships
Find out how to configure relationships and the foreign key constraints they map to using the Fluent API.
Fluent API with VB.NET
This walkthrough shows how to use the fluent API in VB.NET projects.
Code First Migrations
Learn more about upgrading, downgrading and creating SQL scripts with Code First Migrations.
Automatic Code First Migrations
Automatic migrations allow you to upgrade your database without code-based migrations in your project.
Migrate.exe
Use migrate.exe to apply migrations to a database from a command line.
Defining DbSets
Discover the various options for defining DbSets on your derived context.
Creating a Model with the EF Designer

These topics are specific to models created using the EF Designer.

EF Designer to a New Database (Model First)
Use Model First to define your model using boxes and lines and then generate a database.
EF Designer to an Existing Database (Database First)
Use Database First to create a boxes and lines model that maps to an existing database.
Complex Types
Find out how to group properties on your entities into complex types.
Associations/Relationships
Learn how to configure relationships in your model.
TPT Inheritance Pattern
Learn how to implement the Table-per-Type (TPT) inheritance pattern in your model.
TPH Inheritance Pattern
Learn how to implement the Table-per-Hierarchy (TPH) inheritance pattern in your model.
Query with Stored Procedures
Use stored procedures to load data from the database.
Stored Procedures with Multiple Result Sets
Use stored procedures with multiple result sets to load data from the database.
Insert, Update & Delete with Stored Procedures
Use stored procedures to insert, update and delete data.
Map an Entity to Multiple Tables (Entity Splitting)
Learn how to map the properties of an entity to columns in multiple tables.
Map Multiple Entities to One Table (Table Splitting)
Learn how to map the columns of a table to properties in multiple entities.
Defining Queries
A defining query is like a view that is defined in your model, rather than the database.
Code Generation Templates
Find out how to customize the code that is generated from your model.
Reverting to ObjectContext
New models created in VS2012 generate code that uses DbContext, but you can revert to ObjectContext.
EDMX Files
Covers properties of EDMX files and specification of the xml format (including CSDL, SSDL & MSL).

 

Learn More About Using Your Model

Working with DbContext
Guidance on how to manage instances of your context class.
Querying/Finding Entities
Learn how to retrieve data from the database using LINQ and the Find method.
Working with Relationships
Find out how to access and manipulate data using relationships.
Loading Related Entities
EF supports the eager, lazy and explicit loading patterns for loading related data.
Working with Local Data
Access your in-memory entity instances and the additional information EF is tracking about them.
N-Tier Applications
Learn how to use Entity Framework to build N-Tier applications, including Self-Tracking Entities.
Raw SQL Queries
Find out how to load data from a raw SQL query directly against the database.
Optimistic Concurrency Patterns
Learn about the various strategies for dealing with concurrency exceptions in EF.
Working with Proxies
Proxies derive from your entities and override virtual properties to enable features such as lazy loading.
Automatic Detect Changes
Find out what detect changes is and when you may want to disable automatic detect changes..
No-Tracking Queries
No-tracking allows you to query for entities without having the results be tracked by the context.
The Load Method
Load entities from the database into the context without immediately doing anything with those entities.
Add/Attach and Entity States
Get familiar with adding and attaching entities and setting entity states in disconnected/N-Tier scenarios.
Working with Property Values
Find out how to access the current, original and database values for your entity instances.
API Documentation
Find out more about a particular namespace, class, property or method in Entity Framework.

 

Using EF With Other Technologies

ASP.NET MVC
EF provides the M (Model) in MVC. Chapter 4 onwards of this tutorial uses EF for data access.
ASP.NET Web API
Use EF and ASP.NET Web API to build HTTP services that reach a broad range of clients.
ASP.NET Web Forms
Find out how to perform data access in your Web Forms application using EF.
WPF - Windows Presentation Foundation
Learn how to create a master/detail window in WPF using Entity Framework for data access.
WinForms - Windows Forms
Learn how to create a master/detail window in WinForms using Entity Framework for data access.

Blogroll

ADO.NET Blog ADO.NET Blog

The official source of information on Managed Providers, DataSet & EF

Arthur Vickers One Unicorn

Arthur Vickers is a member of the Entity Framework team at Microsoft

Diego Vega Diego Vega

Diego Vega is a member of the Entity Framework team at Microsoft

Rowan Miller RoMiller.com

Rowan Miller is a member of the Entity Framework team at Microsoft

Brice Lambson Brice Lambson

Brice Lambson is a member of the Entity Framework team at Microsoft

Julie Lerman Don't Be Iffy

Julie Lerman is a Microsoft MVP who speaks, blogs & authors books on EF

Books

Programming EF: DbContext Programming EF: DbContext

By Julie Lerman & Rowan Miller

Programming EF: Code First Programming EF: Code First

By Julie Lerman & Rowan Miller

Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?