News

Entity Framework 7 Preview 7 Adds & Improves Interceptors

Entity Framework 7 Preview 7 is all about Interceptors, used for working with EF Core operations.

Interceptors enable interception, modification and/or suppression of EF Core operations, such as low-level database operations to execute a command and higher-level operations like calls to SaveChanges.

"Interceptors support async operations and the ability to modify or suppress operations, making them more powerful than traditional events, logging, and diagnostics," Microsoft said this week in announcing the preview. While Interceptor functionality is somewhat similar to that of events in terms of reacting to what EF Core is doing, they also let developers change the behavior of EF by suppressing or replacing actions that EF was going to perform, or by modifying or replacing action results. They can even perform async database access, such as changing complete database commands.

For this dev cycle, following general EF Core themes on the Themes of .NET site, the team introduced support for several new interceptors and improved existing interceptors.

EF Core Themes
[Click on image for larger view.] EF Core Themes (source: Microsoft).

Among the new Interceptor offerings is IMaterializationInterceptor, which can change or replace the entity instance before and after an entity instance is created, and before and after properties of that instance are initialized.

The post goes into detail about LINQ expression tree interception, optimistic concurrency interception and more, explaining how it can sometimes take an enormous amount of code to accomplish a simple task like making a change to a query.

"This brings us to a critical point about interceptors," Microsoft said. "Always ask yourself if there is an easier way of doing what you want. Interceptors are powerful, but it's easy to get things wrong. They are, as the saying goes, an easy way to shoot yourself in the foot."

Existing interceptors that were enhanced in this preview include:

EF7 also includes new traditional .NET events for:

While Interceptor discussion dominates the announcement post, other improvements include:

EF Core Voting
[Click on image for larger view.] EF Core Voting (source: Microsoft).

Going forward, Microsoft will continue work in preparation for a General Availability release expected in November. The dev team collects feedback from feature requests that are voted on by developers in the project's GitHub repo. Top feature requests are illustrated in the graphic above.

Microsof'ts "Plan for Entity Framework Core 7.0" indicates large investments in EF7 will fall mainly under the following themes:

  • Highly requested features
  • NET platforms and ecosystem
  • Clear path forward from EF6
  • Performance

This week Microsoft also shipped .NET 7 Preview 7 and Visual Studio 2022 17.3.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube