All Blog Posts

Entity Framework Part 5: EF6 New Features!

Check out my previous EF posts: New Entity Framework EF6 Features
Entity Framework 6 was RTMed a few months ago and boasts a metric crap-ton of new features, including asynchronous query support, testability improvements, logging enhancements, stored procedure support in Code First, and general performance improvements. It’s available on NuGet now (beware of the caveats to upgrading existing applications to EF6).

Here’s some info about the new features along with additional references to learn more. Specific questions? Post in the comments sections or ask me on Twitter and I’ll try to get back to you.

Asynchronous Support

One of the new features with a lot of buzz is EF6 supporting the asynchronous features introduced in .NET 4.5. When used in appropriate situations, this can really help performance. Note: Not all situations can benefit from async execution so do your homework before modifying.
Links for more info on async:

Testability Improvements

Generally when testing data access code, you’ll want to abstract it all away behind a repository and mock the repository in your code, and then handle the data access calls in other integration tests. However, some (not me quite yet) are comfortable with working directly with the Context. If you are one of those people, you have some more options in EF6.
Links about testing:

Logging Enhancements

I’m a big fan of the Hibernating Rhinos products, and I use EFProf extensively in day-to-day development. Not only does it show you exactly what SQL EF is generating, but it also formats it in a helpful way and gives you suggestions about how to better optimize your queries.

In EF6, there are additional logging capabilities that enable the developer to log queries from within the application. This allows logging to the console, to the database, to log files, or wherever else your heart desires.
Links about logging:

Stored Procedure Support

I generally don’t use a lot of stored procedures unless I have bulk data operations or crazy grid scenarios that I’m trying to forget. If you need to use stored procedures with code first, you’re in luck—EF6 supports mapping an entity to a stored procedure and handles complicated mapping scenarios. I haven’t personally used it, but it looks really useful.
Links for more on stored procedures:

Custom Code First Conventions

Entity Framework Grinds My GearsI write a lot of custom configuration classes to modify how code first generates my database schema (See part 2 of this series.) One thing that REALLY GRINDS MY GEARS is how code first uses the default length of MAX when generating string fields, unless explicitly told otherwise. This is a terrible design choice. You should not use the data type of NVARCHAR(MAX) unless you specifically need to; and the default should be a reasonable length such as 50. Pre EF6 you were forced to specify every single string length, but with EF6 you can actually modify the convention.
Links on custom conventions:


For a complete list of Entity Framework 6 new features I’d recommend checking out the Entity Framework documentation on the EF website. It looks like version 6.1 is currently being developed and I see some useful modifications on their list.