Sei sulla pagina 1di 32

DEV-B417

Entity
Framework
Rowan Miller

Setting expectations
This is a level 400 session
Assumes prior knowledge of data access and EF

For getting started with EF


http://bit.ly/EFTechEd2014

Agenda
Where are we at?
A quick look at EF6, EF6.1 and EF6.1.1

Demos
EF6 in action

Where are we going?


Whats happening in EF7

Demos
EF7 sneak peek

Where are we at?

Versions
Entity
Entity
6.1.1
Entity

Framework 7
Framework
Framework 6.1

Entity Framework 6

Runtime out-of-band (NuGet)


Tooling out-of-band (Microsoft Download Center)
Latest version chained in to new Visual Studio release

Entity Framework 5
Entity Framework 4.3
Entity Framework 4.2

Core runtime in .NET Framework


Newer runtime pieces out-of-band (NuGet)
Tooling in Visual Studio

Entity Framework 4.1


Entity Framework 4
Entity Framework 3.5
SP1

Runtime in .NET Framework


Tooling in Visual Studio

What was new in EF6


From the EF Team

From our contributors

Asynchronous query and save


23 total contributions
Connection resiliency
Custom migrations operations
Code-based configuration
Improved warm up time for large models
Database command interception/logging
Pluggable pluralization & singularization
service
Custom Code First conventions
DbModelBuilder.Configurations.AddFromAsse
Code First Insert, update, & delete stored procedures
mbly
Nested entity types
DbSet.AddRange/RemoveRange
Improved transaction Support
Multiple contexts per database
DbModelBuilder.HasDefaultSchema
Configurable migrations history table
Creating context with an open connection
Enums, spatial and better performance on .NET 4.0
Default transaction isolation level changed to READ_COMMITTED_SNAPSHOT

What was new in EF6.1


From the EF Team
120+ bug fixes
Tooling consolidation
Handling Transaction.Commit failures
[Index] attribute
Public mapping API
Configuring interceptors in web/app.config
Improved migrations change detection
Fewer database operations during startup

From our contributors


17 total contributions
Support for String.Concat and .ToString in LINQ queries
Support for enum HasFlags in LINQ queries
Entity SQL canonical functions for SQL Server Compact

Whats coming in EF6.1.1


From the EF Team
47 bug fixes (and counting)

From our contributors


12 total contributions (and counting)
DbModelBuilder.Conventions.AddFromAssembly

Demos | EF6 in
action

Demo
Implementing soft deletes
Command tree interceptors (EF 6)
Custom Code First conventions (EF 6)
Model annotations (EF 6.1)
Constructible DbUpdateCommandTree (EF 6.1.1)

Soft Deletes
public
class Listing
[SoftDelete("IsDeleted")]
{
public class Listing
{ public int ListingId { get; set; }
public string
Title {{get;
int ListingId
get;set;
set;}}
public string Description
get;}set;
Title { get;{ set;
} public string Description { get;
public
int Price { get; set; }
set;
}
} public int Price { get; set; }
public bool IsDeleted { get; set; }
}
var query = from l in db.Listings
orderby l.Title
select l;

Custom
Conventio
n
Model
Builde
r

Listing

Query
Pipeline
Command
Tree
Interceptor

db.Listings.Remove(listing);
db.SaveChanges();

Update
Pipeline
Command
Tree
Interceptor

ListingId
Title
Description
Price
IsDeleted

SoftDeleteProperty:
"IsDeleted"

dbo.Listings

ListingId
Title
Description
Price
IsDeleted

SELECT * FROM dbo.Listings


WHERE IsDeleted
=0

Databas
e
UPDATE
DELETE
FROM dbo.Listings
dbo.Listings

Demo
Full text search
Raw SQL queries (EF 4)
Custom migration operations (EF 6)
Public mapping API (EF 6.1)

Demo
Testing without hitting a database
Mockable DbSet<T> (EF 6)

Demo
Enabling logging with recompiling
Registering interceptors in config (EF 6.1)
DatabaseLogger (EF 6.1)

Demo
Tooling consolidation

Where are we going?

Entity Framework 7
EF6 supported scenarios
Full .NET Framework (ASP.NET & traditional desktop applications)
Relational databases

EF7 enabling new scenarios


New platforms (Windows Phone, Windows Store, etc.)
New data stores (Non-relational)

Challenges with current code base


Long history going back to the WinFS
days
Extensive use of older APIs and design patterns
Heavy use of APIs not available on all platforms
Lots of seldom used code/features
Monolithic implementation
Unintuitive behaviors woven throughout code base

Not optimized for density/devices


High memory footprint

Tight coupling to relational concepts

What we are doing


Lightweight, extensible version of EF
Just the commonly used features (and many new features)
Built using modern design patterns
DbContext and Code First only

Not a micro-O/RM
Still supports LINQ, change tracking, unit of work, etc.

Support relational & non-relational stores


Not a high level abstraction over all data stores
Provide high level services that are useful on all/most stores
Non-common concerns handled by provider extensions

Design principles
Keep EF6 patterns
Only break from existing patterns where there is good reason

Pay per play


Simpler apps will require fewer resources
Low memory footprint

Extensible
Simple high level API over building blocks
Easy to replace/extend individual building blocks as needed

Sensible defaults, less magic


Only support magic where it supports long term success

What about EF6 apps?


You dont have to upgrade
EF6 is still supported
Updates to EF6 will continue (weve done EF6.1 and EF6.1.1 in parallel with EF7)

Not all EF6 features will be in 7.0.0


We dont expect everyone to be able to upgrade immediately

Upgrade is a key scenario


Same concepts, same patterns
Some code changes will be needed

Get involved in EF7


Open source
See http://bit.ly/EFTechEd2014 for links

Nightly builds now available


See http://bit.ly/EFTechEd2014 for links

Demos | EF7 sneak


peek

Demo
New data stores

Demo
New platforms

Related content
DEV-B356 Industrial-Strength Entity
Framework
Find Me Later At Developer Tools Booth

Visit the Developer Platform & Tools


Booth
Having a friend
buy your coffee?
Yea, its kind of like that.

3 Steps to New Gear! With Application Insights

MSDN Subscribers get up to $150/mo in Azure


credits.

Stop by the Developer Platform and Tools


booth and visit the MSDN Subscriptions
station to activate your benefits and
receive a gift!

Alex Park

http://aka.ms/msdn_teched

VSIP QR Tag Contests

Visit our booth to join the hunt for cool prizes!

1. Create a
Visual Studio
Online
account
http://visualstudio.c
om

2. Install
Application
Insights Tools
for Visual
Studio Online
http://aka.ms/aivsix

3. Come to our
booth for a
t-shirt and a
chance to win!

Resources
Microsoft Engineering
Stories
Development tools & services for teams
of all sizes
http://www.visualstudio.com

Visual Studio
Industry Partner
Program
Meet Our New Visual Studio Online
Partners
or Join Now.
http://vsipprogram.com

How Microsoft Builds Software


http://aka.ms/EngineeringStories

Visual Studio | Integrate

Create Your Own Dev Environment


http://integrate.visualstudio.com

Complete an evaluation and enter


to win!

Evaluate this session


Scan this
QR code
to evaluate
this session.

2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be
interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR
STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Potrebbero piacerti anche