OVERVIEW ON HOW ENTITY FRAMEWORK CODE FIRST CAN EASE THE DEVELOPMENT PROCESS Entity Framework Code First 11/19/2013 Joe Walling Copyright Walling Info Systems
What is Code First You focus on domain design, creating classes that match your database and the code first apis create the db on the fly. Basic workflow Create code first classes F5 Database auto created Default data added (if specified) Launch application 11/19/2013 Joe Walling Copyright Walling Info Systems
Convention Based Persistence Mapping 11/19/2013 Joe Walling Copyright Walling Info Systems No tools or XML mapping files are required to create mappings between model and database This is because of convention over configuration You can override default behavior but the default requires little to work Pluralize entity name for table name Properties map to columns in table Id or tablenameid maps to primary key Show simple example
DB Initialization How it works Strategies CreateDatabaseIfNotExists DropCreateDatabaseIfModelChanges DropCreateDatabaseAlways Custom Where to set Code Config Turning off DbInitializer Show examples 11/19/2013 Joe Walling Copyright Walling Info Systems
Configure Domain Classes Create data model Create data context Customize using Data annotations Fluent API 11/19/2013 Joe Walling Copyright Walling Info Systems
Migrations Automated – run Nuget package manager Code based Add-migration Update-database Show migration file and history Rollback and when needed When each is used Implications on group development 11/19/2013 Joe Walling Copyright Walling Info Systems
Configure Relationship One to one One to many Many to may 11/19/2013 Joe Walling Copyright Walling Info Systems
Annotations Validation Attributes Required MinLength MaxLength StringLength Database Schema Related Table Column Key Timestamp ForeignKey NotMapped DatabaseGenerated Inverse property ConcurrencyCheck 11/19/2013 Joe Walling Copyright Walling Info Systems