+ All Categories
Home > Software > State of entity framework

State of entity framework

Date post: 15-Jul-2015
Category:
Upload: david-paquette
View: 742 times
Download: 0 times
Share this document with a friend
Popular Tags:
19
The State of Entity Framework David Paquette www.davepaquette.com @Dave_Paquette
Transcript

The State of Entity Framework

David Paquette

www.davepaquette.com

@Dave_Paquette

Overview

Background

Entity Framework 6

What’s New?

Demo – Profiling and Performance Tuning

Entity Framework 7

What? – Where? – When? - Why?

Entity Framework

An Object Relational Mapper (ORM) for .NET

EFv1 in .NET 3.5 SP1 / VS 2008 SP1

EFv4 in .NET 4

EFv4.1 – Code First (Magic Unicorn)

EFv4.3 – Code First Migrations

EFv5.0 – enum support, table valued functions, spacial data types, performance Improvements

EFv6.0 – Lots of great stuff

EFv7.0 – What the ?

Entity Framework 6

Async Query and Save

Connection Resiliency

Code-Based Configuration

Interception / SQL Logging

Ability to Reuse an open connection

Custom Conventions

Improved Transaction Support

And Much Much More…

Flavours of Entity Framework

Model First

Design objects in the visual designer (generate the database scripts and the C# objects)

Database First

Start with an existing database (generate the model)

Code First (Magic Unicorn)

Create Plain Old CLR Objects (POCOs) first

Database can be generated or can map to existing database

There is no edmx file!

Sample App – Social Recipes

A site for sharing your favorite recipes with your friends

Create and join Groups

Create, share, and review Recipes

https://github.com/dpaquette/SocialRecipes

NuGet Packages Used

PM> Install-Package EntityFramework

PM> Install-Package Ninject.MVC3

PM> Install-Package MiniProfiler.EF6

PM> Install-Package MiniProfiler.MVC4

Connection Resiliency

public class MyConfiguration : DbConfiguration

{

public MyConfiguration()

{

SetExecutionStrategy(

"System.Data.SqlClient",

() => new SqlAzureExecutionStrategy(1,

TimeSpan.FromSeconds(30)));

}

}

Transactions

using (var scope = new TransactionScope(TransactionScopeOption.Required))

{

using (var conn = new SqlConnection("..."))

{

conn.Open();

var sqlCommand = new SqlCommand();

sqlCommand.Connection = conn;

sqlCommand.CommandText =

@"UPDATE Blogs SET Rating = 5" +

" WHERE Name LIKE '%Entity Framework%'";

sqlCommand.ExecuteNonQuery();

using (var context =

new BloggingContext(conn, contextOwnsConnection: false))

{

var query = context.Posts.Where(p => p.Blog.Rating > 5);

foreach (var post in query)

{

post.Title += "[Cool Blog]";

}

context.SaveChanges();

}

}

scope.Complete();

}

Entity Framework 7

https://github.com/aspnet/EntityFramework

Part of ASP.NET vNext (v5)

Yup, it’s a re-write

But why?

Familiar APIusing (var db = new BloggingContext(){

db.Blogs.Add( new Blog {

Url = "blogs.msdn.com/adonet"});

db.SaveChanges(); var blogs = from b in db.Blogs.Include(b => b.Posts)

orderby b.Nameselect b;

foreach (var blog in blogs) {

//… }

}

Code-Based Modelling

New Features

Windows Store Apps, .NET Core (Linux / OSx)

Non-Relational Data Stores

Azure Table Storage, Redis, DocumentDB, MongoDB, etc.

Light-weight Relational Data Stores

SQL Lite, In Memory

Batching of Updates!!!!

Proper Unique Constraints

Simplified Meta-Data Model

More New Features

using (var db = new BloggingContext())

{

var tableName = db.Model.GetEntityType(typeof(Blog)).Relational().Table;

}

Entity Framework 7 – First Release

Focus on ASP.NET 5

Not recommended for any other platform

Wrapping it up

Entity Framework 6 is great

Fast, Flexible and Well Understood

Recommended for all non-ASP.NET 5 projects

Entity Framework 7 will be great

Support for non-relational stores

Multi Platform

Faster, More Flexible

Only recommended for ASP.NET 5 projects

The State of Entity Framework

David Paquette

www.davepaquette.com

@Dave_Paquette


Recommended