Captivix

Introduction to Entity Framework Core 1.0 (Initially Entity Framework 7)

What is Entity Framework (EF)?

Entity Framework (EF) is an object-relational mapping (ORM) framework and a set of technologies for developing applications that interact with data. A.NET developer spends a lot of time keeping up with database changes. Entity Framework provides a mapping from the relational database schema to the objects and offers an abstraction. In the Entity Framework, you can define entity classes that are independent of a database structure and then map them to the tables and associations of the database. Since we are now working with entities that have their own schema, we are shielded from changes in the database. The object context keeps tabs on the entities that are changed. Entity Framework provides a shift from database-oriented (DataReader, DataSet) to model-oriented development. So instead of focusing on a database, a developer focuses on the entity that represents the business model of the application.

History of Entity Framework Version

Announced in TechEd 2006, the first version of Entity Framework 3.5 was released two years later, in August 2008, along with Visual Studio 2008 SP1 and.NET 3.5 SP1. This release provided basic O/RM support using the Database First workflow. This version was met with exceptional controversy. Few infrastructure products have provoked a Vote of no confidence petition signed by almost a thousand developers, including a couple of dozen MVPs. The key criticism was aimed at the clumsiness of writing modern, clean code: the entity classes had to be populated with boilerplate code, lazy loading was a pain to implement, and the advertised disconnect between a data model and a business-driven entity model was relatively cumbersome to achieve.

An extra insult was added by the launch date:.NET 3.5 and Visual Studio 2008 shipped without Entity Framework, as Microsoft simply missed the deadline. After the November 2007 release, it took an additional year to push out Entity Framework with.NET 3.5 Service Pack 1. With this delay, many had already clung on to the “simplified EF” LINQ to SQL shipping with.NET 3.5 or competing ORM products. And to further mess things up, it was then announced that the development focus would be on EF. People read this as having the LINQ to SQL project terminated—perhaps a slightly dramatized conclusion, but not entirely baseless.

The second version of Entity Framework, named Entity Framework 4.0 (EFv4), was released as part of.NET 4.0 on April 12, 2010 and addressed many of the criticisms made of version 1. New features in this release included POCO support, lazy loading, testability improvements, customizable code generation, and the Model First workflow. Although it was the second release of Entity Framework, it was named EF 4 to align with the.NET Framework version that it shipped with.

A third version of Entity Framework, named Entity Framework 4.1, was released on April 12, 2011, with Code First support and a simplified DbContext API. This release was available on NuGet and adopted semantic versioning since it was no longer tied to the.NET Framework Version.

A refresh of version 4.1, named Entity Framework 4.1 Update 1, was released on July 25, 2011. It includes bug fixes and new supported types. In addition to bug fixes, this patch release introduced some components to make it easier for design-time tooling to work with a Code First model.

Entity Framework 4.2 was released on November 1, 2011. It includes bug fixes and adopts the https://semver.org standard for semantic versioning.

Entity Framework 4.3 was released on February 9, 2012. This release included the new Code First Migrations feature, which allows a database created by Code First to be incrementally changed as your Code First model evolves.

A patch of version 4.3, named Entity Framework 4.3.1, was released on February 29, 2012. This patch release included some bug fixes to the EF 4.3 release and introduced better LocalDb support for folks using EF 4.3 with Visual Studio 2012.

Entity Framework 5.0.0 was released on August 11, 2012, and is targeted at.NET Framework 4.5. Also, this version is available for.Net Framework 4, but without any runtime advantages over version 4. This release can be used in Visual Studio 2010 and Visual Studio 2012 to write applications that target.NET 4.0 and.NET 4.5. When targeting.NET 4.5, this release introduces some new features, including enum support, table-valued functions, spatial data types, and various performance improvements. The Entity Framework Designer in Visual Studio 2012 also introduces support for multiple diagrams per model, coloring of shapes on the design surface, and batch import of stored procedures.

Entity Framework 6.0 was released on October 17, 2013 and is now an open source project licensed under Apache License v2. This version has a number of improvements for code-first support. This release can be used in Visual Studio 2013, Visual Studio 2012, and Visual Studio 2010 (runtime only) to write applications that target.NET 4.0 and.NET 4.5. This release included asynchronous query support, testability improvements, logging enhancements, stored procedure support in Code First, code-based configuration, and general performance improvements.

The Entity Framework 6.0.1 patch release is limited to fixing issues that were introduced in the EF6 release (regressions in performance/behavior since EF5). This is a runtime-only release; there was no update to the tooling. The most notable changes were to fix some performance issues during warm-up for EF models. This was important as warm-up performance was an area of focus in EF6, and these issues were negating some of the performance gains made in EF6.

The Entity Framework 6.0.2 patch release is limited to fixing issues that were introduced in the EF6 release (regressions in performance/behavior since EF5). This patch includes fixes to some performance and functional issues that were introduced in the 6.0.0 and 6.0.1 releases.

Entity Framework 6.1.0 is a minor update to Entity Framework 6. It includes various new features and a few bug fixes. This release included tooling consolidation, handling transaction commit failures, indexing, a public mapping API, interceptor configuration, and improved performance.

Entity Framework 6.1.1, Entity Framework 6.1.2, and Entity Framework 6.1.3 are bug fix releases only.

Entity Framework Core 1.0 (aka EF Core 1.0), initially available as Entity Framework Version 7 (EF7), is currently being built as part of Microsoft’s efforts to modernize, componentize, and bring.NET cross-platform to Linux, OSX, and elsewhere. The vision for EF Core is “a core framework that handles concepts common to most data stores with provider-specific extensions that become available when you target a specific provider.”. EF Core is much lighter than previous versions and is built from the ground up to work great in the cloud (using ASP.NET vNext) on devices (i.e., in universal Windows apps) as well as in traditional.NET scenarios.

Important Features of Entity Framework Core

  1. EF Core is a major evolution of EF. Moving from EF6 to EF Core is not an “upgrade” scenario; it’s a “port” scenario.
  2. EF Core runs everywhere. EF Core supports the default provider(s) for each platform (i.e., SQL Server for Windows, SQLite for devices, and Postgres/MySQL for Mac/Linux).
  3. EF Core supports new data stores (relational and non-relational) EF is the most popular ORM that currently includes applications built with technologies such as WPF, WinForms, and ASP.NET. After looking at the future, Microsoft has decided to support the remaining platforms where.NET development is common. This includes the Windows Store, Windows Phone, and the cloud-optimized.NET. The entity framework was clearly tied to relational data stores. From now on, EF provides great support for non-relational data stores as well. Relational & non-relational, like Azure table storage.
  4. EF Core is lightweight and composable. EF Core will be built with memory and CPU usage in mind. Instead of using existing Entity Framework 6 APIs, the team decided to start developing from scratch. You can use only those extensions that are useful to your project. The pattern and concept remain the same for the Entity Framework. You can use DbContext and DbSet the same way as you are currently using them. The advantage of being extensible is that you can replace and extend it.
  5. Enhanced support for unit testing: EF Core supports in-memory providers for unit testing. The code snippet given below shows a sample unit test.

Constraints

  1. EF Core supports SQL Server 2008 onwards. Things need to work well by default in 2012. It’s ok to have to change settings, etc. to work in 2008.
  2. EF Core works well by default on SQL Azure.
  3. EF Core supports.NET 4.5.1 onwards
  4. EF Core doesn’t have to support older versions of each platform (i.e., Win10 UWP support is more important than Win81, Mono 4 over Mono 3.x, etc.).

Share this Blog