News

What's New in Entity Framework Core 5.0 Preview 7

Microsoft shipped the seventh preview of Entity Framework Core 5.0, boosting its data access technology with a factory to create DbContext instances and more.

A DbContext instance represents a session with the database and can be used to query and save instances of entities, Microsoft says.

The new EF Core 5.0 Preview 7 discusses AddDbContextFactory and AddPooledDbContextFactory, introduced in EF Core 5.0 to register a factory for creating DbContext instances in an application's dependency injection container. The factory helps developers create and use instances as needed.

"Note that the DbContext instances created in this way are not managed by the application's service provider and therefore must be disposed by the application," said Jeremy Likness, senior program manager for .NET Data and .NET, in a July 21 blog post. "This decoupling is very useful for Blazor applications, where using IDbContextFactory is recommended, but may also be useful in other scenarios."

Other highlights of Preview 7 listed by Likness include:

  • Reset DbContext state: This provides the option to reset the state of a DbContext instance, something that normally isn't required if developers follow the best practice of creating new, short-lived context instances for each unit-of-work.
  • New pattern for store-generated defaults: This addresses problems in certain circumstances when explicit values are set for columns that may also have default value constraints. In these scenarios, EF Core 5.0 now allows the backing field to be nullable.
  • Savepoints: These provide greater control over transactions that execute multiple operations, giving developers the ability to manually create them, release them and roll them back.
  • Cosmos partition keys: Cosmos partition keys are included in EF models, and in Preview 7 the partition key is included in the entity type's PK and is used to improved performance in some queries.
  • Cosmos configuration: EF Core 5.0 improves configuration of Cosmos and Cosmos connections, improving on the previous scheme of EF Core requiring the end-point and key to be specified explicitly when connecting to a Cosmos database. "EF Core 5.0 allows use of a connection string instead," Likness said. "In addition, EF Core 5.0 allows the WebProxy instance to be explicitly set."
  • Scaffold-DbContext now singularizes: "Previously when scaffolding a DbContext from an existing database, EF Core will create entity type names that match the table names in the database. For example, tables People and Addresses resulted in entity types named People and Addresses.

    "In previous releases, this behavior was configurable through registration of a pluralization service. Now in EF Core 5.0, the Humanizer package is used as a default pluralization service. This means tables People and Addresses will now be reverse engineered to entity types named Person and Address."

All of the above and more is presented in greater detail in the "what's new" notes, which also include information on previous previews.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • Creating a Progressive Web App with Blazor WebAssembly

    Not surprisingly, it's dead easy to create an app in Blazor that runs outside of the browser window and (potentially) in an offline mode. Before you get carried away, though, there are some key design decisions to make.

  • GitLab Takes Over VS Code Extension, Plans Improvements

    DevOps specialist GitLab has officially taken over the control of a GitLab extension for Microsoft's open source, cross-platform Visual Studio Code editor.

  • VS Code Python Tool Now Does Native Notebooks

    The Python Extension for VS Code Insiders team is previewing the newest implementation of notebooks, used frequently in data science with offerings such as Jupyter Notebooks.

  • As .NET 5 Nears, Content/Documentation Reorganization Starts

    A GitHub project is seeking to reorganize documentation and developer content in advance of the November debut of .NET 5, a unification of all things .NET that combines. .NET Core and other components.

  • Windows Devs Get Cross-Platform Page, Issues Repo

    Developers doing their coding on the Windows OS have received two new resource gifts from Microsoft: a new landing page for those using cross-platform technologies and a new GitHub repo with which to report issues to Windows engineering teams.Developers doing their coding on the Windows OS have received two new resource gifts from Microsoft: a new landing page for those using cross-platform technologies and a new GitHub repo with which to report issues to Windows engineering teams.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events