News

What's New in EF Core

How can a developer possibly learn about the new features in EF Core in just 20 minutes when the list includes Table Splitting, Owned Types, Query Filters, DbContext pooling, GroupBy, String Interpolation, Lazy loading, Value Converters, Data Seeding, Query types, Optimized correlated subqueries, Spatial support, Query Tags and more?

Well, you attend a "Fast Focus" session led by an EF Core expert who makes it his business to spread the data-driven word to developers across the country and share his expertise in condensed presentations that get right to the facts.

Jim Wooley, a Senior Delivery Principal at Slalom Consulting, will do just that next month at the big Live! 360 multi-event IT/developer conference in Orlando.

Titled "Fast Focus: What's New in EF Core," the 20-minute session will explore the additions to EF Core 2 and beyond and how they can impact your application decisions.

[Click on image for larger view.] EF8 on NuGet (source: Microsoft).

That's a lot to discuss in a short time, as Entity Framework Core, Microsoft's Object Relational Mapping (ORM) data access tool, was re-written from the ground up with .NET Core, with the dev team changing and rethinking a number of features. "This redesign caused it to continue playing catch-up to features added in 10 years of development leading up to EF6, while also exploring new programming options that have popularized since the original design came out, including non-relational data stores," said Wooley, a frequent speaker, MVP and co-author of "LINQ in Action."

We caught up with Wooley to learn more about his session next month in the Visual Studio Live! segment of the multi-event conference.

VisualStudioMagazine: What inspired you to present a session on what's new in EF Core?
Wooley: Ever since I first saw the elegant simplicity of LINQ back in 2005, I've been spending time helping others understand the benefits that it can bring on the surrounding topics, including LINQ to Objects, LINQ to SQL, LINQ to XML, Entity Framework, Reactive Extensions. EF Core (with .NET 8, just referred to as EF8) is a natural extension.

"I first started talking about migrating, but spend more time now trying to stay on top of the changes that happen for each version and the performance benefits that they bring."

Jim Wooley, Senior Delivery Principal, Slalom Consulting

I first started talking about migrating, but spend more time now trying to stay on top of the changes that happen for each version and the performance benefits that they bring.

From a personal perspective, I often recommend if I want to really understand a topic, not only should I use the thing, but try to describe it to others. This forces me to know it deeper than I would have for just using it. It also gives me a deadline on when I need to know it by. Without the concrete date, that thing on the todo list can often keep get pushed back and never get "to-Done." I do talks on what's new in EF, C# and so on in part to keep me on my toes and force me to learn so that others can benefit.

Inside the Session

What: What's New in EF Core

When: Nov. 14, 1:30 p.m. - 1:50 p.m.

Who: Jim Wooley, Senior Delivery Principal, Slalom Consulting

Why: Whirlwind "Fast Focus" tour will include topics such as Table Splitting, Owned Types, Query Filters, DbContext pooling, GroupBy, String Interpolation, Lazy loading, Value Converters, Data Seeding, Query types, Optimized correlated subqueries, Spatial support, and Query Tags.

Find out more about Visual Studio Live!, taking place Nov. 12-17 in Orlando

The laundry list of topics you'll be covering in your presentation, from primitive collections to HierarchyId support, is impressive. Could you highlight a couple of these topics that you believe will have the most immediate impact on developers' day-to-day work?
EF Core 7 introduced support for JSON columns in SQL Server. EF8 extends this support by adding a number of capabilities. For teams using SQLite, JSON column support was added to that provider. Additionally, EF8 brings the ability to use a JSON column to represent primitive collections (string arrays) rather than needing to join tables for simple lists. This should simplify data querying and increase performance by reducing the traditionally needed joins.

EF8 also extends JSON support to enable the ability to pass arrays into a query. For example, in the past to perform an "In" clause in SQL, developers would set up an array and use the "Where(x => array.Contains(x => x.Value))" syntax. This translated into multiple parameters and a computed "where value in (@p1, @p2, .. @pn)" clause in SQL. The multiple parameter strategy is problematic when there are lots of values in the input array, and disallows support for pre-compilation of the query expression. EF8 changes the paradigm for the same LINQ query to use a JSON parameter and a join rather than IN clauses for your query once you upgrade your project to use EF8. While you can benefit from this by just upgrading your Entity Framework references, this is potentially a breaking change if you are using an older version of SQL Server (or compatibility level). Thus even if you don't change your implementation code, you may find that your queries may perform faster because of the new feature. But, your application may throw exceptions now on the same code depending on your server. I have long recommended having a full suite of integration tests when planning for a version upgrade.

With the advancements in EF Core, there might be concerns about the learning curve for developers transitioning from previous versions or other data access tools. How does EF Core address these concerns, and do you have any recommendations for developers looking to smoothly migrate their projects to harness the benefits of EF Core?
It largely depends on what model they are coming from and what edge case customizations they have made. If they are upgrading between versions of Core, typically the change is minimal. Effort may only be necessary if you want to take advantage of some of the new features introduced with that version. Reviewing the change long and breaking change lists on Microsoft's Entity Framework Core learning site is often a good first start when upgrading between Core versions.

If they are coming from EF6 (for .NET Framework) and used code-first models, the transition should be pretty smooth. While there may be some differences between some syntaxes, lots of resources exist online to help guide developers on the necessary changes. You can start with the guides at Port from EF6 to EF Core. EF6 with the EDMX database-first strategy requires more effort to move to code-only mappings since the graphical EDMX tools and XML structure have been abandoned. Use of the scaffolding tooling reduces the learning curve by investigating the code generated by the scaffolding tooling and making additional customizations as necessary for your domain.

If you're coming from a system that used DataSets and other low-level ADO tools, the learning curve may increase and require re-conceptualizing your data access strategies to take advantage of the flexile options that the LINQ abstraction brings. In particular, if your organization requires use of stored procedures rather than direct table access, you may find that you can't take full advantage of the power of EF and LINQ, but EF does support the ability to call stored procedures and not need to worry about manually managing opening and closing connections or manual mapping to and from your entity models. With EF8, this support extends to immutable types (C# 9 records) and unmapped types.

As developers, we're always concerned about the performance and efficiency of the tools we use. Could you delve into some of the performance-oriented enhancements in EF Core and explain how these features help developers build more responsive and scalable applications, especially when dealing with complex data scenarios?
Performance improvements have been a key component of every version of EF Core. Even with the initial version of EF Core 1, I've seen performance comparisons for simple queries to have given a 4x performance improvement over EF6. I've also seen the built-in support for batch operations increase the performance by as much as 98 percent. Each version of Core has brought additional optimizations in terms of the generated SQL and queryable evaluation and serialization. As a result, performance differences between EF, Dapper and raw ADO are largely negligible. This is due in part to the open source nature of EF and the ability to take optimizations from other tools (like Dapper). In many cases, developers can take advantage of the improvements without altering their code.

For developers who are open to updating their code to increase performance further, each version of EF Core has also added some features to target increased performance. For example, the Context Pooling features of Core 2, Compiled Queries, EF7's Batch Update, and EF8's JSON features all help support the performance improvement targets. In addition, the team is working on ways to achieve further performance improvements offered by Ahead-of-Time (AOT) compilation strategies in upcoming versions.

Given that EF Core has been re-written from scratch and had to catch up with features that EF6 gained over a decade, how would you compare the two in their current states? Do any notable drawbacks still exist in EF Core that developers should be aware of?

For many applications that I've worked with for customers, most of the features will just work. That's not to say that there is complete parity. A full feature comparison chart is available at Compare EF Core & EF6. Some of the notable differences include: No support for the graphical EDMX modeling or EntitySql. Earlier versions of Core had gaps. For example, support for Many-Many relationships without the join table in the models didn't come until Core 5. Developers trying to port applications from EF6 to Core found that they had to change their queries and models until support for that feature was added.

That being said, the number of additional features, providers and performance gains that Core/EF8 support that never made it into Entity Framework for .NET Framework more than compensate for the inconvenience that is imposed by migrating code to take advantage of these new features. If for no other reason, the performance improvements should be a strong argument for making the switch for many applications.

Note: Those wishing to attend the conference can save hundreds of dollars by registering early, according to the event's pricing page. "Save up to $300 if you register by Oct. 27," said the organizer of the event, which is presented by the parent company of Visual Studio Magazine.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube