Announcing Entity Framework Core 6.0 Preview 2

Jeremy Likness

Today, the Entity Framework Core team announces the second preview release ofEF Core 6.0.This release includes changes to handling the synchronization context when SaveChangesAsync is called, smoother integration with System.Linq.Async, updates to string concatenation and improvements to free text search.


  • EF Core 6.0 currently targets .NET 5. This will likely be updated to .NET 6 as we near the release. EF Core 6.0 does not target any .NET Standard version; for more information see the future of .NET Standard.
  • EF Core 6.0 will not run on .NET Framework.

How to get EF Core 6.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 CLI:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --prerelease

This following table links to the preview 2 versions of the EF Core packages and describes what they are used for.

Microsoft.EntityFrameworkCoreThe main EF Core package that is independent of specific database providers
Microsoft.EntityFrameworkCore.SqlServerDatabase provider for Microsoft SQL Server and SQL Azure
Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuiteSQL Server support for spatial types
Microsoft.EntityFrameworkCore.SqliteDatabase provider for SQLite that includes the native binary for the database engine
Microsoft.EntityFrameworkCore.Sqlite.CoreDatabase provider for SQLite without a packaged native binary
Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuiteSQLite support for spatial types
Microsoft.EntityFrameworkCore.CosmosDatabase provider for Azure Cosmos DB
Microsoft.EntityFrameworkCore.InMemoryThe in-memory database provider
Microsoft.EntityFrameworkCore.ToolsEF Core PowerShell commands for the Visual Studio Package Manager Console; use this to integrate tools like scaffolding and migrations with Visual Studio
Microsoft.EntityFrameworkCore.DesignShared design-time components for EF Core tools
Microsoft.EntityFrameworkCore.ProxiesLazy-loading and change-tracking proxies
Microsoft.EntityFrameworkCore.AbstractionsDecoupled EF Core abstractions; use this for features like extended data annotations defined by EF Core
Microsoft.EntityFrameworkCore.RelationalShared EF Core components for relational database providers
Microsoft.EntityFrameworkCore.AnalyzersC# analyzers for EF Core

We also published the 6.0 preview 2 release of the Microsoft.Data.Sqlite.Core provider for ADO.NET.

Installing the EF Core Command Line Interface (CLI)

As with EF Core 3.0 and 3.1, the EF Core CLI 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 6.0.0-preview.2.21154.2

It’s possible to use this new version of the EF Core CLI with projects that use older versions of the EF Core runtime.

What’s New in EF Core 6 Preview 2

We maintain documentation covering new features introduced into each preview.

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

TIPYou can run and debug into all the preview 2 samples shown below by downloading the sample code from GitHub.

NOTEThe following fix did not make it into Preview 2: #24251.

Preserve synchronization context in SaveChangesAsync

GitHub Issue: #23971.

We changed the EF Core code in the 5.0 release to set System.Threading.Tasks.Task.ConfigureAwait to false in all places where we await async code. This is generally a better choice for EF Core usage. However, Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync is a special case because EF Core will set generated values into tracked entities after the async database operation is complete. These changes may then trigger notifications which, for example, may have to run on the U.I. thread. Therefore, we are reverting this change in EF Core 6.0 for the Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync method only.

Translate String.Concat with multiple arguments

GitHub Issue: #23859. This feature was contributed by @wmeints.

Starting with EF Core 6.0, calls to System.String.Concat with multiple arguments are now translated to SQL. For example, the following query:

var shards = context.Shards
  .Where(e => string.Concat(e.Token1, e.Token2, e.Token3) != e.TokensProcessed).ToList();

Will be translated to the following SQL when using SQL Server:

SELECT [s].[Id], [s].[Token1], [s].[Token2], [s].[Token3], [s].[TokensProcessed]
FROM [Shards] AS [s]
WHERE ((COALESCE([s].[Token1], N'') + (COALESCE([s].[Token2], N'') + COALESCE([s].[Token3], N''))) <> [s].[TokensProcessed]) OR [s].[TokensProcessed] IS NULL

Smoother integration with System.Linq.Async

GitHub Issue: #24041.

The System.Linq.Async package adds client-side async LINQ processing. Using this package with previous versions of EF Core was cumbersome due to a namespace clash for the async LINQ methods. In EF Core 6.0 we have taken advantage of C# pattern matching for System.Collections.Generic.IAsyncEnumerable such that the exposed EF Core Microsoft.EntityFrameworkCore.DbSet does not need to implement the interface directly.

Note that most applications do not need to use System.Linq.Async since EF Core queries are usually fully translated on the server.

GitHub Issue: #23921.

In EF Core 6.0, we have relaxed the parameter requirements for Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.FreeText(Microsoft.EntityFrameworkCore.DbFunctions,System.String,System.String) and Microsoft.EntityFrameworkCore.SqlServerDbFunctionsExtensions.Contains. This allows these functions to be used with binary columns, or with columns mapped using a value converter. For example, consider an entity type with a Name property defined as a value object:

public class Customer
  public int Id { get; set; }

  public Name Name{ get; set; }

public class Name
  public string First { get; set; }
  public string MiddleInitial { get; set; }
  public string Last { get; set; }

This is mapped to JSON in the database:

  .Property(e => e.Name)
    v => JsonSerializer.Serialize(v, null),
    v => JsonSerializer.Deserialize<Name>(v, null));

A query can now be executed using Contains or FreeText even though the type of the property is Name not string. For example:

var result = context.Customers.Where(e => EF.Functions.Contains(e.Name, "Martin")).ToList();

This generates the following SQL, when using SQL Server:

SELECT [c].[Id], [c].[Name]
FROM [Customers] AS [c]
WHERE CONTAINS([c].[Name], N'Martin')

Daily builds

EF Core previews are aligned with .NET 6 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 require .NET 5.

The EF Core Community Standup

The EF Core team is now live streaming every other Wednesday at 10am Pacific Time, 1pm Eastern Time, or 17:00 UTC. Join the stream to ask questions about the EF Core topic of your choice, including the latest preview release.

Documentation and Feedback

The starting point for all EF Core documentation is

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.

EF Core Community Standup Playlist:

Main documentation:

Issues and feature requests for EF Core:

Entity Framework Roadmap:

Thank you from the team

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

ajcvickersArthur VickersAndriySvyrydAndriy SvyrydBrice LambsonJeremyLiknessJeremy Likness
maumarMaurycy MarkowskirojiShay RojanskysmitpatelSmit Patel

Thank you to our contributors!

We are grateful to our amazing community of contributors. Our success is founded upon the shoulders of your efforts and feedback. If you are interested in contributing but not sure how or would like help, please reach out to us! We want to help you succeed. We would like to publicly acknowledge and thank these contributors for investing in the success of EF Core 6.0.

#1, #2#1#1#1, #2
#1, #2#1#1#1
#1, #2, #3, #4, #5, #6#1#1, #2, #3, #4, #5, #6, #7, #8#1, #2
#1, #2#1, #2, #3#1#1, #2
#1, #2, #3, #4#1#1#1, #2
#1#1#1, #2#1, #2
#1#1, #2, #3, #4#1, #2#1
#1#1#1#1, #2, #3, #4, #5, #6, #7, #8
#1#1#1, #2#1
#1#1#1#1, #2
#1, #2, #3, #4#1#1#1, #2
#1, #2, #3, #4, #5, #6, #7, #8#1#1, #2#1, #2
#1, #2#1, #2#1, #2, #3, #4#1, #2
#1, #2#1, #2, #3, #4