Presenting Entity Framework Core

EF Core was released in June 2016 after more than 2 years of dedicated effort and following numerous alpha, beta, and even a few release candidate versions. It was originally named Entity Framework 7, but later its name was changed to Entity Framework Core. So what exactly is Entity Framework Core? The official Microsoft documentation (https://docs.microsoft.com/en-us/ef/core/) describes Entity Framework Core as a lightweight and extensible version of Entity Framework. In other words, this is not simply an update from EF6; it's a brand new Entity Framework altogether. EF6 is still actively supported and will continue to have tweaks and fixes made to it, though for many reasons, all of the true innovation has gone into Entity Framework Core. Apart from new features that the team wanted to add to Entity Framework, there are also some critical and comprehensive themes for developing EF Core which align with ASP.NET Core and the underlying .NET Core. The idea behind developing EF Core is that it should be built from lightweight composable APIs; that is, it should be able to run on different operating systems that can host native implementations of the CoreCLR and, equally important, use modern software practices in the design, coding, and delivery of Entity Framework Core. Like EF6, EF Core is open source and available on GitHub. The source code of EF Core can be seen at https://github.com/aspnet/EntityFrameworkCore. The EF team has a road map for the features that they are prioritizing and the order in which they will be shipped in the upcoming releases. The road map for EF Core can be seen at https://github.com/aspnet/EntityFrameworkCore/wiki/roadmap.

EF Core runs on .NET Core, and .NET Core runs in a lot of places, such as Windows and Linux-based systems, as we have seen in earlier chapters. It runs inside the full .NET Framework, so any version that is 4.5.1 or newer. .NET Core itself can run on the CoreCLR; that's the runtime. CoreCLR can run natively, not only on Windows, but also on Macintosh and Linux. EF Core can also be used with the Universal Windows Platform (UWP) for Windows 10, so it runs on any device or PC that can run on Windows 10. So one may be tempted to think, should I use EF Core anywhere and everywhere, just because it is supported? The answer is no. This is a really important point to keep in mind. EF Core is a brand new set of APIs, and so it doesn't have all of the features that you might be used to with EF 6, and while some of those features will be coming in future versions of EF Core, there are a few that will never be part of EF Core, so it's important to understand this, and hence you may not want to start every single new project with EF Core. Before using EF Core, ensure that EF Core has all the features that you need. For a comprehensive list of features that are available in EF and EF Core and for a comparison, I would highly recommend that you visit the official Microsoft documentation describing the feature comparison between EF and EF Core in depth at https://docs.microsoft.com/en-us/ef/efcore-and-ef6/features.

For the sake of completeness, the subset of the feature comparison containing the important features are listed in the following table:

Name of feature

EF6

EF Core

Entity Data Model Extension (EDMX) designer support

Yes No

Entity Data Model Wizard (for database first approach)

Yes No

Automatic migration

Yes No

Lazy loading of data

Yes No

Stored procedure mapping with DbContext

Yes No

Batch Insert, Update, Delete operations

No Yes

In-memory provider for testing

No Yes

Support for Inversion of Control (IoC)

No Yes

Field mapping

No Yes

DbContext pooling

No Yes

If you are overwhelmed with this comparison and feel out of place with the listed features, do not worry. EF is indeed a huge topic to learn. However, we will learn to use it from scratch to have the basic fundamentals in place. To do so, we will learn to create a simple data access console application. Once we know how to use EF Core, we can then use it in our movie booking app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset