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 API
using (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.Name
select 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

State of entity framework

  • 1.
    The State ofEntity Framework David Paquette www.davepaquette.com @Dave_Paquette
  • 2.
    Overview  Background  EntityFramework 6 What’s New? Demo – Profiling and Performance Tuning  Entity Framework 7 What? – Where? – When? - Why?
  • 3.
    Entity Framework  AnObject 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 ?
  • 4.
    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…
  • 5.
    Flavours of EntityFramework  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!
  • 6.
    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
  • 7.
    NuGet Packages Used PM>Install-Package EntityFramework PM> Install-Package Ninject.MVC3 PM> Install-Package MiniProfiler.EF6 PM> Install-Package MiniProfiler.MVC4
  • 8.
    Connection Resiliency public classMyConfiguration : DbConfiguration { public MyConfiguration() { SetExecutionStrategy( "System.Data.SqlClient", () => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30))); } }
  • 9.
    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(); }
  • 10.
    Entity Framework 7 https://github.com/aspnet/EntityFramework  Part of ASP.NET vNext (v5)
  • 11.
    Yup, it’s are-write
  • 12.
  • 13.
    Familiar API using (vardb = 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.Name select b; foreach (var blog in blogs) { //… } }
  • 14.
  • 15.
    New Features  WindowsStore 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
  • 16.
     Batching ofUpdates!!!!  Proper Unique Constraints  Simplified Meta-Data Model More New Features using (var db = new BloggingContext()) { var tableName = db.Model.GetEntityType(typeof(Blog)).Relational().Table; }
  • 17.
    Entity Framework 7– First Release  Focus on ASP.NET 5  Not recommended for any other platform
  • 18.
    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
  • 19.
    The State ofEntity Framework David Paquette www.davepaquette.com @Dave_Paquette

Editor's Notes

  • #3 Overview of the session.