Announcing Entity Framework Core 5.0 Preview 2
Today we are excited to announce the second preview release of EF Core 5.0.
The second 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.2.20159.4
The EF Core packages published today are:
- Microsoft.EntityFrameworkCore – The main EF Core package
- Microsoft.EntityFrameworkCore.SqlServer – Database provider for Microsoft SQL Server and SQL Azure
- Microsoft.EntityFrameworkCore.Sqlite – Database provider for SQLite
- Microsoft.EntityFrameworkCore.Cosmos – Database provider for Azure Cosmos DB
- Microsoft.EntityFrameworkCore.InMemory – The in-memory database provider
- Microsoft.EntityFrameworkCore.Tools – EF Core PowerShell commands for the Visual Studio Package Manager Console
- Microsoft.EntityFrameworkCore.Design – Shared design-time components for EF Core tools
- Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite – SQL Server support for spatial types
- Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite – SQLite support for spatial types
- Microsoft.EntityFrameworkCore.Proxies – Lazy-loading and change-tracking proxies
- Microsoft.EntityFrameworkCore.Abstractions – Decoupled EF Core abstractions
- Microsoft.EntityFrameworkCore.Relational – Shared EF Core components for relational database providers
- Microsoft.EntityFrameworkCore.Analyzers – C# analyzers for EF Core
- Microsoft.EntityFrameworkCore.Sqlite.Core – Database provider for SQLite without a packaged native binary
We have also published the 5.0 preview 2 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.
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.2.20159.4
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 2
We maintain documentation covering new features introduced into each preview.
Some of the highlights from preview 2 are called out below.
Use a C# attribute to specify a property backing field
A C# attribute can now be used to specify the backing field for a property. This allows EF Core to still write to and read from the backing field as would normally happen, even when the backing field cannot be found automatically. For example:
public class Blog
{
private string _mainTitle;
public int Id { get; set; }
[BackingField(nameof(_mainTitle))]
public string Title
{
get => _mainTitle;
set => _mainTitle = value;
}
}
Documentation is tracked by issue #2230.
Complete discriminator mapping
EF Core uses a discriminator column for TPH mapping of an inheritance hierarchy. Some performance enhancements are possible so long as EF Core knows all possible values for the discriminator. EF Core 5.0 now implements these enhancements.
For example, previous versions of EF Core would always generate this SQL for a query returning all types in a hierarchy:
SELECT [a].[Id], [a].[Discriminator], [a].[Name]
FROM [Animal] AS [a]
WHERE [a].[Discriminator] IN (N'Animal', N'Cat', N'Dog', N'Human')
EF Core 5.0 will now generate the following when a complete discriminator mapping is configured:
SELECT [a].[Id], [a].[Discriminator], [a].[Name]
FROM [Animal] AS [a]
This will be the default behavior starting with preview 3.
Performance improvements in Microsoft.Data.Sqlite
We have made two performance improvements for SQLIte:
- Retrieving binary and string data with
GetBytes
,GetChars
, andGetTextReader
is now more efficient by making use ofSqliteBlob
and streams. - Initialization of
SqliteConnection
is now lazy.
These improvements are in the ADO.NET Microsoft.Data.Sqlite provider and hence also improve performance outside of EF Core.
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
The starting point for all EF Core documentation is docs.microsoft.com/ef/core/.
Please file issues found and any other feedback on the dotnet/efcore GitHub repo.
Thank you from the team
A big thank you from the EF team to everyone who has used EF over the years!
Arthur Vickers |
Andriy Svyryd |
Brice Lambson |
Jeremy Likness |
lajones |
Maurycy Markowski |
Shay Rojansky |
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!
What's the point of .NET Standard 2.1 if it doesn't run on .NET Framework? What advantages does it give you over .NET Standard 2.0? I think you should go back to using 2.0 so that you can continue supporting .NET Framework. There are a lot of legacy ASP.NET Web Forms applications out there. I just upgraded to 3.1. Are you going to continue patching 3.1? Why did you switch from .NET Standard 2.1 in EF...
.NET Standard 2.1 expanded the API surface area significantly to make more cross-platform scenarios a reality. It is also a stepping stone to the single .NET 5 solution. EF Core 3.x should continue to work fine, EF6 works for both .NET Core and .NET Framework, EF Core 5.x is recommended when you move to .NET 5.
What about xamarin?
Xamarin is supported by EF Core. There are some nuances with how the application is compiled/deployed that we are working with the mobile teams to address and document.
Why would it even be worth your time to update a legacy ASP.NET Web Forms app to EF Core 5, let alone EF Core? EF6 worked just fine for a 10-year-old legacy ASP.NET Web Forms app I supported, never needed to update it.
Maybe because startup performance in EF 6 was horrible for projects with large number of entities, so, I upgraded to EF Core a long time ago. EF Core has been missing features this whole time. Years later, features, such as not having to jump through massive hoops to get something like logging working. Things that are broken in the query engine. In retrospect, yes, it was a big waste of time. I would have been...
Maybe Spans and all this low-level memory stuff?
“These improvements are in the ADO.NET Microsoft.Data.Sqlite provider and hence also improve performance outside of EF Core.”
Can we use these improvements (MS.Data.Sqlite 5 prev2) alongside with EF Core 3.1 to improve our existing mobile apps?
We haven’t tested that combination. Our recommendation is to use the 5.x bits with .NET 5.x. This doesn’t mean it won’t work, it’s just not a path we are explicitly testing and supporting.