BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Entity Framework Core 2.1 Release Adds Improved SQL Query Generation

Entity Framework Core 2.1 Release Adds Improved SQL Query Generation

This item in japanese

Bookmarks

Microsoft has released Entity Framework Core 2.1, bringing with it many features existing EF developers have long waited for.  EF Core 2.1 adds support for SQL GROUP BY, support for Lazy Loading, and data seeding, among others.

The first big addition to EF Core 2.1 is that the use of GroupBy LINQ operator will now be translated into proper SQL using the GROUP BY clause.  The lack of this support was considered a big omission in EF Core 2.0.  Similarly, support for Lazy Loading has made it into EF Core 2.1.  To support the addition of Lazy Loading, entities that take parameters in their constructors can now be created.  Once defined, EF Core can call this constructor when creating an instance of the entity.

EF Core now supports the ability to programmatically populate a database with initial data. In a departure from EF6, "seeding data is associated with an entity type as part of the model configuration".  But there are some open items from EF Core 2.0 that remain out of 2.1.  For example, Table Per Type remains an open issue on the GitHub project page.

The packaging of EF has been simplified in this release, with the command line tools now part of the .NET Core SDK.  They can be accessed through dotnet ef and the previous reference to them (DotNetCliToolReference) in a project is not required.  However, these commands only support EF Core 2.0/2.1, so care must be taken if it is necessary to support EF Core 1.0/1.1.

EF Core 2.1 is available now through the installation of the .NET Core 2.1 SDK.  Since EF Core 2.1 conforms to .NET Standard 2.0, it will run on both .NET Core 2.0 and .NET Framework 4.6.1 or later.

If you are upgrading from a previous build, it is important to note that the packages providing support for your database provider should be upgraded.  Attempting to use a database provider designed for EF Core 2.0 will cause problems in EF Core 2.1, and not all of them will be immediately noticeable so to save frustration it is best to update.  Microsoft suggests directly updating via dotnet add package to ensure the proper version is loaded.

Rate this Article

Adoption
Style

BT