Papa's Perspective

An Entity Framework Book Worth Your Time

A new book on Code First Entity Framework is a concise, readable guide to the technology.

House plumbing isn't sexy, but I wouldn't want to live without it. Nor would I want to neglect the primary plumbing of my application architecture: data access. Using an Object Relational Mapper (ORM) such as the Entity Framework (EF) properly is paramount, which is why it's important to have solid resources to rely on. Julie Lerman's first Entity Framework book has become the "book of answers" for EF. But since that book's release, EF has evolved and finally implemented a solid Persistence Ignorance (POCO) implementation with its new "Code First" option.

This was great news for developers like me who were itching for EF to go this route. And now, Lerman has teamed up with Rowan Miller (a Microsoft project manager on the EF team) on a follow-up book titled "Programming Entity Framework Code First" (O'Reilly), scheduled to be available in December 2011. I was lucky enough to get an advance copy to review; I was thoroughly impressed (full disclosure: I am friends with both authors).

First off, I can't read an 800-page technical book. I work on a number of things at a time and with the depth of Lerman's first book, it just wasn't targeted for a guy like me. However, her new book is a nearly perfect fit for me. It's fewer than 200 pages, eight chapters, and has zero fluff. I read this book in an afternoon and found it fast-moving yet very informative.

Chapter 1 sets the baseline of what you should and shouldn't expect out of EF Code First. Chapter 2 jumps right into domain classes, EF conventions, and how to use both the data annotations and the fluent API to configure EF. Chapter 3 goes a bit deeper into configuration by demonstrating how to handle mapping, keys, prepare for concurrency, and map complex types. One of the best aspects of this book is that it shows most examples using both the data annotations and the fluent API (which I prefer).

Chapters 4 and 5 dig into the various ways you may want to map tables to entities including 1-to-1, 1-to-many, many-to-many, and how to handle the navigation properties and relationships.  Chapter 6 is a well-written change of pace that demonstrates dealing with database initialization and seed data.

Chapter 7 is titled "Advanced Concepts" and covers an array of topics that didn't fit smoothly elsewhere. Most technical books have this type of chapter; this one covers some nice tips like how (and why) to get to the ObjectContext from the DbContext.

I would have liked a few more tips in this chapter, especially since the authors have done some awesome presentations on difficult topics such as change tracking with disconnected POCOs. But I'm really just nitpicking.

The final chapter is where the authors provide a glimpse at what else is coming in EF Code First. I won't spoil any of the details, but the importance of this chapter is not what's in it, but rather that it's still being actively developed.

Miller is one of Microsoft's key EF influencers, and Lerman knows how to make EF sit, speak and roll over better than just about anyone. It covers the fundamentals every developer needs to know when using EF Code First. One thing to remember, though, is that isn't a soup-to-nuts EF book. If you want that, go grab Lerman's first book.

EF Code First is still EF, so the concepts you know are simply built upon with EF Code First, which is why this new book is a terrific companion. It's a great cover-to-cover read, and I can easily see topics I'll bookmark and come back to when I hit certain scenarios such as table splitting, complex types, changing mapping conventions and handling database generated IDs like GUID and IDENTITY columns. If you're planning on using EF Code First, make getting this book a priority.

About the Author

John Papa is a Microsoft Regional Director and former Microsoft technical evangelist. Author of 100-plus articles and 10 books, he specializes in professional application development with Windows, HTML5, JavaScript, CSS, Silverlight, Windows Presentation Foundation, C#, .NET and SQL Server. Check out his online training with Pluralsight; find him at johnpapa.net and on Twitter at twitter.com/john_papa.

comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.