4

Entity Framework 7 Brings Bulk Operations and JSON Columns

 1 year ago
source link: https://www.infoq.com/news/2022/12/ef7-core-json/?utm_campaign=infoq_content&utm_term=global
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Entity Framework 7 Brings Bulk Operations and JSON Columns

Dec 30, 2022 2 min read

Version 7 of Entity Framework (EF) Core, Microsoft's object-to-database mapper library for .NET Framework, was released in November, together with the wider .NET 7 release. The updated version brings performance updates when saving data, allows JSON column operations, enables efficient bulk operations, and contains many minor fixes and improvements. The EF7 Core is available for both .NET 7 and .NET 6.

Microsoft released EF7 on November 8th, distributed as a set of NuGet packages. According to the breaking changes documentation, the most important change in EF Core 7 is treating SQL Server connections as encrypted by default. The developers will have to configure a valid certificate on their machines or explicitly relax the security restriction. If not, the connection strings that were valid in EF6 will throw an exception in EF7.

One of the already-known advances in EF7 Core are performance improvements when saving changes to the database with the SaveAsync method. In some scenarios it can be over 50% when compared to EF6 Core on the same machine.

EF7 Core adds support for extending text columns containing JSON documents in the database into query objects. The developers can filter and sort on the JSON properties inside the documents as part of the query to the database. EF7 contains a generic support of JSON columns and a concrete implementation of a provider for SQL Server.

The bulk operations on the database, such as bulk updates or deletes, have also been reworked in EF7. A standard SaveChangesAsync method execution can affect multiple records, but the results of the SQL execution are loaded in memory as a result. EF7 now has two new methods, ExecuteUpdateAsync and ExecuteDeleteAsync, which will perform bulk operations on the server immediately and won’t load any entities back into memory.

By default, EF Core maps an inheritance hierarchy of .NET types to a single database table, in a strategy called Table-per-Hierarchy (TPH). EF Core 5 added Table-per-Type (TPT) strategy, where each type in the hierarchy gets a database table. EF Core 7 now adds the Table-per-Concrete-Type (TPC) strategy, where each non-abstract type gets a database table while the abstract type columns are added to the tables of the concrete implementations of the abstract type.

There are other improvements in EF7 such as support for custom T4 templates in database-first reverse engineering, support for overriding and changing default model conventions, improved interceptors and events, and mapping of inserts, updates and deletes to stored procedures.

While historically .NET developers have perceived the Entity Framework as bulky and full of shortcomings, the new versions are now recognized as highly-efficient, fault-tolerant ORM.

With the EF7 release, there is already a roadmap for EF8 with more JSON columns enhancements, .NET value objects support and the ability to return unmapped types as query results.

About the Author

Edin Kapić

Edin Kapic is a Lead Software Engineer working in Vista, based in Barcelona (Spain).

Edin started messing with .NET and SharePoint in 2005 and still tinkers with it. He was SharePoint MVP untin 2022. Together with two other like-minded SharePoint addicts he founded and currently acts as a president of the SharePoint User Group Catalonia (SUG.CAT). He writes and speaks about technology in numerous publications and events, in Spain and abroad.

When he has some free time, between technical stuff, he enjoys flight simulation, sailing, reading and hiking.

Show more

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK