Entity framework, as discussed in our last blog, is one of the most powerful ORM (Object Relation Mapper) frameworks. It is generally used as a Data Access layer in the application. Initially, Entity framework came with fewer features and limited functionality. There were continuous changes made in the Entity framework as a result, entity framework has become more powerful and comes with lots of new features in every release.
In this blog, I will be discussing new features available in Entity Framework 7 in details.
But before getting into details, I would like to mention a few items, which are no longer supported in Entity Framework 7.
EDMX (Entity Model Data XML) is no longer supported in Entity framework 7. This means that Entity framework 7 only support code first approach. EDMX file stores everything in one file and it may view in Entity framework designer and contains tightly coupled mappings configurations and contexts.
Entity SQL is a preferable way to execute LINQ to Entity. Now, ESQL is no longer supported by Entity framework 7.
Generating database schema from entity model is called migration. There are many techniques available for performing migration likes explicitly adding migrations through code by using PM (package manager) console. There are alternative methods are available called Automatic Migration. This Automatic migration is supported by Entity framework 7.
ObjectContext API support
DbContext class was introduced in Entity framework 4.1. Up to entity framework 4, ObjectContext Class is used to manage all the database operations and manages various entities of the Entity Model. DbContext is conceptually similar to ObjectContext. DbContext is nothing but an ObjectContext wrapper, we can say it is a lightweight alternative to the ObjectContext. Up to entity framework 6.x, ObjectContext API is continuing for the backward compatibility purpose. This API has been removing in a new version.
Apart from these, other two features Metadata Workspace API and MEST (Multiple Entities for Single Type) Mapping are also discontinued in the new version.
EF 7 is now Open source
Like EF 6, EF 7 is also open source. EF 6 codes available on CodePlex but EF 7 is on GitHub along with the upcoming version of ASP.NET.Now we can explore the source code, participate in discussions, raise issues and submit pull requests to the examine team.
Lightweight and extensible
Entity Framework 7 is now very lightweight. It contains only very common features. The components of EF are easy to replace and extended EF 6.1.3 is about 10 MB and it includes 5MB of entity framework DLL for .NET 4.5. EF 7 comes in much smaller sizes DLLs as compare to EF 6. We will combine the DLLs necessary to support our workflow.
Support new Platforms
Entity Framework 7 now supports the following types of application:
• All .NET application (Console, ASP.NET 4, WinForms, WPF)
• Mac and Linux applications (Mono)
• UWP (Universal Windows Platform)
• ASP.NET 5 applications
• Can use EF 7 in Windows phone and Windows store app
New Data Stores
Up to the Entity Framework 6, it is clearly tied to relational data stores. Now Entity framework also supports many non-relational data stores. The support includes change tracking, LINQ, and unit of work. Also, EF 7 will be enabling providers that can be used to support non-relational data stores.
Supported providers in Entity Framework 7
• SQL Server
• Azure Table Storage
• In Memory (for unit testing)
• SQL Server Compact
• IBM Data Servers
NoSQL database is very popular because of the performance of CRUD operations is much faster than other relational databases. NoSQL database is a good choice when we have a large amount of data process. Entity Framework 7 now provides support to non-relational databases so we can use NoSQL database with EF.
Support for unit testing
Unit test is helping us to test blocks of code. Now, Unit test is much simpler with Entity Framework 7. Entity framework 7 now supports in-memory tables.
Entity Framework 7 has built-in logging feature. To use this logger feature, we need to implement ILoggerProvider interface. Hopefully, it is supported on all platforms. This logging feature is also present in EF 6.x.
Support Cascade Delete
Cascade delete allows us to automatic delete child records when parent data is deleted. In other words, all related data will be deleted when parent data is deleted. Entity framework 7 support cascade delete.
Shadow Properties are properties which are not present in our entity model class. They can participate in queries, we can also perform create/ update operation. The values can be changed and maintained by the Change Tracker API.
To sum up, Entity framework 7 comes with many powerful features. There are various performance related changes incorporated in EF 7. Microsoft will continue to support EF 6.x and also provide a new release of EF 6.x for bug fixes and small improvements.