Entity Framework 7: Providing support for new platforms and new data stores

Leverage Entity Framework 7's support for non-relational data stores and in-memory data in your applications

Entity Framework 7

EF (Entity Framework) is Microsoft's flagship data access platform -- an extended ORM (Object Relational Mapper) that abstracts the calls to the ADO.Net data access provider underneath. It is an open source ORM framework for ADO.Net and is included as part of .Net Framework. The first version of Entity Framework (EFv1) was released as part of .Net Framework 3.5 Service Pack 1 and Visual Studio 2008 Service Pack 1 in the year 2008.

In using Entity Framework, you can work with relational data using domain-specific objects. Entity Framework has been the technology of choice for building data access layer while working with WPF, WinForms, MVC, WebAPI, WebForms and WCF applications. Here are a few design documents on Entity Framework 7.

The latest version of this ORM is Entity Framework 7. Microsoft's vision for Entity Framework 7 is "New Platforms, New Data Stores". This implies that Entity Framework 7 is an extensible and lightweight version of Entity Framework that enables provides support for new platforms and new data stores. Entity Framework 7 is a major redesign of Entity Framework and is the default data stack for ASP.Net 5 applications. Brice has a nice post on EF7 migrations.

I would like to highlight some of the striking features of EF7 in this post. To get started working with Entity Framework 7 you should add the Entity Franework 7 NuGet packages to your project.

Here's quick glance at what's new in Entity Framework 7:

  • Support for non-relational data stores and in-memory data
  • Support for Windows Phone and Windows Store applications
  • Support for Linux and Macintosh machines

Support for non-relational data stores and in-memory data

NoSQL databases are widely popular these days primarily because of performance -- CRUD operations on these database are faster compared to their relational counterparts. NoSQL databases are a good choice when you have to work with a large volume of data - particularly useful in statistical or real-time analysis of data. Entity Framework 7 now provides support for non-relational databases as well. The support for no-SQL in Entity Framework 7 is great. Interestingly, for querying and updating data in non-relational databases, you can use the same approach you are familiar with.

The following code snippet illustrates how you can use Entity Framework 7 with Microsoft Azure Table Storage to initialize a connection to the database.

public class StoresContext : DbContext
protected override void OnConfiguring(DbContextOptions options)
var connection =

The supported providers in Entity Framework 7 include:

  • SQL Server
  • SQLit
  • Azure Table Storage
  • Redis
  • In Memory (for unit testing)

Support for Windows Phone, Windows Store applications and Linux and Macintosh platforms

With Entity Framework 7, Windows Phone, Windows Store and ASP.Net 5 and desktop applications can leverage Entity Framework. Entity Framework 7 would work on SQLLite database -- the database of choice for mobile devices. Entity Framework 7 also provides support for Linux and Macintosh systems where Mono framework has been installed.

Entity Framework 7 is Lightweight and Extensible

Entity Framework 7 is lightweight and extensible -- it comes with more features and flexibility and enhanced performance. Another major change will be the "code first only" approach -- all models in Entity Framework 7 will be represented in the code. You would however be able to reverse engineer a model from the underlying database thanks to the tooling support. Code based modeling is preferred as it is less repetitive and easier to use and manage. You can know more on Entity Framework 7 from Julie Lerman's MSDN article.

Enhanced support for Unit testing

Unit testing allows you to test blocks or units of the source code. Unit testing is simpler with EntityFramework 7. The code snippet given below shows a sample unit test.

public void SampleTest()
var options = new DbContextOptions()
using (var db = new StoresContext(options))
//Code to perform CRUD operations
//Assert the results

Effort is an easy to use and powerful unit testing tool for applications that use Entity Framework. It is actually an ADO.Net provider that comes with some helper methods that enables you to execute the CRUD operations on a lightweight in-memory database for faster execution. Effort is an Entity Framework provider that runs in memory. When writing your unit tests you can still use your familiar DbContext or ObjectContext classes. Most importantly, you are not constrained to have an actual database – your unit tests would be executed against the in-memory database.

Stephen Walther has a nice post on how you can work with Entity Framework 7.

Copyright © 2015 IDG Communications, Inc.

How to choose a low-code development platform