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

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube