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

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events