Authors: Brian Discoll, Nitin Gupta, Robert Vettor, Zeeshan Hirani, Larry Tenny
Aimed at: developers who want to do more with Entity Framework
Reviewed by: Kay Ewbank
Entity Framework provides a good way of creating data projects for .NET, but this book works on the principle that there's no need to reinvent the wheel; use the work someone else has done.
Entity Framework provides a good way of creating data projects for .NET, but this book works on the principle that there’s no need to reinvent the wheel; use the work someone else has done. To produce the book, the authors took the questions that were posted most regularly to forums about Entity Framework, and put together a set of recipes – solutions to those problems.
Entity Framework users will know that it provides three routes to creating projects – code first, database first, and model first. The examples in the book concentrate mainly on the first two on the basis that most database apps use one or the other of them. What’s more, many of the examples show how to work with EF on what the authors call ‘challenged’ database designs – essentially where the way the database has been badly designed but you have to live with it and work around it. It’s a pragmatic approach.
The book is not designed particularly to teach you how to use EF. Instead, its aim is to show you ways to deal with common situations. One thing to point out is that while the word ‘recipes’ in the title suggests that if you just follow the steps exactly you’ll get a working creation, that’s not always the case. It’s better to treat the examples as showing you the technique, but not necessarily the exact code. There are places, particularly in the early chapters, where the code doesn’t give the results the authors suggest. In most cases this is down to the fact that it doesn’t work with a LocalDB database even though that’s what’s used in the sample code. I suspect the authors wrote it using a specific server then generalized it without checking that the code still worked. It’s irritating, but not disastrous so long as you follow the technique being applied.
The book opens with a chapter introducing Entity Framework and what it does, then goes on to a good chapter on modeling fundamentals. This introduces database first and code first modeling, and usefully goes on to show some of EFs cleverer modeling options such as splitting entities among multiple tables and tables among multiple entities. There’s also a good chapter on querying an entity data model.
Chapter 4 is new in this edition and looks at using EF in ASP.NET MVC (Model View Controller). The next chapter concentrates on the different ways you can load entities from your database, and I couldn’t think of any possibility they’d missed. The more complicated modeling and inheritance problems get a chapter to themselves that is also crammed with examples and good ideas. There’s also a rather specific chapter on working with object services that shows how to use the pluralization service and how to work with identifying relationships, which will be useful to anyone with problems in those particular areas, but the next chapter on using your own classes and POCO (Plain Old CLR Objects) is much more generally applicable.
The final group of chapters looks at more advanced topics, starting with– using EF in n-tier apps with WCF and Web API. There’s a good chapter on stored procedures, and one on functions that shows both creating your own functions, and using those of EF and the storage layer.
The book closes with chapters on improving performance, and concurrency. Despite the niggles of code that doesn’t work completely as shown, I liked this book. It concentrates on how to do things, and the code is well written and simple to understand. The examples are well chosen, and overall I recommend it.