BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Entity Framework 7: New Platforms and New Data Stores

Entity Framework 7: New Platforms and New Data Stores

Bookmarks

Entity Framework was created solely for working with relational data on the full version of .NET. In EF 7, neither of those statements is true.

The platform goal for Entity Framework 7 includes

  • .NET Full Framework
  • ASP.NET 5
  • Windows 10 UAP
  • Mac
  • Linux

On the provider side, EF 7

  • Relational Providers: SQL Server, SQLite, Postgres
  • Azure Table Storage
  • Redis
  • In Memory Provider (for testing)

The Top-level experience is the same as EF 6, you will still be working with DbContext, DbSet, etc. Internally the core has been rewritten. This means the metadata, change tracking, query pipeline, etc. are all different, but for most applications the developer won’t notice.

The core is being changed for a number of reasons. One reason is that current architecture is very difficult to work with. Even basic things like plugging in a logging framework is far more difficult that necessary. By rewriting the core, confusing APIs and behaviors can finally be removed.

EF is well known for being memory hungry and slow. A major emphasis for the rewrite is to address these concerns. This is important across the board, from small mobile devices with limited battery life to massive cloud severs where you pay for CPU utilization.

Logging

Logging in Entity Framework is based on the ILogger interface from the Microsoft.Owin.Logging namespace. Microsoft’s hope is that this will become the standard interface that all .NET logging frameworks support.

SQL Generation Improvements

Insert and update operations are slightly better in EF 7. Say, for example, you want to apply a discount to four products in a table. When using EF 6, this would require 1+N round-trips to the database: one to load the data and one for each row. In EF 7, save operations are batched so that you only need two round-trips to the database.

This is still slower than the one round trip that you would get when using native SQL, but it also works for non-relational databases.

Mixing SQL and LINQ

EF 7 supports mixing FromSQL with LINQ expressions. This allows you to access things that EF cannot normally work with such as Table Value Functions or index-hinted tables.

context.FromSql<Customer>("SELECT * FROM Customer (WITH (IX_Index)").OrderBy(c => c.Name)

This will generate the correct SQL to perform the order by, where, etc. in the database.

EF and Mobile Devices

As mentioned above, one of the goals of EF 7 is to not be limited to just desktop applications. One of the use cases for this is offline mobile devices. The idea is that you should be able to use the same code on your mobile device to locally cache and manipulate data that you would use on your server.

For more information on Entity Framework 7, watch the Channel 9 video Entity Framework 7: Data for Web, Phone, Store, and Desktop.

Rate this Article

Adoption
Style

BT