{"id":37836,"date":"2021-11-29T11:05:02","date_gmt":"2021-11-29T18:05:02","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=37836"},"modified":"2021-12-06T11:24:08","modified_gmt":"2021-12-06T18:24:08","slug":"get-to-know-ef-core-6","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/get-to-know-ef-core-6\/","title":{"rendered":"Get to Know EF Core 6"},"content":{"rendered":"<p>The Entity Framework Core team has released the generally available version of EF Core 6.0 in parallel with <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-6\/\">.NET 6<\/a>.\nEF Core 6 is available as a set of <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/6.0.0\">NuGet Packages<\/a>. At the end of this blog post you will find a <a href=\"#packages\">packages<\/a> section that lists all of the\navailable packages and describes what they are used for.<\/p>\n<p>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 &#8220;out of the box&#8221;, and can even run inside your browser!<\/p>\n<p>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 <a href=\"https:\/\/youtu.be\/kesUNeBZ1Os\">Steven Sanderson&#8217;s excellent video<\/a> 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.<\/p>\n<p>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.<\/p>\n<p>The first step in your journey should always be the comprehensive documentation available online at <a href=\"https:\/\/docs.microsoft.com\/ef\">https:\/\/docs.microsoft.com\/ef<\/a>. There you will find\neverything from a <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/get-started\/overview\/first-app\">step-by-step guide to build your first EF Core app<\/a> to a comprehensive list of <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew\">what&#8217;s new in EF Core 6<\/a>. If you find anything missing, let us know via <a href=\"https:\/\/github.com\/dotnet\/EntityFramework.Docs\/issues\">GitHub issues<\/a> and\/or\nsubmit a pull request.<\/p>\n<blockquote><p><strong>Note<\/strong>: various samples ready to build and run are available on GitHub at: <a href=\"https:\/\/github.com\/dotnet\/EntityFramework.Docs\/tree\/main\/samples\/core\/Miscellaneous\/NewInEFCore6\">What&#8217;s New in EF Core 6 Samples<\/a>.<\/p><\/blockquote>\n<p>Check out our <a href=\"https:\/\/youtu.be\/cx6IUURncgk\">EF Core Community Standup EF Core 6.0 retrospective<\/a> to hear from the team and several community members about the release. We also presented <a href=\"https:\/\/youtu.be\/_1fJeW4F3ts\">What&#8217;s New with EF Core 6.0<\/a> at .NET Conf 2021. Be sure to check out community member Julie Lerman&#8217;s comprehensive article <a href=\"https:\/\/codemag.com\/Article\/2111072\/EF-Core-6-Fulfilling-the-Bucket-List\">EF Core 6: Fulfilling the Bucket List<\/a>.<\/p>\n<p>For excellent advice regarding updating your existing apps, read <a href=\"https:\/\/www.thereformedprogrammer.net\/updating-your-asp-net-core-ef-core-application-to-net-6\/\">Updating your ASP.NET Core and\/or EF Core Application to .NET 6<\/a>.<\/p>\n<h2>Get to Know EF Core 6.0<\/h2>\n<p>The following major areas were added or improved in EF Core 6.0, and each has several resources to help you get started.<\/p>\n<h3>Azure Cosmos DB<\/h3>\n<p>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.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/zQC9D00pr6I\">.NET Conf: EF Core 6 and Azure Cosmos DB<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/nEqH_XfCfho\">Azure Cosmos DB and EF Core<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/VUyavt95CkQ\">Cosmos Live TV: What&#8217;s New with EF Core 6 for Cosmos DB<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/MicJm1hRNKU\">On .NET: Working with EF Core and Azure Cosmos DB<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcc3 Official Docs<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew#cosmos-provider-enhancements\">Cosmos Provider Enhancements<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Compiled Models<\/h3>\n<p>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.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/XdhX3iLXAPk\">Introducing EF Core Compiled Models<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcd6 Blog Post<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-entity-framework-core-6-0-preview-5-compiled-models\/\">Compiled Models<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcc3 Official Docs<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew#compiled-models\">Compiled Models<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Configure Conventions<\/h3>\n<p>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.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcd6 Blog Post<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-entity-framework-core-6-0-preview-6-configure-conventions\/\">Configure Conventions<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcc3 Official Docs<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew#pre-convention-model-configuration\">Pre-convention Model Configuration<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Migration Bundles<\/h3>\n<p>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.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcd6 Blog Post<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-devops-friendly-ef-core-migration-bundles\/\">Introducing DevOps-friendly EF Core Migration Bundles<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcc3 Official Docs<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew#migration-bundles\">Migration Bundles<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Performance<\/h3>\n<p>The team&#8217;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.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/bXZCdoKpjts\">Julie Lerman on Performance<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/Zhy5antRDJk\">Visualizing Database Query Plans<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/VgNFFEqwZPU\">Performance Tuning an EF Core Application<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcd6 Blog Post<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-entity-framework-core-6-0-preview-4-performance-edition\/\">EF Core Performance<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcc3 Official Docs<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew#improved-performance-on-techempower-fortunes\">Improved Performance on TechEmpower Fortunes<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Temporal Tables<\/h3>\n<p>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.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/2aCgKM41NFw\">SQL Server Temporal Tables and EF Core 6<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcd6 Blog Post<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/prime-your-flux-capacitor-sql-server-temporal-tables-in-ef-core-6-0\/\">Prime your flux capacitor: SQL Server temporal tables in EF Core 6<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83d\udcc3 Official Docs<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-6.0\/whatsnew#sql-server-temporal-tables\">SQL Server Temporal Tables<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>GraphQL<\/h3>\n<p>The team focused on the GraphQL experience and although there aren&#8217;t specific changes in EF Core 6.0 related to GraphQL, here are some resources that show how well the two technologies work together.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Resource Type<\/th>\n<th style=\"text-align: left;\">Title<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/GBvTRcV4PVA\">Modern Data APIs with EF Core and GraphQL<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\ud83c\udf9e\ufe0f Video<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/youtu.be\/4nqjB_z5CU0\">GraphQL with EF Core 6 and HotChocolate 12<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Packages<\/h2>\n<p>The EF Core packages for EF Core 6 include:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/6.0.0\">Microsoft.EntityFrameworkCore<\/a> &#8211; The main EF Core package<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.SqlServer\/6.0.0\">Microsoft.EntityFrameworkCore.SqlServer<\/a> &#8211; Database provider for Microsoft SQL Server and SQL Azure<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite\/6.0.0\">Microsoft.EntityFrameworkCore.Sqlite<\/a> &#8211; Database provider for SQLite<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Cosmos\/6.0.0\">Microsoft.EntityFrameworkCore.Cosmos<\/a> &#8211; Database provider for Azure Cosmos DB<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.InMemory\/6.0.0\">Microsoft.EntityFrameworkCore.InMemory<\/a> &#8211; The in-memory database provider<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Tools\/6.0.0\">Microsoft.EntityFrameworkCore.Tools<\/a> &#8211; EF Core PowerShell commands for the Visual Studio Package Manager Console<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Design\/6.0.0\">Microsoft.EntityFrameworkCore.Design<\/a> &#8211; Shared design-time components for EF Core tools<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite\/6.0.0\">Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite<\/a> &#8211; SQL Server support for spatial types<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite\/6.0.0\">Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite<\/a> &#8211; SQLite support for spatial types<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Proxies\/6.0.0\">Microsoft.EntityFrameworkCore.Proxies<\/a> &#8211; Lazy-loading and change-tracking proxies<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Abstractions\/6.0.0\">Microsoft.EntityFrameworkCore.Abstractions<\/a> &#8211; Decoupled EF Core abstractions<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Relational\/6.0.0\">Microsoft.EntityFrameworkCore.Relational<\/a> &#8211; Shared EF Core components for relational database providers<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Analyzers\/6.0.0\">Microsoft.EntityFrameworkCore.Analyzers<\/a> &#8211; C# analyzers for EF Core<\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite.Core\/6.0.0\">Microsoft.EntityFrameworkCore.Sqlite.Core<\/a> &#8211; Database provider for SQLite without a packaged native binary<\/li>\n<\/ul>\n<p>We have also published the 6.0.0 release of the <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Data.Sqlite.Core\/6.0.0\">Microsoft.Data.Sqlite.Core<\/a> ADO.NET provider.<\/p>\n<h2>Installing dotnet ef<\/h2>\n<p>To execute EF Core migration or scaffolding commands, you&#8217;ll have to install the EF Tools package as either a global or local tool.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2021\/11\/dotnetef.png\" alt=\"EF Tool\" \/><\/p>\n<p>If you already installed a previous version of the tool, update it with<\/p>\n<pre><code class=\"language-cmd\">dotnet tool update --global dotnet-ef<\/code><\/pre>\n<p>If this is your first time installing the tool, use:<\/p>\n<pre><code class=\"language-cmd\">dotnet tool install --global dotnet-ef<\/code><\/pre>\n<p>It&#8217;s possible to use this new version of <code>dotnet ef<\/code> with projects that use older versions of the EF Core runtime. For more information on the tool, read: <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/get-started\/overview\/install#get-the-entity-framework-core-tools\">Get the Entity Framwork Core Tools<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>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!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to download and work with EF Core 6 and new features from improved support for Azure Cosmos DB to increased performance and first-class APIs to SQL Server temporal tables.<\/p>\n","protected":false},"author":368,"featured_media":37835,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,859],"tags":[7239,7250,7594,70],"class_list":["post-37836","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-entity-framework","tag-dotnet-6","tag-ef-core","tag-ef-core-6","tag-entity-framework"],"acf":[],"blog_post_summary":"<p>Learn how to download and work with EF Core 6 and new features from improved support for Azure Cosmos DB to increased performance and first-class APIs to SQL Server temporal tables.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/37836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/368"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=37836"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/37836\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/37835"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=37836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=37836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=37836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}