Top 10 Entity Framework Features Every Developer Should Know

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Discover, Master, InfluenceSlide 1 SQL Server Compact Edition and the Entity Framework Rob Sanders Readify.
1 Developing Rules Driven Workflows in Windows Workflow Foundation Jurgen Willis COM318 Program Manager Microsoft Corporation.
Web & Cloud Development Jason Keicher - Microsoft.
Database Design for DNN Developers Sebastian Leupold.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
Introducing Reporting Services for SQL Server 2005.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Ronnie Saurenmann Principal Architect Microsoft Switzerland.
1 ADO.NET Data Services Mike Taulty Developer & Platform Group Microsoft Ltd
Entity Framework 7 Who Are You & What Have You Done to my ORM?
Entity Framework 7: What’s New? Ricardo Peres Technical Evangelist at Simplifydigital. Microsoft
2 Behind every great site, there is great data Eric Nelson Developer Evangelist Microsoft UK
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Data in Windows 10 UWP Andy Wigley XML, JSON, SQLite or EF Core ?
2 ADO.NET Data Services for the Web Mike Flasko Program Manager, Microsoft “Project Astoria”
Introduction ITEC 420.
Introduction to ASP.NET Core
Introduction to .NET Florin Olariu
Microsoft SQL Server 2014 for Oracle DBAs Module 8
5/15/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
What’s new in Entity Framework Core 2.0
Data centric apps for web, desktop and mobile with EF5
Mobile App Trends: lifecycle, functions, and cognitive
ASP.NET Core: Web apps, cloud apps, and containers
TechEd /1/2018 7:56 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
6/2/2018 4:08 AM BRK3327 Ten things you didn't know about building .NET UWP apps in Visual Studio 2017 Daniel Jacobson Program Manager – Visual Studio.
The Future of C# The Future of C# and VB 2-577
The Modern ASP.NET Tech Stack!
TFS Database Import Service for Visual Studio Team Services
 .NET CORE
Getting Started with Visual Studio Tools for Tizen
Did your feature got in, out or planned?
Building Innovative Apps using the Microsoft Developer Platform
SQL Server Data Tools for Visual Studio Part I: Core SQL Server Tools
Entity Framework By: Casey Griffin.
A Tour of EF Core’s Most Interesting & Important Features
DNN Connect 2017 Microsoft Keynote
Introducing ASP.NET Core 2.0
Learn. Imagine. Build. .NET Conf
.NET Standard Jon Galloway | Executive Director, .NET |
ADO.NET Entity Framework
ADO.NEXT Advances in Data Access for 2008
Microsoft Build /11/2018 2:12 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Building Modern Web Apps with ASP.NET MVC 6
Explore web development with Microsoft ASP.NET Core 1.0
DotnetConf 11/14/2018 3:27 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Microsoft Ignite /14/ :21 AM BRK2101
Microsoft Build /15/2018 6:28 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
An Introduction to Entity Framework
Learn. Imagine. Build. .NET Conf
Entity Framework Core.
Microsoft Build /30/2018 2:15 AM Migrating Silverlight Windows Phone apps to the Universal Windows Platform Ricardo Villalobos Principal SDE Manager.
Microsoft Connect /1/2018 2:36 AM
12/3/2018 7:56 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
Entity Framework Core (EF Core)
Jim Nakashima Program Manager Cloud Tools
SSDT and Database Project Basics
Microsoft Connect /22/2019 9:54 PM
From Development to Production: Optimizing for Continuous Delivery
What is Visual Studio Code?
SharePoint Development
TechEd /3/ :48 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
From Development to Production: Optimizing for Continuous Delivery
Implementing Entity Framework with MVC Jump Start
Mark Quirk Head of Technology Developer & Platform Group
Blazor A new framework for browser-based .NET apps Ryan Nowak
Navigating SSMS Primer for Beginners
Presentation transcript:

Top 10 Entity Framework Features Every Developer Should Know

Agenda EF Project Status Which EF is right for you? Top 10 Features Demos

EF Project Status

Entity Framework Project Status Beta 1 coming soon! Bug fixes, VS2017 support http://bit.ly/ef6roadmap Entity Framework 6.2 Entity Framework Core 2.0 Entity Framework 6.1 Entity Framework Core 1.1 Runtime on NuGet Tooling on Microsoft Download Center Latest version included in Visual Studio Entity Framework 6.0 Entity Framework Core 1.0 Entity Framework 5.0 New runtime components on NuGet Core runtime components in .NET Tooling in Visual Studio Entity Framework 4.1 – 4.3 Entity Framework 4 Runtime in .NET Framework Tooling in Visual Studio Entity Framework 3.5 SP1 Courtesy of Rowan Miller- https://github.com/rowanmiller/Demo-EFCore

COMMON INFRASTRUCTURE 12/15/2017 9:29 AM New Platforms .NET FRAMEWORK WINDOWS APPLICATIONS CROSS-PLATFORM SERVICES .NET CORE XAMARIN MOBILE APPLICATIONS TOOLS Visual Studio Visual Studio Code .NET STANDARD LIBRARY COMMON INFRASTRUCTURE Xamarin Studio Compilers Languages Runtime components EF6.x EF Core Courtesy of Rowan Miller- https://github.com/rowanmiller/Demo-EFCore © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Choosing Between EF 6 and EF Core

When Choosing EF 6.X vs EF Core 1, Chose Wisely Windows only Full featured 8 years of development Patch and minor releases still coming Widely used Rich set of database providers Lots of articles, books, examples Cross Platform Brand new - missing features from EF 6 EF Core 1.1 closed the gap Many new features not in EF 6.x Much faster performance Documentation is catching up http://bit.ly/ef6efcore

Top 10 Features for Entity Framework

Top 11 Features You Need To Know (In No Particular Order) Improved Performance in EF Core Batching (EFC 1.0+) Field Mapping (EFC 1.1) Connection Resiliency (EF 6, EFC 1.1) Concurrency (EF6, New APIs ECC 1.1) Mixed Mode Evaluation (EFC 1.0+) FromSql (EF6, EFC 1.0+) Improved Migrations (EFC 1.0+) Computed Columns (EF6, EFC 1.1*) Find (EF, EFC 1.1)

Performance Improvements

Batching of Statements

Batching of statements for Insert, Update, Delete EF Core batches multiple statements into a single call Uses table valued parameters to process changes in a single call Improved performance through reduced network traffic Reduces cost for cloud based databases Batch size can be configured

Controlling Batching

Field Mapping

Field Mapping/Backing Fields Allows EF to read and/or write to fields instead of properties Conventions (in order of precedence) [m]_<camel-cased property name> [m]_<property name> Fluent API modelBuilder.Entity<Blog>().Property(b=>b.Url).HasField(“_theUrl”) Used when materializing objects Public getters/setters (if they exist) used at other times Can control when the fields is used

Field Mapping

Connection Resiliency

Connection Resiliency Built in retry mechanism defined by relational database providers Default – no retry SqlServerRetryingExecutionStrategy Optimized for SQL Server and SQL Azure Custom Execution Strategy Specify retry count and max delay Throws RetryLimitExceededException Actual exception is inner exception

Connection Resiliency

Concurrency

Concurrency SQL Server uses Timestamp (rowversion) properties Coded as a byte[] in C# Updates and Deletes are modified Where <pk> = @p1 and <timestamp> = @p2 Error throws DbUpdateConcurrencyException Provides access to entities not updated/deleted EF Core 1.1 added back familiar API calls Developer decides how to handle concurrency errors

Concurrency

Mixed Mode Query Evaluation

EF Core supports mixed Evaluation EF Core supports queries being evaluated on the server and the client What executes where is provider specific Useful for including C# functions into the LINQ query/project Be careful where the client functions are injected Poor usage can crush performance Enabled or disabled at the context level

Mixed Mode Query Evaluation

Populating Models with Raw SQL Queries

Populating Models with Raw SQL Queries Models can be populated from raw SQL using FromSql on DbSet<T> Select list names must match the names that properties are mapped to All fields on the model must be returned Useful for times when Sprocs or UDFs perform better than LINQ/EF Can also populate POCOs that are not tables Must be in the Context as a DbSet<T> Must have a primary key defined

FromSQL

Migrations

EF Core Context Migrations Used to modify schema of based on model and SQL Code Can also scaffold existing database into Context and Models Supports more than one DbContext in a project E.g. ApplicationDbContext (ASP.NET Identity) and MyDomainModelContext Can also create SQL script representing changes to the database Note: Migrations only work with projects that emit entry point

Changes from EF6 Migrations The Good No longer uses a hash to check database state ModelSnapshot is C# file that contains all of the DDL Database.Migrate method creates model AND runs all migrations The bad? Database Initializers and Configuration Seed method are gone

Migrations

Computed Columns

Using Computed Columns in Models Same table computed columns supported with EF Core 1.0 entity.Property(e => e.LineItemTotal).HasColumnType("money") .HasComputedColumnSql("[Quantity]*[UnitCost]"); UDF based computed columns supported with EF Core 1.1 entity.Property(e => e.OrderTotal).HasColumnType("money") .HasComputedColumnSql("Store.GetOrderTotal([id])");

Computed Columns

Find

DbSet<T> Find Method 12/15/2017 DbSet<T> Find Method Introduced in EF Core 1.1 Largely due to the developer community Searches on primary key(s) Returns instance from DbChangeTracker is currently tracked Else calls to database Finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.

Get the code: https://github