Slides - Sergey Barskiy's Blog

italiansaucyΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 11 μήνες)

86 εμφανίσεις

S

Entity Framework
Code First


Beyond
the Basics

Sergey Barskiy, Magenic

Microsoft MVP


Data Platform

Principal Consultant



Entity Framework Code
First

S
Entity Framework in Microsoft’s ORM Tool


Has been out since 2008


Code First has been out since 2011



Handling Schema Changes

S
Code First Migrations


Create database


Maintain schema


Command line migrations

S
Custom Migrations


Using 3
rd

Party tooling



Code First Migrations

S
Enable automatic migrations

S
Update
-
Database

S
Has to be run to create database

S
Add
-
Migration

S
Add manual migration

S
Up / Down methods

S
Supplying default values for non
-
nullable

columns

S
MigrateDatabaseToLatestVersion
<T,C>



Code First Migrations

S
DbMigration

API

S
Index

S
Rename

S
Update
-
Database

TargetMigration
:
(can be used to
rollback)

S
Migrate.exe

S
Create script



Performance

S
Caching Context


Web environments

S
CRUD Efficiencies

S
Update

S
Delete

S
Insert

S
Select

S
When used in services, disable

S
Lazy Loading

S
Proxy Creation

Performance

S
Auto Compiled Queries (v5), etc…

S
View generation

S
http://blogs.msdn.com/b/adonet/archive/2012/04/09/ef
-
power
-
tools
-
beta
-
2
-
available.aspx

S
Lazy vs. Eager Loading

S
White Paper
http://
msdn.microsoft.com/en
-
us/data/hh949853

S
Upgrade server to .NET 4.5 to take advantage

DbEntityEntry

S
State

S
Current, Original, Database values

S
ComplexProperty

S
Entity

S
Reload

S
GetValidationResult

S
Access to see if a scalar property was modified (requires all
properties to be virtual)

Organizing the Model

S
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

Organizing the Model

S
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.

S
Entity Splitting


Properties from a single entity in the conceptual model are
mapped to columns in two or more underlying tables.

S
Excluding Types and Properties


Properties and/or classes are excluded from storage.

S
Explicit Mapping of Types and Properties





Relationships

S
Relationships


All are supported


One
-
to
-
one needs explicit configuration

S
Cascading deletes



More…

S
Working with Views and Stored Procedures



More…

S
Create your own repository


Create/Update/Delete


Select

S
Conventions

S
Creating your own conventions

S
V6 Preview



RDBMS Providers

S
Available providers


DevArt


DataDirect


Oracle


MySQL.etc…

S
Mileage may vary



Contact Info

S
SergeyB@Magenic.com

S
www.DotNetSpeak.com

S
www.CampusMVP.net