1 / 15

Entity Framework Code First – Beyond the Basics

Entity Framework Code First – Beyond the Basics. Sergey Barskiy, Magenic Microsoft MVP – Data Platform Principal Consultant. Entity Framework Code First. Entity Framework in Microsoft’s ORM Tool Has been out since 2008 Code First has been out since 2011. Handling Schema Changes.

lisle
Download Presentation

Entity Framework Code First – Beyond the Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Entity Framework Code First – Beyond the Basics Sergey Barskiy, Magenic Microsoft MVP – Data Platform Principal Consultant

  2. Entity Framework Code First • Entity Framework in Microsoft’s ORM Tool • Has been out since 2008 • Code First has been out since 2011

  3. Handling Schema Changes • Code First Migrations • Create database • Maintain schema • Command line migrations • Custom Migrations • Using 3rd Party tooling

  4. Code First Migrations • Enable automatic migrations • Update-Database • Has to be run to create database • Add-Migration • Add manual migration • Up / Down methods • Supplying default values for non-nullable columns • MigrateDatabaseToLatestVersion<T,C>

  5. Code First Migrations • DbMigration API • Index • Rename • Update-Database –TargetMigration: (can be used to rollback) • Migrate.exe • Create script

  6. Performance • Caching Context • Web environments • CRUD Efficiencies • Update • Delete • Insert • Select • When used in services, disable • Lazy Loading • Proxy Creation

  7. Performance • Auto Compiled Queries (v5), etc… • View generation • http://blogs.msdn.com/b/adonet/archive/2012/04/09/ef-power-tools-beta-2-available.aspx • Lazy vs. Eager Loading • White Paper http://msdn.microsoft.com/en-us/data/hh949853 • Upgrade server to .NET 4.5 to take advantage

  8. DbEntityEntry • State • Current, Original, Database values • ComplexProperty • Entity • Reload • GetValidationResult • Access to see if a scalar property was modified (requires all properties to be virtual)

  9. Organizing the Model • Hierarchies • Table per hierarchy • Types in an inheritance hierarchy are mapped to a single table. A condition clause is used to define the entity types • Table per type • Types are all mapped to individual tables. Properties that belong solely to a base type or derived type are stored in a table that maps to that type • Table per concrete type • Non-abstract types are each mapped to an individual table. Each of these tables must have columns that map to all of the properties of the derived type, including the properties inherited from the base type

  10. Organizing the Model • Complex Types • A complex type is a non-scalar property of an entity type that does not have a key property. A complex type can contain other nested complex types. • Entity Splitting • Properties from a single entity in the conceptual model are mapped to columns in two or more underlying tables. • Excluding Types and Properties • Properties and/or classes are excluded from storage. • Explicit Mapping of Types and Properties

  11. Relationships • Relationships • All are supported • One-to-one needs explicit configuration • Cascading deletes

  12. More… • Working with Views and Stored Procedures

  13. More… • Create your own repository • Create/Update/Delete • Select • Conventions • Creating your own conventions • V6 Preview

  14. RDBMS Providers • Available providers • DevArt • DataDirect • Oracle • MySQL.etc… • Mileage may vary

  15. Contact Info • SergeyB@Magenic.com • www.DotNetSpeak.com • www.CampusMVP.net

More Related