BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Entity Framework 5 - Performance Considerations

by Roopesh Shenoy on Apr 10, 2012 |

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.  

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

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT