November 29th, 2021

Get to Know EF Core 6

Jeremy Likness
Principal Program Manager - .NET Web Frameworks

The Entity Framework Core team has released the generally available version of EF Core 6.0 in parallel with .NET 6. EF Core 6 is available as a set of NuGet Packages. At the end of this blog post you will find a packages section that lists all of the available packages and describes what they are used for.

EF Core 6.0 is a modern, cloud-native-friendly data access API that supports multiple backends. Get up and running with a document-based Azure Cosmos DB container using only a few lines of code, or use your LINQ query skills to extract the data you need from relational databases like SQL Server, MySQL, and PostgreSQL. EF Core is a cross-platform solution that runs on mobile devices, works with data-binding in client WinForms and WPF apps “out of the box”, and can even run inside your browser!

Did you know it is possible to embed a SQLite database in a web app and use Blazor WebAssembly to access it using EF Core? Check out Steven Sanderson’s excellent video to see how this is possible. Combined with the power of .NET 6, EF Core 6.0 delivers major performance improvements and even scored 92% better on the industry standard Tech Empower Fortunes benchmark compared to EF Core 5.0 running on .NET 5. The EF Core team and global OSS community have built and published many resources to help you get started.

This blog post lists a few ways to learn about new features and get up and running with Entity Framework Core as quickly as possible.

The first step in your journey should always be the comprehensive documentation available online at https://docs.microsoft.com/ef. There you will find everything from a step-by-step guide to build your first EF Core app to a comprehensive list of what’s new in EF Core 6. If you find anything missing, let us know via GitHub issues and/or submit a pull request.

Note: various samples ready to build and run are available on GitHub at: What’s New in EF Core 6 Samples.

Check out our EF Core Community Standup EF Core 6.0 retrospective to hear from the team and several community members about the release. We also presented What’s New with EF Core 6.0 at .NET Conf 2021. Be sure to check out community member Julie Lerman’s comprehensive article EF Core 6: Fulfilling the Bucket List.

For excellent advice regarding updating your existing apps, read Updating your ASP.NET Core and/or EF Core Application to .NET 6.

Get to Know EF Core 6.0

The following major areas were added or improved in EF Core 6.0, and each has several resources to help you get started.

Azure Cosmos DB

The EF Core team invested heavily to ensure that working with Azure Cosmos DB is a first class experience. From simplifying configuration to supporting raw SQL and delivering diagnostics, we believe this is a full featured option for working with the popular NoSQL database.

Resource Type Title
🎞️ Video .NET Conf: EF Core 6 and Azure Cosmos DB
🎞️ Video Azure Cosmos DB and EF Core
🎞️ Video Cosmos Live TV: What’s New with EF Core 6 for Cosmos DB
🎞️ Video On .NET: Working with EF Core and Azure Cosmos DB
📃 Official Docs Cosmos Provider Enhancements

Compiled Models

EF Core parses configuration information to build a working model of how the domain maps to the underlying database. The time it takes to compile the memory increases as the number of entities, properties, and relationships grows. Customers with apps in distributed environments or using platforms like Azure Functions require fast startup times. Compiled models addresses this by building the model at development time, significantly improve the time to first query result.

Resource Type Title
🎞️ Video Introducing EF Core Compiled Models
📖 Blog Post Compiled Models
📃 Official Docs Compiled Models

Configure Conventions

Imagine you want to impose a string column length limit of 200 characters on every table in your database. If you have hundreds of entities, this would require either applying data annotations or performing fluent configuration for every table. Pre-configuration conventions allow you to specify a rule as a convention that becomes the default unless you opt-out. This can potentially save hundreds of lines of code and allows you to make changes in a single place.

Resource Type Title
📖 Blog Post Configure Conventions
📃 Official Docs Pre-convention Model Configuration

Migration Bundles

A popular feature of EF Core is the ability to track schema changes by version for your database. This capability is called migrations. Traditionally, migrations are embedded in your target application. They would require you to deploy the app along with the .NET SDKs and runtime to execute. To simplify this step as a part of continuous deployment, the EF Core team built migration bundles. These are self-contained, standalone executables that apply the migrations as part of your CI/CD pipeline.

Resource Type Title
📖 Blog Post Introducing DevOps-friendly EF Core Migration Bundles
📃 Official Docs Migration Bundles

Performance

The team’s aggressive focus on performance resulted in a 92% improvement for the full stack of EF Core 6 on .NET 6 over EF Core 5 on .NET 5 according to the industry standard TechEmpower benchmark.

Resource Type Title
🎞️ Video Julie Lerman on Performance
🎞️ Video Visualizing Database Query Plans
🎞️ Video Performance Tuning an EF Core Application
📖 Blog Post EF Core Performance
📃 Official Docs Improved Performance on TechEmpower Fortunes

Temporal Tables

SQL Server supports temporal tables. This is an audit mechanism that tracks every change to a database table and exposes it in a queryable format. EF Core recently added first class support to create, query, and even restore entries from temporal tables.

Resource Type Title
🎞️ Video SQL Server Temporal Tables and EF Core 6
📖 Blog Post Prime your flux capacitor: SQL Server temporal tables in EF Core 6
📃 Official Docs SQL Server Temporal Tables

GraphQL

The team focused on the GraphQL experience and although there aren’t specific changes in EF Core 6.0 related to GraphQL, here are some resources that show how well the two technologies work together.

Resource Type Title
🎞️ Video Modern Data APIs with EF Core and GraphQL
🎞️ Video GraphQL with EF Core 6 and HotChocolate 12

Packages

The EF Core packages for EF Core 6 include:

We have also published the 6.0.0 release of the Microsoft.Data.Sqlite.Core ADO.NET provider.

Installing dotnet ef

To execute EF Core migration or scaffolding commands, you’ll have to install the EF Tools package as either a global or local tool.

EF Tool

If you already installed a previous version of the tool, update it with

dotnet tool update --global dotnet-ef

If this is your first time installing the tool, use:

dotnet tool install --global dotnet-ef

It’s possible to use this new version of dotnet ef with projects that use older versions of the EF Core runtime. For more information on the tool, read: Get the Entity Framwork Core Tools.

Conclusion

Speed. Performance. Improved capabilities across the board. This version of EF Core 6.0 is optimized to work on your platform of choice and connect to your database of choice. Accelerate your development and speed up your performance and make the move to EF Core 6.0!

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

3 comments

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

  • Jens Samson

    What about migrating from L2S ?
    We have been using L2S since it came out, and I’m sure we’re not the only ones.
    Will we ever be offered a migration path to EF Core 6 ? A manual migration is simply too much work, so without a migration path we’ll be tied to the .Net framework like forever.

  • hitesh davey · Edited

    EF Core 6 has lots of improvements. Good job. This will be useful when building New Projects.

    Now the question is what about the existing codebase using ADO.NET?

    Can you pl share some lights on ADO.NET improvements done in DOTNET 6 platform? I am not seeing any blog or text discussing what's new or improved in ADO.NET. We have many LOB apps which are using ADO.NET extensively for data access and it is too late to port...

    Read more