June 10th, 2020

Announcing Entity Framework Core 5.0 Preview 5

Jeremy Likness
Principal Program Manager - .NET Web Frameworks

Today we are announcing the fifth preview release of EF Core 5.0.

The fifth previews of .NET 5 and ASP.NET Core 5.0 are also available now.

Prerequisites

The previews of EF Core 5.0 require .NET Standard 2.1. This means:

  • EF Core 5.0 runs on .NET Core 3.1; it does not require .NET 5.
    • This may change in future previews depending on how the plan for .NET 5 evolves.
  • EF Core 5.0 runs on other platforms that support .NET Standard 2.1.
  • EF Core 5.0 will not run on .NET Standard 2.0 platforms, including .NET Framework.

How to get EF Core 5.0 previews

EF Core is distributed exclusively as a set of NuGet packages. For example, to add the SQL Server provider to your project, you can use the following command using the dotnet tool:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-preview.5.20278.2

The EF Core packages published today are:

We have also published the 5.0 preview 5 release of the Microsoft.Data.Sqlite.Core ADO.NET provider.

Installing dotnet ef

As with EF Core 3.0 and 3.1, the dotnet ef command-line tool is no longer included in the .NET Core SDK. Before you can execute EF Core migration or scaffolding commands, you'll have to install this package as either a global or local tool.

dotnet-ef

To install the preview tool globally, first uninstall any existing version with:

dotnet tool uninstall --global dotnet-ef

Then install with:

dotnet tool install --global dotnet-ef --version 5.0.0-preview.5.20278.2

It's possible to use this new version of dotnet ef with projects that use older versions of the EF Core runtime.


What's new in EF Core 5 Preview 5

We maintain documentation covering new features introduced into each preview.

Some of the highlights from preview 4 are called out below. This preview also includes several bug fixes.

Database collations

The default collation for a database can now be specified in the EF model. This will flow through to generated migrations to set the collation when the database is created. For example:

modelBuilder.UseCollation("German_PhoneBook_CI_AS");

Migrations then generates the following to create the database on SQL Server:

CREATE DATABASE [Test]
COLLATE German_PhoneBook_CI_AS;

The collation to use for specific database columns can also be specified. For example:

 modelBuilder
     .Entity<User>()
     .Property(e => e.Name)
     .UseCollation("German_PhoneBook_CI_AS");

For those not using migrations, collations are now reverse-engineered from the database when scaffolding a DbContext.

Finally, the EF.Functions.Collate() allows for ad-hoc queries using different collations. For example:

context.Users.Single(e => EF.Functions.Collate(e.Name, "French_CI_AS") == "Jean-Michel Jarre");

This will generate the following query for SQL Server:

SELECT TOP(2) [u].[Id], [u].[Name]
FROM [Users] AS [u]
WHERE [u].[Name] COLLATE French_CI_AS = N'Jean-Michel Jarre'

Note that ad-hoc collations should be used with care as they can negatively impact database performance.

Documentation is tracked by issue #2273.

Flow arguments into IDesignTimeDbContextFactory

Arguments are now flowed from the command line into the CreateDbContext method of IDesignTimeDbContextFactory. For example, to indicate this is a dev build, a custom argument (e.g. dev) can passed on the command line:

dotnet ef migrations add two --verbose --dev

This argument will then flow into the factory, where it can be used to control how the context is created and initialized. For example:

public class MyDbContextFactory : IDesignTimeDbContextFactory<SomeDbContext>
{
    public SomeDbContext CreateDbContext(string[] args) 
        => new SomeDbContext(args.Contains("--dev"));
}

Documentation is tracked by issue #2419.

No-tracking queries with identity resolution

No-tracking queries can now be configured to perform identity resolution. For example, the following query will create a new Blog instance for each Post, even if each Blog has the same primary key.

context.Posts.AsNoTracking().Include(e => e.Blog).ToList();

However, at the expense of usually being slightly slower and always using more memory, this query can be changed to ensure only a single Blog instance is created:

context.Posts.AsNoTracking().PerformIdentityResolution().Include(e => e.Blog).ToList();

Note that this is only useful for no-tracking queries since all tracking queries already exhibit this behavior. Also, following API review, the PerformIdentityResolution syntax will be changed. See #19877.

Documentation is tracked by issue #1895.

Stored (persisted) computed columns

Most databases allow computed column values to be stored after computation. While this takes up disk space, the computed column is calculated only once on update, instead of each time its value is retrieved. This also allows the column to be indexed for some databases.

EF Core 5.0 allows computed columns to be configured as stored. For example:

modelBuilder
    .Entity<User>()
    .Property(e => e.SomethingComputed)
    .HasComputedColumnSql("my sql", stored: true);

SQLite computed columns

EF Core now supports computed columns in SQLite databases.


Daily builds

EF Core previews are aligned with .NET 5 previews. These previews tend to lag behind the latest work on EF Core. Consider using the daily builds instead to get the most up-to-date EF Core features and bug fixes.

As with the previews, the daily builds do not require .NET 5; they can be used with GA/RTM release of .NET Core 3.1.


Documentation and feedback

EF Core docs has a new landing page! The main page for Entity Framework documentation has been overhauled to provide you with a hub experience. We hope this new format helps you find the documentation you need faster and with fewer clicks.

The starting point for all EF Core documentation is docs.microsoft.com/ef/.

Please file issues found and any other feedback on the dotnet/efcore GitHub repo.


The following short links are provided for easy reference and access.

Main documentation: https://aka.ms/efdocs

Issues and feature requests for EF Core: https://aka.ms/efcorefeedback

Entity Framework Roadmap: https://aka.ms/efroadmap

What's new in EF Core 5.x? https://aka.ms/efcore5


Thank you from the team

A big thank you from the EF team to everyone who has used EF over the years!

ajcvickers
Arthur Vickers
AndriySvyryd
Andriy Svyryd

Brice Lambson
JeremyLikness
Jeremy Likness
lajones
lajones
maumar
Maurycy Markowski
roji
Shay Rojansky
smitpatel
Smit Patel

Thank you to our contributors!

A big thank you to the following community members who have already contributed code or documentation to the EF Core 5 release! (List is in chronological order of first contribution to EF Core 5).

aevitas
aevitas
alaatm
Alaa Masoud
aleksandar-manukov
Aleksandar Manukov
amrbadawy
Amr Badawy
AnthonyMonterrosa
Anthony Monterrosa
bbrandt
Ben Brandt
benmccallum
Ben McCallum
ccjx
Clarence Cai
CGijbels
Christophe Gijbels
cincuranet
Jiri Cincura
Costo
Vincent Costel
dshuvaev
Dmitry Shuvaev
EricStG
Eric St-Georges
ErikEJ
Erik Ejlskov Jensen
gravbox
Christopher Davis
ivaylokenov
Ivaylo Kenov
jfoshee
Jacob Foshee
jmzagorski
Jeremy Zagorski
jviau
Jacob Viau
knom
Max K.
lohoris-crane
lohoris-crane
loic-sharma
Loïc Sharma
lokalmatador
lokalmatador
mariusGundersen
Marius Gundersen
Marusyk
Roman Marusyk
matthiaslischka
Matthias Lischka
MaxG117
MaxG117
MHDuke
MHDuke
mikes-gh
Mike Surcouf
Muppets
Neil Bostrom
nmichels
Nícolas Michels
OOberoi
Obi Oberoi
orionstudt
Josh Studt
ozantopal
Ozan Topal
pmiddleton
Paul Middleton
prog-rajkamal
Raj
ptjhuang
Peter Huang
ralmsdeveloper
Rafael Almeida Santos
redoz
Patrik Husfloen
rmarskell
Richard Marskell
sguitardude
sguitardude
SimpleSamples
Sam Hobbs
svengeance
Sven
VladDragnea
Vlad
vslee
vslee
WeihanLi
liweihan
Youssef1313
Youssef Victor
1iveowl
1iveowl
thomaslevesque
Thomas Levesque
akovac35
Aleksander Kovač
leotsarev
Leonid Tsarev
kostat
Konstantin Triger
sungam3r
Ivan Maximov
dzmitry-lahoda
Dzmitry Lahoda
Logerfo
Bruno Logerfo
witheej
Josh Withee
FransBouma
Frans Bouma
IGx89
Matthew Lieder
paulomorgado
Paulo Morgado
mderriey
Mickaël Derriey
LaurenceJKing
Laurence King
oskarj
Oskar Josefsson
bdebaere
bdebaere
BhargaviAnnadevara-MSFT
Bhargavi Annadevara
AlexanderTaeschner
Alexander Täschner
Jesse-Hufstetler
Jesse Hufstetler
ivarlovlie
Ivar Løvlie
cucoreanu
cucoreanu

Author

Jeremy Likness
Principal Program Manager - .NET Web Frameworks

Jeremy is a Principal Program Manager for .NET Web Frameworks at Microsoft. Jeremy wrote his first program in 1982, was recognized in the "who's who in Quake" list for programming the first implementation of "Midnight Capture the Flag" in Quake C and has been developing enterprise applications for 25 years with a primary focus on web-based delivery of line of business applications. Jeremy is the author of four technology books, a former 8-year Microsoft MVP for Developer Tools and Technologies, ...

More about author

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • petr petr

    This is a gret Platform

    • Ian Marteens

      Yeah, gret for fret (still waiting for a usable version).