$30 off During Our Annual Pro Sale. View Details »

DotNet Meetup - Jan 2017 - EF Core (INSTIL)

DotNet Meetup - Jan 2017 - EF Core (INSTIL)

Deck by Eamonn Boyle (INSTIL) for the Belfast .NET Meetup

Gareth Burns

January 23, 2017
Tweet

More Decks by Gareth Burns

Other Decks in Programming

Transcript

  1. © Instil Software 2017
    January 2017
    [email protected]
    [email protected]
    [email protected]
    Entity Framework Core
    Belfast .NET Developer Guild

    View Slide

  2. © Instil Software 2017
    • Software Trainer at Instil
    • Since 5 months ago
    • Spent previous years mainly on .NET
    and C++
    • Working with hardware
    • Performance
    • Low level
    • Interested in all things tech
    About Me
    Disclaimer – Not a DBA or Entity
    Guru 

    View Slide

  3. © Instil Software 2017
    Goals
    Introduce Entity Framework Core
    • It’s the Core part I’m interested in
    • Assumes no previous knowledge of Entity Framework
    What it’s Not
    Masterclass on Entity Framework
    Overview

    View Slide

  4. © Instil Software 2017
    • .NET Platform – the new kid
    • Open Source
    • Cross Platform
    • Can deploy within the application
    • Complies with .NET Standard
    New and still evolving
    .NET Core Refresher

    View Slide

  5. © Instil Software 2017
    .NET Platforms

    View Slide

  6. © Instil Software 2017
    .NET Standard

    View Slide

  7. © Instil Software 2017
    Most Import Question - S.Q.L. or Sequel
    http://www.vertabelo.com/blog/notes-from-the-lab/sql-or-sequel

    View Slide

  8. © Instil Software 2017
    Microsoft’s recommended Object Relational Mapper
    • Allows developers to interact with relational databases
    • Use domain specific classes and LINQ – translated to SQL
    • Combat Object-relational impedance mismatch
    Supports different workflows
    • Code or Box & Line designer
    • Database or Code or Model first
    Relies on .NET Framework
    • Current version – EF 6.x
    What is Entity Framework
    “Entity Framework is Microsoft’s recommended
    data access technology for new applications”
    MSDN

    View Slide

  9. © Instil Software 2017
    What is Entity Framework
    Code Model SQL DB

    View Slide

  10. © Instil Software 2017
    A complete rewrite of Entity Framework
    • Cross platform focus – targets .NET Standard
    • Lightwieght
    • Extensible
    Started life as EF 7
    • Changed name to clarify that it is a different product
    • Does not have all features of EF 6
    Supported on .NET Framework, .NET Core and Xamarin*
    • Current version is EF Core 1.1.0
    *Eventually, when it supports .NET Standard 2.0
    What is Entity Framework Core

    View Slide

  11. © Instil Software 2017
    Timeline
    2008 – EF 1.0 – First version
    2010 – EF 4.0 - Second version – not semantic versioning
    2011 – EF 4.1 – Code First support
    2013 – EF 6.0
    June 2016 – EF Core 1.0
    November 2016 – EF Core 1.1.0

    View Slide

  12. © Instil Software 2017
    • Uses the same approach to provide data access
    • Largely the same developer experience
    • APIs largely the same
    • Entity classes, DbSet, DbContext etc
    • Use LINQ and automatically translated to queries
    • Supports .NET Framework
    EF Core vs EF 6
    EF Core EF 6
    New product
    Cross platform (.NET and OS)
    Explicit configuration and DI
    Some EF Core Only Features
    Stable and mature
    .NET Framework (Windows)
    Auto-configuration Magic
    Some EF 6 Only Features

    View Slide

  13. © Instil Software 2017
    EF Core – Missing Features
    https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features
    • Complex/value types
    • Visualising Model, Wizard for Reverse Engineering
    • Simple Type Conversions
    • Spatial data types
    • Many to Many without join
    • TPT and TPC. Only TPH Supported
    • Improved Translation - GroupBy
    • Lazy Loading
    • Raw SQL for non-model types
    • Lifecycle Hooks - Simple Command Interception
    • Explicit Loading
    • Connection Resiliency

    View Slide

  14. © Instil Software 2017
    EF Core – Missing Features
    https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features
    • Complex/value types
    • Visualising Model, Wizard for Reverse Engineering
    • Simple Type Conversions
    • Spatial data types
    • Many to Many without join
    • TPT and TPC. Only TPH Supported
    • Improved Translation - GroupBy
    • Lazy Loading
    • Raw SQL for non-model types
    • Lifecycle Hooks - Simple Command Interception
    • Explicit Loading
    • Connection Resiliency

    View Slide

  15. © Instil Software 2017
    EF Core – Unique Features
    • Shadow State Properties
    • Alternate Keys
    • Key Generation - Client
    • Reverse Engineering from Command Line
    • Better “Pretty” SQL Generation
    • Mixed Client Server Evaluation
    • Raw SQL Composing with LINQ
    • Batching of Statements
    • Detached Graph Support
    • InMemory Database Provider
    • Support in .NET Core, UWP, Xamarin etc
    https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features

    View Slide

  16. © Instil Software 2017
    Database Providers
    Database Maintained Under
    Microsoft SQL Server (including SQL Azure) EF
    SQLLite EF
    In Memory EF
    Oracle under Evaluation
    Not yet supported
    EF
    PostgreSQL Npgsql
    MySQL MySQL
    Pomelo
    Sapient Guardian
    Devart dbConnect
    MySQL, Oracle, PostgreSQL, SQLite, DB2, Cloud apps
    Devart dbConnect
    SQL Server Compact Edition ErikEJ/EntityFramewor
    k.SqlServerCompact

    View Slide

  17. © Instil Software 2017
    • Lego
    Entities - .NET Standard
    Setup Provider/Context
    Logger
    Demo

    View Slide

  18. © Instil Software 2017
    The toolchain I’m using is,
    • Visual Studio 2017 RC 1
    • .Net Core 1.1 – MSBuild Tools
    • Much simplified csproj project format
    Why has Microsoft gone back to csproj from project.json file
    • One .NET tools ecosystem
    • Project to project references
    • Proven scalability
    The CLI works the same
    CSProj is Back, Baby!

    View Slide

  19. © Instil Software 2017
    No major “regular” EF releases
    • Only bug fixes, community contributions etc
    All new major features & innovations are going into EF Core
    • Azure Table Storage
    • Redis
    • Non relational databases
    • UWP and Xamarin
    What’s in the Future

    View Slide

  20. © Instil Software 2017
    If targeting .NET Core, then you have no choice
    Otherwise, it depends
    • Can you survive without the missing features?
    • Can you survive with some instability?
    • Do you have use cases that need a performance gain?
    Avoid migrating existing code from EF 6.x to EF Core
    • Advantages don’t outweigh the effort
    Should I use EF Core?

    View Slide

  21. © Instil Software 2017
    Entity Framework Core
    https://docs.microsoft.com/en-us/ef/core/
    EF6 vs EF Core 1.0 Feature Comparison
    https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features
    .NET Core
    https://www.microsoft.com/net/core#windowsvs2015
    Visual Studio 2017 RC
    https://www.visualstudio.com/vs/visual-studio-2017-rc/
    Lego Data Sets
    http://rebrickable.com/downloads
    More Info

    View Slide

  22. © Instil Software 2017
    Appendix

    View Slide

  23. © Instil Software 2017
    Raw SQL Example
    var blogs = context.Blogs
    .FromSql("SELECT * FROM dbo.Blogs")
    .ToList();
    var blogs = context.Blogs
    .FromSql("EXECUTE dbo.GetMostPopularBlogs")
    .ToList();
    var user = "johndoe";
    var blogs = context.Blogs
    .FromSql("EXECUTE dbo.GetMostPopularBlogsForUser {0}", user)
    .ToList();

    View Slide

  24. © Instil Software 2017
    Raw SQL and then Compose with LINQ
    var searchTerm = ".NET";
    var blogs = context.Blogs
    .FromSql("SELECT * FROM dbo.SearchBlogs {0}", searchTerm)
    .Where(b => b.Rating > 3)
    .OrderByDescending(b => b.Rating)
    .ToList();

    View Slide

  25. © Instil Software 2017
    Centos Setup
    1. sudo yum install libunwind libicu
    2. curl -sSL -o dotnet.tar.gz
    https://go.microsoft.com/fwlink/?linkid=837969
    3. sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz
    -C /opt/dotnet
    4. sudo ln -s /opt/dotnet/dotnet /usr/local/bin
    https://github.com/dotnet/core/blob/master/release-
    notes/preview4-download.md

    View Slide

  26. © Instil Software 2017
    MySQL EF Core Provider
    https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blo
    b/master/README.md#getting-started

    View Slide