{"id":39427,"date":"2022-04-13T10:16:28","date_gmt":"2022-04-13T17:16:28","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=39427"},"modified":"2022-04-13T10:16:28","modified_gmt":"2022-04-13T17:16:28","slug":"announcing-entity-framework-7-preview-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-entity-framework-7-preview-3\/","title":{"rendered":"Announcing Entity Framework Core 7 (EF7) Preview 3"},"content":{"rendered":"<p>Today, the .NET data team announces the third preview release of\n<a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/7.0.0-preview.3.22175.1\">EF Core 7.0 (EF7)<\/a>.\nIn addition to bug fixes and foundation work for larger features, we are pleased to announce the initial preview of scaffolding (database-first) templates. This preview also includes changes to the update pipeline to improve performance and streamline the generated SQL, and support for TPC in migrations.\nBe sure to read the <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/what-is-new\/ef-core-7.0\/plan\">full plan for EF7<\/a> to learn what&#8217;s on the roadmap.<\/p>\n<p>You can also view the <a href=\"https:\/\/github.com\/dotnet\/efcore\/issues?q=is%3Aclosed+is%3Aissue+milestone%3A7.0.0-preview3+\">full list of issues addressed in EF7 Preview 3<\/a>.<\/p>\n<h2>Improvements to the update pipeline<\/h2>\n<p>Several improvements to the update pipeline are now part of Preview 3, including:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/pull\/27573\">Improve SQL Server insertion logic<\/a> (also make RETURNING the default INSERT strategy for retrieving db-generated values for other providers).<\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/pull\/27663\">Use RETURNING\/OUTPUT clause for UPDATE\/DELETE<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/pull\/27584\">Refactor ReaderModificationCommandBatch<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/pull\/27696\">Reimplement MaxBatchSize as a pre-check<\/a><\/li>\n<\/ul>\n<h2>Take control of your DbContext<\/h2>\n<p>Preview 3 introduces the ability to control how EF7 reverse engineers or scaffolds classes for database-first projects using <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/modeling\/code-generation-and-t4-text-templates\">T4 templates<\/a>.\nDo you prefer &#8220;null bang&#8221; setters? Property initializers? Constructor initialization? All these customizations are now possible. In fact, you are not limited to generating\nthe &#8220;traditional&#8221; DbContext and entity classes. Anything is possible, including using the templates to generate documentation.<\/p>\n<p>The best way to learn about this new feature is to watch our recent community standup: <a href=\"https:\/\/youtu.be\/x2nh1vZBsHE\">Database-first with T4 templates in EF7<\/a>. The video\nbegins with an introduction to T4 templates for those of you who are not familiar with them. The EF7 feature is introduced about 23 minutes in. In addition to generating custom code, the demo shows how to create markdown using Mermaid syntax to generate ERD diagrams.<\/p>\n<p>Code like this:<\/p>\n<pre><code class=\"language-mermaid\">\r\n```mermaid\r\nerDiagram\r\n    ORDERMASTER ||--o{ ORDERDETAIL : owns\r\n    ORDERDETAIL ||--|{ LINE-ITEM : contains\r\n    ORDERMASTER }|..|{ CUSTOMER : uses\r\n```<\/code><\/pre>\n<p>Produces diagrams like this:<\/p>\n<p><figure id=\"attachment_39431\" aria-labelledby=\"figcaption_attachment_39431\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2022\/04\/mermaidexample.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2022\/04\/mermaidexample.png\" alt=\"An ERD diagram\" width=\"400\" height=\"527\" class=\"size-full wp-image-39431\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2022\/04\/mermaidexample.png 400w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2022\/04\/mermaidexample-228x300.png 228w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"figcaption_attachment_39431\" class=\"wp-caption-text\">Mermaid ERD Diagram<\/figcaption><\/figure><\/p>\n<p>You can get started in 3 steps:<\/p>\n<ul>\n<li>Include the Preview 3 <code>Microsoft.EntityFrameworkCore.Design<\/code> package in your project (this will also work with the daily builds). <\/li>\n<li>Install or update the <code>dotnet-ef<\/code> tool either globally or locally using a <a href=\"https:\/\/docs.microsoft.com\/dotnet\/core\/tools\/global-tools#install-a-local-tool\">tool manifest<\/a>.<\/li>\n<li>Create the <code>DbContext.t4<\/code> and <code>EntityType.t4<\/code> T4 templates in a folder named <code>CodeTemplates<\/code>. EF7 will pick these up by convention.<\/li>\n<\/ul>\n<p>For more details, watch the <a href=\"https:\/\/youtu.be\/x2nh1vZBsHE\">community standup demo<\/a>.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>EF7 currently targets .NET 6. This will likely be updated to .NET 7 as we near the release. <\/li>\n<li>EF7 will not run on .NET Framework.<\/li>\n<\/ul>\n<p>EF7 is the successor to EF Core 6.0, not to be confused with <a href=\"https:\/\/github.com\/dotnet\/ef6\">EF6<\/a>. If you are considering upgrading from EF6, please read our guide to <a href=\"https:\/\/docs.microsoft.com\/ef\/efcore-and-ef6\/porting\/\">port from EF6 to EF Core<\/a>.<\/p>\n<hr \/>\n<h2>How to get EF7 previews<\/h2>\n<p>EF7 is distributed exclusively as a set of NuGet packages.\nFor example, to add the SQL Server provider to your project, you can use the following command using the dotnet tool:<\/p>\n<pre><code class=\"language-bash\">dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 7.0.0-preview.3.22175.1<\/code><\/pre>\n<p>This following table links to the preview 3 versions of the EF Core packages and describes what they are used for.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: right\"><strong>Package<\/strong><\/th>\n<th style=\"text-align: left\"><strong>Purpose<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore<\/a><\/td>\n<td style=\"text-align: left\">The main EF Core package that is independent of specific database providers<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.SqlServer\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.SqlServer<\/a><\/td>\n<td style=\"text-align: left\">Database provider for Microsoft SQL Server and SQL Azure<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite<\/a><\/td>\n<td style=\"text-align: left\">SQL Server support for spatial types<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Sqlite<\/a><\/td>\n<td style=\"text-align: left\">Database provider for SQLite that includes the native binary for the database engine<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite.Core\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Sqlite.Core<\/a><\/td>\n<td style=\"text-align: left\">Database provider for SQLite <em>without<\/em> a packaged native binary<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite<\/a><\/td>\n<td style=\"text-align: left\">SQLite support for spatial types<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Cosmos\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Cosmos<\/a><\/td>\n<td style=\"text-align: left\">Database provider for Azure Cosmos DB<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.InMemory\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.InMemory<\/a><\/td>\n<td style=\"text-align: left\">The in-memory database provider<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Tools\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Tools<\/a><\/td>\n<td style=\"text-align: left\">EF Core PowerShell commands for the Visual Studio Package Manager Console; use this to integrate tools like <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/managing-schemas\/scaffolding\">scaffolding<\/a> and <a href=\"https:\/\/docs.microsoft.com\/ef\/core\/managing-schemas\/migrations\/\">migrations<\/a> with Visual Studio<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Design\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Design<\/a><\/td>\n<td style=\"text-align: left\">Shared design-time components for EF Core tools<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Proxies\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Proxies<\/a><\/td>\n<td style=\"text-align: left\">Lazy-loading and change-tracking proxies<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Abstractions\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Abstractions<\/a><\/td>\n<td style=\"text-align: left\">Decoupled EF Core abstractions; use this for features like extended data annotations defined by EF Core<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Relational\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Relational<\/a><\/td>\n<td style=\"text-align: left\">Shared EF Core components for relational database providers<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: right\"><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.EntityFrameworkCore.Analyzers\/7.0.0-preview.3.22175.1\">Microsoft.EntityFrameworkCore.Analyzers<\/a><\/td>\n<td style=\"text-align: left\">C# analyzers for EF Core<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We also published the 7.0 preview 3 release of the <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Data.Sqlite.Core\/7.0.0-preview.3.22175.1\">Microsoft.Data.Sqlite.Core<\/a> provider for <a href=\"https:\/\/docs.microsoft.com\/dotnet\/framework\/data\/adonet\/ado-net-overview\">ADO.NET<\/a>.<\/p>\n<h2>Installing the EF7 Command Line Interface (CLI)<\/h2>\n<p>Before you can execute EF7 Core migration or scaffolding commands, you&#8217;ll have to install the CLI package as either a global or local tool.<\/p>\n<p>To install the preview tool globally, install with:<\/p>\n<pre><code class=\"language-bash\">dotnet tool install --global dotnet-ef --version 7.0.0-preview.3.22175.1<\/code><\/pre>\n<p>If you already have the tool installed, you can upgrade it with the following command:<\/p>\n<pre><code class=\"language-bash\">dotnet tool update --global dotnet-ef --version 7.0.0-preview.3.22175.1<\/code><\/pre>\n<p>It&#8217;s possible to use this new version of the EF7 CLI with projects that use older versions of the EF Core runtime.<\/p>\n<h2>Daily builds<\/h2>\n<p>EF7 previews are aligned with .NET 7 previews. These previews tend to lag behind the latest work on EF7. Consider using the <a href=\"https:\/\/github.com\/aspnet\/AspNetCore\/blob\/master\/docs\/DailyBuilds.md\">daily builds<\/a> instead to get the most up-to-date EF7 features and bug fixes.<\/p>\n<p>As with the previews, the daily builds require .NET 6.<\/p>\n<h2>The .NET Data Community Standup<\/h2>\n<p>The .NET data 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 data-related topic of your choice, including the latest preview release. <\/p>\n<ul>\n<li><a href=\"https:\/\/aka.ms\/efstandups\">Watch our YouTube playlist<\/a> of previous shows<\/li>\n<li><a href=\"https:\/\/dotnet.microsoft.com\/platform\/community\/standup\">Visit the .NET Community Standup<\/a> page to preview upcoming shows<\/li>\n<li><a href=\"https:\/\/github.com\/dotnet\/efcore\/issues\/22700\">Submit your ideas<\/a> for a guest, product, demo, or other content to cover<\/li>\n<\/ul>\n<h2>Documentation and Feedback<\/h2>\n<p>The starting point for all EF Core documentation is <a href=\"https:\/\/docs.microsoft.com\/ef\/\">docs.microsoft.com\/ef\/<\/a>.<\/p>\n<p>Please file issues found and any other feedback on the <a href=\"https:\/\/github.com\/dotnet\/efcore\">dotnet\/efcore GitHub repo<\/a>.<\/p>\n<h2>Helpful Links<\/h2>\n<p>The following links are provided for easy reference and access.<\/p>\n<p>EF Core Community Standup Playlist:\n<a href=\"https:\/\/aka.ms\/efstandups\" target=\"_blank\" rel=\"noopener\">https:\/\/aka.ms\/efstandups<\/a><\/p>\n<p>Main documentation:\n<a href=\"https:\/\/aka.ms\/efdocs\" target=\"_blank\" rel=\"noopener\">https:\/\/aka.ms\/efdocs<\/a><\/p>\n<p>Issues and feature requests for EF Core:\n<a href=\"https:\/\/aka.ms\/efcorefeedback\" target=\"_blank\" rel=\"noopener\">https:\/\/aka.ms\/efcorefeedback<\/a><\/p>\n<p>Entity Framework Roadmap:\n<a href=\"https:\/\/aka.ms\/efroadmap\" target=\"_blank\" rel=\"noopener\">https:\/\/aka.ms\/efroadmap<\/a><\/p>\n<p>Bi-weekly updates:\n<a href=\"https:\/\/github.com\/dotnet\/efcore\/issues\/27185\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/dotnet\/efcore\/issues\/27185<\/a><\/p>\n<h2>Thank you from the team<\/h2>\n<p>A big thank you from the EF team to everyone who has used and contributed to EF over the years!<\/p>\n<p>Welcome to EF7.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Announcing the release of EF7 Preview 3 and custom database-first scaffolding with T4 templates.<\/p>\n","protected":false},"author":368,"featured_media":39428,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,859],"tags":[7250,7629,70],"class_list":["post-39427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-entity-framework","tag-ef-core","tag-ef-core-7","tag-entity-framework"],"acf":[],"blog_post_summary":"<p>Announcing the release of EF7 Preview 3 and custom database-first scaffolding with T4 templates.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/39427","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=39427"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/39427\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/39428"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=39427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=39427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=39427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}