EF Development Approaches Database First Existing Generated Data Database Model (.edmx) Model First Data Model Generated (.edmx) Database Code First Data Model Generated (classes) Database Today’s Demos Existing Generated Data Database Model (classes)
Entity Framework ContextObjectContextDbContext (Code First support)Roles: tracking changes and managing identities, concurrency, and relationships.
DbContext• Locating entities with key value• Add/Remove/Attach/Query• Modify State• Change Tracking API (current/original values)• Built-in Model-Level Validation and DataAnnotations support• Raw SQL Query/Command Support
Demo 1Northwind databaseConvention over Configuration
Mappings - Fluent APICreate metadata at runtimeAdvanced mapping configurationsDomain classes free of infrastructure code (DataAnnotations attributes, EntityObject)Rules defined within DbContext class (OnModelCreating event)Better support for existing databases
Demo 2Northwind databaseFluent API Change Primary Key name Mapping a Complex Type