BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Entity Framework 7 Brings Bulk Operations and JSON Columns

Entity Framework 7 Brings Bulk Operations and JSON Columns

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

Rate this Article

Adoption
Style

BT