![]() Here's the documentation for the UseHiLo method. I had completely forgotten about this feature, introduced in EF Core 3, to ask SQL Server to pre-generate a bunch of primary keys that EF Core caches and pushes into INSERT commands as needed. Not only do they also lose the explicit BEGIN and COMMIT for transactions, but they're also expressed in a more efficient way.Īnd if you've ever used EF Core's HiLo feature, parent/child inserts can really benefit from it. The improvements are not limited to when SaveChanges only sends a single change. VALUES the case of a single INSERT being sent where EF Core 7 won't wrap this in a transaction, the OUTPUT clause also removes the need for a transaction that was needed around the composed INSERT plus SELECT. In other words, instead of this multi-command message from EF Core 6: INSERT INTO ()ĮF Core 7 sends this: INSERT INTO () Now with EF Core 7, the SQL Server provider compresses all of those into a single command by using an OUTPUT in the INSERT command, rather than an extra command to SELECT. Although this doesn't require EF Core to make an additional call to the database, it does force the database to execute an additional command. These new keys were then applied to the related objects that EF was inserting. ![]() ![]() You may be aware of another pattern that's been around since the beginning of EF, and which continued through EF Core, and that's that INSERT commands have always been paired with a SELECT to return the database-generated value of any primary or foreign key. This is a great example of the types of tweaks made to the updates.Īnother tweak is related to inserts. Granted this was only a change from about 8 ms to 4 ms, but those do add up in a production application. And when comparing EF Core 6 to EF Core 7 where the database was on a remote server, Shay measured a 45% improvement on the SaveChanges call. Therefore, when SaveChanges involves only a single change, rather than sending the three commands (BEGIN TRANSACTION, the change command, and then COMMIT), EF Core 7 only sends the change command, cutting the chattiness down from three commands to one. If you only have one command being sent, the calls for the transaction aren't needed because there aren't other commands involved. As you may know, EF Core wraps every command sent in SaveChanges inside a database transaction so that if one fails, they'll all roll back. An interesting one is a drawback of EF Core's default transaction behavior. Some of Shay's discoveries were nuances that I hadn't paid attention to. However, if you do want to geek out on these changes, I highly recommend watching the standup video here on YouTube ( ). Each tuning may have only sped things up a small amount, but they do add up!Īlthough most of these tweaks are under the covers and you will benefit from them without having to take any action, I would like to highlight some of them for you. In an EF Core Community Standup earlier this year, Shay walked us through a fascinating look at the discoveries he'd made and the tunings he applied. Some of the inefficiencies he discovered hailed back to the early days of Entity Framework. Shay Rojansky, who has become “the performance guy” on the EF team, has explored the many nooks and crannies within SQL sent to the database and other related areas, discovering many points at which efficiencies could be applied. And true to their word, there was a lot of work done on updates that EF Core sends to the database. At that time, the team committed to focusing on improving the performance of other workflows in EF Core 7. Faster and Faster!īack in 2021, one of the biggest stories for EF Core 6 was the dramatic performance improvement for non-tracking queries. So, I may wait until EF Core 8 to use the new nickname. ![]() I still remember that first version of EF Core, just after EF6, which had a working name of EF7 until it became EF Core. You'll find this article filled with some of the features that will be most impactful to the bulk of dev teams as well as a few that I personally found interesting.Īlthough I will always refer to this version as EF Core 7, keep in mind that much of the documentation and other resources will use EF7 as its nickname. Not only does it mean writing about them, but I also get to test them all out, which is quite a lot of fun, thanks to the fact that I don't have to do so with the goal of releasing production code. ![]() I've been overwhelmed in trying to choose which of its features to share with you here. So you can continue using it on a supported version of. NET 6, which is the long-term support version of. Although EF Core 7 is being released alongside. That has a lot do with the fact that the team has made a big investment in creating a stable base to build on. Lately, it seems that each iteration of EF Core brings fabulous new features and improvements. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |