BT

Your opinion matters! Please fill in the InfoQ Survey!

Entity Framework 5 - Performance Considerations

| by Roopesh Shenoy  Followers on Apr 10, 2012. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

While Entity Framework (EF) 5 promises to bring significant performance improvements over EF 4, there are still some considerations to be aware of to use the ORM effectively – namely View generation, Caching, auto-compiled queries, Query execution options and Design-time considerations.

Microsoft has released a white paper outlining various performance considerations while using the yet-to-be-released Entity Framework 5 (which will run under the up-coming .NET 4.5).

Some interesting factors to watch out are -

  • Cold-vs-Warm query execution – there is a view generation step (transformations necessary to go from database schema to conceptual schema and vice-versa) which adds to the overhead the first time a query is run – later runs are faster due to view-caching. You could pre-generate views to improve performance.
  • Caching – at object level (especially improves DbContext Find() in conjunction with disabling AutoDetectChanges), Query Plan Caching, MetaData Caching and Results Caching. There is still no second-level caching for EF, although there is guidance on how to implement one – a sample on codeplex and Julia Lerman’s article “Second Level Caching in Entity Framework and Windows Azure
  • Option for No-Tracking queries (without the overhead of state tracking). This is available only for ObjectQuery though and not for DbSet and DbQuery classes
  • Fast Micro-ORM style SqlQuery on Database and ExecuteStoreQuery
  • Design-time considerations – Table-per-hierarchy (TPH) vs. Table-per-Type (TPT) vs. Table-per-Class (TPC); TPT is the worst in terms of resulting query complexity and performance
  • Lazy-vs-Eager loading

Entity Framework is a Commercial Object-Relational Mapper for .NET applications provided by Microsoft free of cost. Apart from EF, there are several mature alternatives (both Open Source and Commercial) available for .NET developers, like NHibernate and LightSpeed, along with light-weight micro-ORMs like Dapper.NET, PetaPoco and Massive.  

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT