Announcing Entity Framework Core 7 (EF7) Preview 3

Jeremy Likness

Today, the .NET data team announces the third preview release of EF Core 7.0 (EF7). In 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. Be sure to read the full plan for EF7 to learn what’s on the roadmap.

You can also view the full list of issues addressed in EF7 Preview 3.

Improvements to the update pipeline

Several improvements to the update pipeline are now part of Preview 3, including:

Take control of your DbContext

Preview 3 introduces the ability to control how EF7 reverse engineers or scaffolds classes for database-first projects using T4 templates. Do you prefer “null bang” setters? Property initializers? Constructor initialization? All these customizations are now possible. In fact, you are not limited to generating the “traditional” DbContext and entity classes. Anything is possible, including using the templates to generate documentation.

The best way to learn about this new feature is to watch our recent community standup: Database-first with T4 templates in EF7. The video begins 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.

Code like this:


```mermaid
erDiagram
    ORDERMASTER ||--o{ ORDERDETAIL : owns
    ORDERDETAIL ||--|{ LINE-ITEM : contains
    ORDERMASTER }|..|{ CUSTOMER : uses
```

Produces diagrams like this:

An ERD diagram
Mermaid ERD Diagram

You can get started in 3 steps:

  • Include the Preview 3 Microsoft.EntityFrameworkCore.Design package in your project (this will also work with the daily builds).
  • Install or update the dotnet-ef tool either globally or locally using a tool manifest.
  • Create the DbContext.t4 and EntityType.t4 T4 templates in a folder named CodeTemplates. EF7 will pick these up by convention.

For more details, watch the community standup demo.

Prerequisites

  • EF7 currently targets .NET 6. This will likely be updated to .NET 7 as we near the release.
  • EF7 will not run on .NET Framework.

EF7 is the successor to EF Core 6.0, not to be confused with EF6. If you are considering upgrading from EF6, please read our guide to port from EF6 to EF Core.


How to get EF7 previews

EF7 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 7.0.0-preview.3.22175.1

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

Package Purpose
Microsoft.EntityFrameworkCore The main EF Core package that is independent of specific database providers
Microsoft.EntityFrameworkCore.SqlServer Database provider for Microsoft SQL Server and SQL Azure
Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite SQL Server support for spatial types
Microsoft.EntityFrameworkCore.Sqlite Database provider for SQLite that includes the native binary for the database engine
Microsoft.EntityFrameworkCore.Sqlite.Core Database provider for SQLite without a packaged native binary
Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite SQLite support for spatial types
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; use this to integrate tools like scaffolding and migrations with Visual Studio
Microsoft.EntityFrameworkCore.Design Shared design-time components for EF Core tools
Microsoft.EntityFrameworkCore.Proxies Lazy-loading and change-tracking proxies
Microsoft.EntityFrameworkCore.Abstractions Decoupled EF Core abstractions; use this for features like extended data annotations defined by EF Core
Microsoft.EntityFrameworkCore.Relational Shared EF Core components for relational database providers
Microsoft.EntityFrameworkCore.Analyzers C# analyzers for EF Core

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

Installing the EF7 Command Line Interface (CLI)

Before you can execute EF7 Core migration or scaffolding commands, you’ll have to install the CLI package as either a global or local tool.

To install the preview tool globally, install with:

dotnet tool install --global dotnet-ef --version 7.0.0-preview.3.22175.1

If you already have the tool installed, you can upgrade it with the following command:

dotnet tool update --global dotnet-ef --version 7.0.0-preview.3.22175.1

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

Daily builds

EF7 previews are aligned with .NET 7 previews. These previews tend to lag behind the latest work on EF7. Consider using the daily builds instead to get the most up-to-date EF7 features and bug fixes.

As with the previews, the daily builds require .NET 6.

The .NET Data Community Standup

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.

Documentation and Feedback

The starting point for all EF Core documentation is docs.microsoft.com/ef/.

Please file issues found and any other feedback on the dotnet/efcore GitHub repo.

The following links are provided for easy reference and access.

EF Core Community Standup Playlist: https://aka.ms/efstandups

Main documentation: https://aka.ms/efdocs

Issues and feature requests for EF Core: https://aka.ms/efcorefeedback

Entity Framework Roadmap: https://aka.ms/efroadmap

Bi-weekly updates: https://github.com/dotnet/efcore/issues/27185

Thank you from the team

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

Welcome to EF7.

13 comments

Leave a comment

      • Brice Lambson

        Reverse engineering a model from an existing database is a design-time gesture similar to adding a new views or controllers in MVC. You then customize the scaffolded code to better fit the needs of your application.

        Code generators are used to avoid writing boiler plate code; they use your current project code as an input and augment it.

        Using code generators here would mean connecting to the database and reading it’s entire schema every time you compiled your project. This would be incredibly slow. It would also mean you wouldn’t have a chance to further customize the generated code.

        The idea behind these templates is to give you a better starting place when reverse engineering a model. For example, if you do a lot of client apps with data binding, you probably want all your entity types to implement INotifyPropertyChanged. Or maybe you prefer not to expose surrogate key or foreign key properties, this would save you the time of having to rework them every time you scaffold a new model.

        Simply put, code generators fill a very different need than templates.

  • MgSam

    Nice to see you guys go back to T4 rather than inferior templating technologies. They are very easy to write, read, and update. Hopefully the fact you’re using them again makes the Visual Studio team reconsider the “not deprecated but we’ll be darned if we do any further development on them” attitude around T4 that’s existed for the last decade. I’d love to see T4 fully open sourced and made more independent from Visual Studio.

    • Mike-E

      Curious if you consider code generators among those inferior technologies? I myself hate code generators as they are performance/productivity killers for larger solutions ATM but I feel they are ultimately the right direction (if they can fix the performance issues).

      • Brice Lambson

        Note that T4 and code generators can work very nicely together. T4 is just a fancy way of writing a StringBuilder. It shifts the focus of the output text to be front and center while the mechanics of building the string and the generation logic shift more to the background. A code generator could could simply call into a runtime (aka preprocessed) template to generate its code.

  • Alexey Leonovich

    EF7 currently targets .NET 6. This will likely be updated to .NET 7 as we near the release.
    It’s worth thinking twice before doing this. It seems to be a very controversial decision since .NET 7 is not LTS (.NET 6 will reach EOL later).

    • Michael Taylor

      That depends really. I suspect the EF team (like other MS teams) is following the same LTS/Current format as NET. So EF 7 will be a Current release, not LTS. Hence if you need LTS (and who doesn’t ) then you are stuck with EF 6/NET 6. Of course ideally EF 7 would be multi-targeted like MS is recommending library devs do so you can use either .NET 6 or 7. If they don’t then we’ll be missing out on perf/bug fixes.

      At this point it is hard to tell because we haven’t had a LTS to Current transition. When we transitioned from Current to LTS (5 -> 6) then EF 6 only supported 6 because it was also LTS. It will be telling how the team decides to handle this. If they drop LTS support then I would expect the migration to EF 7 to be slower because I believe most people want LTS. That also mostly makes the multi-targeting a mute point.

  • Jeffrey4 Home

    Could you guys put the community standup demo source code on github or somewhere. Following the 3 steps to make t4 with DbContext does not work, it does not use those T4s.

    • Brice Lambson

      Looks like the last step is wrong. It’s missing the EFCore directory in between. For example: CodeTemplates/EFCore/DbContext.t4