SlideShare a Scribd company logo
Richie Rump
      @Jorriss
www.jorriss.net
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations
• Object-Relational Mapping Framework
• Allows developers to retrieve database
  data from an object model.
• Converts object data into relational data
• Uses your classes
• Generates SQL
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations
• Code First Model
• DbContext
• Fluent API
• Bug Fixes
• Semantic Versioning
Because Entity Framework 4.2 is better
than:
Entity Framework 4.1 Service Pack 2
Update 1 Refresh Release To Web Pack
•   Code First Migrations
•   Data Annotations on non-public properties
•   Additional configuration file settings
•   Removal of EdmMetadata table
•   Bug Fixes
• Added –IgnoreChanges to enable CodeFirst
  against existing database.
• More inevitable bug fixes.
EF 4.3.1 – Bug Fixes

      EF 4.3 - Migrations

      EF 4.2 – Bug Fixes

EF 4.1 - Code First & DbContext


 Entity Framework 4.0
    included with .Net 4.0
Design First                                  Code First

                        Model First                                Code First
                        Create .edmx model in designer             Define classes & mapping in code
       New              Generate DB from .edmx                     Database auto-created at
     Database           Classes auto-generate from                   runtime
                          .edmx


                        Database First                             Code First
                        Reverse engineer .edmx model               Define classes & mapping in code
      Existing          Classes auto-generate from
     Database             .edmx




Adapted from Programming Entity Framework: Code First by Julie Learman and Rowan Miller page 3.
Lovingly stolen from Programming Entity Framework: Code First by Julie Lerman and Rowan Miller page 9.
In a word: Nuget
• What does code look like?
• How do we use it?
• Stop! Demo time.
• Convention over configuration
  – Database naming
  – Primary Key
• SQL Server Express – default database
• dbContext Class
• It’s not enough to use convention.
• Tells EF how to map the object model to the
  database model.
• Place annotations directly against the
  property in your class.
• System.ComponentModel.DataAnnotations
•   Key – Defines a Primary Key
•   Column – Defines DB column name
•   Table – Defines table name for a class
•   Required – Defines a Required DB field
•   NotMapped – Property not in DB mapping
•   MinLength() – Min length for a property
•   MaximumLength() – Max length for property
•   Range() – Defines a valid value range
[Table(“Product_Order")]
public class Order
{
    [Key]
    [Column("Order_ID")]
    public int OrderId { get; set; }
    public DateTime Date { get; set; }
    public OrderState State { get; set; }
    public string Item { get; set; }
    [Range(1, 25)]
    public int Quantity { get; set; }
    [MinLength(3, ErrorMessage="What are you thinking?")]
    [MaxLength(50, ErrorMessage="ERROR!! FAILZ!!!!")]
    public string Name { get; set; }
    [NotMapped]
    public string Note { get; set; }
}
• Allows you to configure EF without polluting
  your classes with annotations.
• Cleaner code
• Can have all EF mapping code in one file.
• Some things you can only do in the Fluent API
Data Annotations
[Column("Order_ID")]
public int Id { get; set; }



Fluent API
modelBuilder.Entity<Order>()
  .Property(p => p.Id).HasColumnName("Order_ID");
• This time it will work…I swear!
• Expressed via the navigation properties in
  your classes
public class Order
{
        public int Id { get; set; }
        public OrderState State { get; set; }
}
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations
public class Order
 {
    public int Id { get; set; }
    public int OrderStateID { get; set; }
    public OrderState State { get; set; }
 }


public class OrderState
{
   public int Id { get; set; }
}


public OrderConfiguration()
{
    ToTable("Order");
    Property(p => p.OrderStateID).HasColumnName("Order_State_ID");
    HasRequired(p => p.State).WithMany()
      .HasForeignKey(f => f.OrderStateID);
}
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations
public class Order
 {
    public int Id { get; set; }
    public int PersonID { get; set; }
    public virtual Person SalesPerson { get; set; }
 }

 public class Person
 {
    public int PersonID { get; set; }
    ...
    public List<Order> Orders { get; set; }
 }

public OrderConfiguration()
{
    ToTable("Order");
    Property(p => p.PersonID).HasColumnName("Person_ID");
    HasRequired(p => p.SalesPerson).WithMany(t => t.Orders)
      .HasForeignKey(f => f.PersonID);
}
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations
public class Order
{
   public int Id { get; set; }
   ...
   public List<Item> Items { get; set; }
}

public class Item
{
   public int Id { get; set; }
   ...
   public List<Order> Orders { get; set; }
}

HasMany(p => p.Items).WithMany(t => t.Orders)
  .Map(m =>
  {
     m.ToTable("Order_Item");
     m.MapLeftKey("Order_ID");
     m.MapRightKey("Item_ID");
  });
• New way to interact with EF objects
• Makes interaction with EF MUCH simpler
• Encapsulates existing EF objects such as
  ObjectContext, ObjectSet and ObjectQuery
• DbContext – Provides facilities querying and
  persisting object changes.
• DbSet – Represents an entity for CRUD
  operations
• Change Tracker API and Validation API are
  other features
EFTestContext context = new EFTestContext();

var query = context.Orders
            .Where(c => c.PersonID == 22)
            .Include(c => c.State)
            .ToList();




List<Order> orders = context.Orders.ToList();
• Easy way to retrieve an object via the Primary
  Key.

EFTestContext context = new EFTestContext();
Person p = context.People.Find(1);
EFTestContext context = new EFTestContext();
Person p = new Person { FirstName = "Testy", LastName = "User" };
context.People.Add(p);
context.SaveChanges();
EFTestContext context = new EFTestContext();
Person p = context.People.Find(1);
context.People.Remove(p);
context.SaveChanges();
• Migrations is a new way to generate database
  changes automatically
• It’s controlled through PowerShell commands
• Can migrate forward or rollback DB changes.
• Migrations can be handled automatically. EF
  will automatically apply change scripts
• To turn Migrations on

PM> Enable-Migrations


• This creates a Migration folder in project
• Creates Configuration.cs file
• Creates __MigrationHistory system table in DB
PM> Add-Migration "Inital" -IgnoreChanges


• “Initial” is the name of the migration
• The –IgnoreChanges switch tells EF to create an
  empty migration. Use this if this is the first
  migration and EF did not create the DB.
• Creates a cs file with the changes since the last
  migration.
• Does not apply changes to DB.
PM> Update-Database


• Pushes the migration changes to the DB
• Use the –script switch to have EF create a SQL
  script of the changes.
• Use –TargetMigration to determine end point for
  DB. (Rollback/Forward)
• Be careful. I wouldn’t run against a production DB.
Y U NO DO DATABASE RIGHT?!?!?!!!
• Now in Release Candidate
• Install using Nuget
    Install-Package EntityFramework –Pre
•   ENUMS!
•   Performance Improvements
•   Spatial Data Types
•   Table-Valued Functions
•   Most features only in .Net 4.5
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations
• Julie Lerman’s Blog
      http://thedatafarm.com/blog/
• Rowan Miller’s Blog
      http://romiller.com
• Arthur Vicker’s Blog
      http://blog.oneunicorn.com
• #efhelp on twitter
• StackOverflow (of course)
• PluralSight – Julie Lerman’s EF videos
Richie Rump
@Jorriss
http://jorriss.net
http://dotnetmiami.com

More Related Content

What's hot (20)

PDF
Squeak DBX
ESUG
 
PPTX
Map-Reduce and Apache Hadoop
Svetlin Nakov
 
PPTX
Spring data jpa
Jeevesh Pandey
 
PPTX
DSpace 4.2 Transmission: Import/Export
DuraSpace
 
PPTX
Jdbc presentation
nrjoshiee
 
PDF
Spring data requery
Sunghyouk Bae
 
PDF
Alternatives of JPA/Hibernate
Sunghyouk Bae
 
ODP
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Knoldus Inc.
 
PPT
5\9 SSIS 2008R2_Training - DataFlow Basics
Pramod Singla
 
PDF
Lift Framework
Jeffrey Groneberg
 
PPTX
Demystifying Oak Search
Justin Edelson
 
PPTX
BGOUG 2012 - XML Index Strategies
Marco Gralike
 
PPTX
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Xml parsers
Manav Prasad
 
PPTX
XFILES, The APEX 4 version - The truth is in there
Marco Gralike
 
PPTX
Oak Lucene Indexes
Chetan Mehrotra
 
PPT
55 New Features in Java 7
Boulder Java User's Group
 
PPTX
Hotsos 2013 - Creating Structure in Unstructured Data
Marco Gralike
 
PPTX
Oracle Database 11g Release 2 - XMLDB New Features
Marco Gralike
 
Squeak DBX
ESUG
 
Map-Reduce and Apache Hadoop
Svetlin Nakov
 
Spring data jpa
Jeevesh Pandey
 
DSpace 4.2 Transmission: Import/Export
DuraSpace
 
Jdbc presentation
nrjoshiee
 
Spring data requery
Sunghyouk Bae
 
Alternatives of JPA/Hibernate
Sunghyouk Bae
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Knoldus Inc.
 
5\9 SSIS 2008R2_Training - DataFlow Basics
Pramod Singla
 
Lift Framework
Jeffrey Groneberg
 
Demystifying Oak Search
Justin Edelson
 
BGOUG 2012 - XML Index Strategies
Marco Gralike
 
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
Xml parsers
Manav Prasad
 
XFILES, The APEX 4 version - The truth is in there
Marco Gralike
 
Oak Lucene Indexes
Chetan Mehrotra
 
55 New Features in Java 7
Boulder Java User's Group
 
Hotsos 2013 - Creating Structure in Unstructured Data
Marco Gralike
 
Oracle Database 11g Release 2 - XMLDB New Features
Marco Gralike
 

Viewers also liked (20)

PDF
SAPCLE Corporate Profile - An Enterprise Application Services Partner of Cho...
SAPCLE Technologies
 
PPTX
Menu Pane E Vino
Pane E Vino
 
PPTX
Mapa Conceptual Gerencia
yolimara
 
PPTX
Apex the peak of good living
ejchapman
 
PPTX
dotNet Miami - May 17th, 2012: Will Tartak: Designing for Mobile Development
dotNet Miami
 
PPTX
Staying connected: An Overview of Announcements from Microsoft’s Connect();
dotNet Miami
 
PPTX
 灘校パソコン研究部内lt大会(2012年度)本物
yamanakako
 
PPTX
Mapa conceptual gerencia
yolimara
 
PPT
Menu Pane E Vino
Pane E Vino
 
PPTX
dotNet Miami - August 16, 2012 - Windows 8 App Walkthrough
dotNet Miami
 
PDF
Guia # 2 karol
karola77740
 
PDF
brochure2014
yudydharmawan
 
PDF
Guia #8 karol
karola77740
 
PDF
Nexus travel
tuanhaimai2010
 
PDF
Denise Sumotzy Art Collection
Denise Sumotzy
 
SAPCLE Corporate Profile - An Enterprise Application Services Partner of Cho...
SAPCLE Technologies
 
Menu Pane E Vino
Pane E Vino
 
Mapa Conceptual Gerencia
yolimara
 
Apex the peak of good living
ejchapman
 
dotNet Miami - May 17th, 2012: Will Tartak: Designing for Mobile Development
dotNet Miami
 
Staying connected: An Overview of Announcements from Microsoft’s Connect();
dotNet Miami
 
 灘校パソコン研究部内lt大会(2012年度)本物
yamanakako
 
Mapa conceptual gerencia
yolimara
 
Menu Pane E Vino
Pane E Vino
 
dotNet Miami - August 16, 2012 - Windows 8 App Walkthrough
dotNet Miami
 
Guia # 2 karol
karola77740
 
brochure2014
yudydharmawan
 
Guia #8 karol
karola77740
 
Nexus travel
tuanhaimai2010
 
Denise Sumotzy Art Collection
Denise Sumotzy
 
Ad

Similar to dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations (20)

PPTX
Ef code first
ZealousysDev
 
PPTX
Applying EF Code First at Your Job
Enea Gabriel
 
PPTX
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
PPTX
Entity Framework Today (May 2012)
Julie Lerman
 
PPTX
Entity Framework
vrluckyin
 
PDF
Learn Entity Framework in a day with Code First, Model First and Database First
Jibran Rasheed Khan
 
PDF
Intake 37 ef2
Mahmoud Ouf
 
PPTX
Getting started with entity framework
Lushanthan Sivaneasharajah
 
PDF
Intake 38 data access 5
Mahmoud Ouf
 
PDF
Murach: How to use Entity Framework EF Core
MahmoudOHassouna
 
DOCX
Getting Started with Entity Framework in .NET
StudySection
 
PPTX
Entity framework
Mehdi jannati
 
PPTX
Entity Frame Work Core.pptx
PrachiPatel779586
 
PDF
[FREE PDF sample] Programming Entity Framework DbContext 1st Edition Julia Le...
pontyrincoe
 
PPTX
05 entity framework
glubox
 
PPTX
Entity Framework v1 and v2
Eric Nelson
 
PPTX
Entity framework code first
Confiz
 
PPT
Real-world Entity Framework
Lynn Langit
 
PPTX
Entity Framework Database and Code First
James Johnson
 
PPTX
La sql
James Johnson
 
Ef code first
ZealousysDev
 
Applying EF Code First at Your Job
Enea Gabriel
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
Entity Framework Today (May 2012)
Julie Lerman
 
Entity Framework
vrluckyin
 
Learn Entity Framework in a day with Code First, Model First and Database First
Jibran Rasheed Khan
 
Intake 37 ef2
Mahmoud Ouf
 
Getting started with entity framework
Lushanthan Sivaneasharajah
 
Intake 38 data access 5
Mahmoud Ouf
 
Murach: How to use Entity Framework EF Core
MahmoudOHassouna
 
Getting Started with Entity Framework in .NET
StudySection
 
Entity framework
Mehdi jannati
 
Entity Frame Work Core.pptx
PrachiPatel779586
 
[FREE PDF sample] Programming Entity Framework DbContext 1st Edition Julia Le...
pontyrincoe
 
05 entity framework
glubox
 
Entity Framework v1 and v2
Eric Nelson
 
Entity framework code first
Confiz
 
Real-world Entity Framework
Lynn Langit
 
Entity Framework Database and Code First
James Johnson
 
Ad

Recently uploaded (20)

PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and Migrations

  • 1. Richie Rump @Jorriss www.jorriss.net
  • 3. • Object-Relational Mapping Framework • Allows developers to retrieve database data from an object model. • Converts object data into relational data • Uses your classes • Generates SQL
  • 5. • Code First Model • DbContext • Fluent API
  • 6. • Bug Fixes • Semantic Versioning Because Entity Framework 4.2 is better than: Entity Framework 4.1 Service Pack 2 Update 1 Refresh Release To Web Pack
  • 7. Code First Migrations • Data Annotations on non-public properties • Additional configuration file settings • Removal of EdmMetadata table • Bug Fixes
  • 8. • Added –IgnoreChanges to enable CodeFirst against existing database. • More inevitable bug fixes.
  • 9. EF 4.3.1 – Bug Fixes EF 4.3 - Migrations EF 4.2 – Bug Fixes EF 4.1 - Code First & DbContext Entity Framework 4.0 included with .Net 4.0
  • 10. Design First Code First Model First Code First Create .edmx model in designer Define classes & mapping in code New Generate DB from .edmx Database auto-created at Database Classes auto-generate from runtime .edmx Database First Code First Reverse engineer .edmx model Define classes & mapping in code Existing Classes auto-generate from Database .edmx Adapted from Programming Entity Framework: Code First by Julie Learman and Rowan Miller page 3.
  • 11. Lovingly stolen from Programming Entity Framework: Code First by Julie Lerman and Rowan Miller page 9.
  • 12. In a word: Nuget
  • 13. • What does code look like? • How do we use it? • Stop! Demo time.
  • 14. • Convention over configuration – Database naming – Primary Key • SQL Server Express – default database • dbContext Class
  • 15. • It’s not enough to use convention. • Tells EF how to map the object model to the database model. • Place annotations directly against the property in your class. • System.ComponentModel.DataAnnotations
  • 16. Key – Defines a Primary Key • Column – Defines DB column name • Table – Defines table name for a class • Required – Defines a Required DB field • NotMapped – Property not in DB mapping • MinLength() – Min length for a property • MaximumLength() – Max length for property • Range() – Defines a valid value range
  • 17. [Table(“Product_Order")] public class Order { [Key] [Column("Order_ID")] public int OrderId { get; set; } public DateTime Date { get; set; } public OrderState State { get; set; } public string Item { get; set; } [Range(1, 25)] public int Quantity { get; set; } [MinLength(3, ErrorMessage="What are you thinking?")] [MaxLength(50, ErrorMessage="ERROR!! FAILZ!!!!")] public string Name { get; set; } [NotMapped] public string Note { get; set; } }
  • 18. • Allows you to configure EF without polluting your classes with annotations. • Cleaner code • Can have all EF mapping code in one file. • Some things you can only do in the Fluent API
  • 19. Data Annotations [Column("Order_ID")] public int Id { get; set; } Fluent API modelBuilder.Entity<Order>() .Property(p => p.Id).HasColumnName("Order_ID");
  • 20. • This time it will work…I swear!
  • 21. • Expressed via the navigation properties in your classes public class Order { public int Id { get; set; } public OrderState State { get; set; } }
  • 23. public class Order { public int Id { get; set; } public int OrderStateID { get; set; } public OrderState State { get; set; } } public class OrderState { public int Id { get; set; } } public OrderConfiguration() { ToTable("Order"); Property(p => p.OrderStateID).HasColumnName("Order_State_ID"); HasRequired(p => p.State).WithMany() .HasForeignKey(f => f.OrderStateID); }
  • 25. public class Order { public int Id { get; set; } public int PersonID { get; set; } public virtual Person SalesPerson { get; set; } } public class Person { public int PersonID { get; set; } ... public List<Order> Orders { get; set; } } public OrderConfiguration() { ToTable("Order"); Property(p => p.PersonID).HasColumnName("Person_ID"); HasRequired(p => p.SalesPerson).WithMany(t => t.Orders) .HasForeignKey(f => f.PersonID); }
  • 27. public class Order { public int Id { get; set; } ... public List<Item> Items { get; set; } } public class Item { public int Id { get; set; } ... public List<Order> Orders { get; set; } } HasMany(p => p.Items).WithMany(t => t.Orders) .Map(m => { m.ToTable("Order_Item"); m.MapLeftKey("Order_ID"); m.MapRightKey("Item_ID"); });
  • 28. • New way to interact with EF objects • Makes interaction with EF MUCH simpler • Encapsulates existing EF objects such as ObjectContext, ObjectSet and ObjectQuery
  • 29. • DbContext – Provides facilities querying and persisting object changes. • DbSet – Represents an entity for CRUD operations • Change Tracker API and Validation API are other features
  • 30. EFTestContext context = new EFTestContext(); var query = context.Orders .Where(c => c.PersonID == 22) .Include(c => c.State) .ToList(); List<Order> orders = context.Orders.ToList();
  • 31. • Easy way to retrieve an object via the Primary Key. EFTestContext context = new EFTestContext(); Person p = context.People.Find(1);
  • 32. EFTestContext context = new EFTestContext(); Person p = new Person { FirstName = "Testy", LastName = "User" }; context.People.Add(p); context.SaveChanges();
  • 33. EFTestContext context = new EFTestContext(); Person p = context.People.Find(1); context.People.Remove(p); context.SaveChanges();
  • 34. • Migrations is a new way to generate database changes automatically • It’s controlled through PowerShell commands • Can migrate forward or rollback DB changes. • Migrations can be handled automatically. EF will automatically apply change scripts
  • 35. • To turn Migrations on PM> Enable-Migrations • This creates a Migration folder in project • Creates Configuration.cs file • Creates __MigrationHistory system table in DB
  • 36. PM> Add-Migration "Inital" -IgnoreChanges • “Initial” is the name of the migration • The –IgnoreChanges switch tells EF to create an empty migration. Use this if this is the first migration and EF did not create the DB. • Creates a cs file with the changes since the last migration. • Does not apply changes to DB.
  • 37. PM> Update-Database • Pushes the migration changes to the DB • Use the –script switch to have EF create a SQL script of the changes. • Use –TargetMigration to determine end point for DB. (Rollback/Forward) • Be careful. I wouldn’t run against a production DB.
  • 38. Y U NO DO DATABASE RIGHT?!?!?!!!
  • 39. • Now in Release Candidate • Install using Nuget Install-Package EntityFramework –Pre • ENUMS! • Performance Improvements • Spatial Data Types • Table-Valued Functions • Most features only in .Net 4.5
  • 41. • Julie Lerman’s Blog http://thedatafarm.com/blog/ • Rowan Miller’s Blog http://romiller.com • Arthur Vicker’s Blog http://blog.oneunicorn.com • #efhelp on twitter • StackOverflow (of course) • PluralSight – Julie Lerman’s EF videos

Editor's Notes

  • #5: EDMX. Entity Data Model. A representation of your classes in XML. Three files: Conceptual (Entity Model) CDSL. Logical (Database Model) SSDL Mapping (Between Entity and Database) MSL. EDMX -&gt; In memory model and metadata. EF translates the XML into an memory model. It uses this model to persist and read data from the database.