Book Review: Programming Entity Framework, Second Edition

by mosessaur| 02 January 2011| 0 Comments

About the book

Title: Programming Entity Framework 2nd Edition
Publisher: O'Reilly Media
URL: http://oreilly.com/catalog/9780596807252
Book website: http://learnentityframework.com/
ISBN: 978-0-596-80726-9
Chapters: 27 + 3 Appendices | ~900 pages
Author:
Author’s blog: http://thedatafarm.com/blog/
Overall rating: 9.70 out of 10
This is the second edition of the book totally revised for Entity Framework 4.0 on VS2010 1st edition was released Jan 2009. this 2nd new edition released August 2010.

Personal Opinion

I can’t do anything but strongly recommend this book. It is almost everything you might need about Entity Framework 4.0. Great walkthroughs and samples in C#. However there are few snippet in VB.Net that shows different syntax of doing things between C# & VB.Net.

What I liked about the book

  • The book is very well organized. Suitable for both experienced Entity Framework developers & newbies in Entity Framework. For experienced developers they can pick the chapters in any order they wish. And for newly comers, following the chapters sequence couldn't be much better.
  • Walkthroughs & samples are very well written.
  • I liked how Julie recommends the new APIs when applicable over the old ones that already exists since the first release of Entity Framework in .Net 3.5 SP1. I also liked how she propose her coding convention which I personally admire.
  • On each chapter, when some topic goes beyond the scope of the chapter, you'll find a reference to another chapter that should contains much more details. I personally think this is great to give better navigation guide around the book especially for eBook version.
  • I like the trap hints and tips & sidebars on every chapter. Very helpful information & tips.

What I didn’t like about the book

It is just too long. Almost reached ~1000 pages. However you don’t need to read it all. I did because I didn’t want to miss single tip that I might regret not reading it.

Another thing, in some chapters I didn’t like the practice being used like in Chapter 27 –storing customer related data in session-. The whole idea about me not liking this is just some developers will take it as common practice while it is not. However Julie was careful to hint most of times that these are not considered best practices and it is just for demonstration.

Book description –as stated in the book page–

Get a thorough introduction to ADO.NET Entity Framework 4 -- Microsoft's core framework for modeling and interacting with data in .NET applications. The second edition of this acclaimed guide provides a hands-on tour of the framework latest version in Visual Studio 2010 and .NET Framework 4. Not only will you learn how to use EF4 in a variety of applications, you'll also gain a deep understanding of its architecture and APIs.

Written by Julia Lerman, the leading independent authority on the framework, Programming Entity Framework covers it all -- from the Entity Data Model and Object Services to WCF Services, MVC Apps, and unit testing. This book highlights important changes for experienced developers familiar with the earlier version.

  • Understand the core concepts you need to make the best use of the EF4 in your applications
  • Learn to query your data, using either LINQ to Entities or Entity SQL
  • Create Windows Forms, WPF, ASP.NET Web Forms, and ASP.NET MVC applications
  • Build and consume WCF Services, WCF Data Services, and WCF RIA Services
  • Use Object Services to work directly with your entity objects
  • Create persistent ignorant entities, repositories, and write unit tests
  • Delve into model customization, relationship management, change tracking, data concurrency, and more
  • Get scores of reusable examples -- written in C# (with notes on Visual Basic syntax) -- that you can implement right away

Programming Entity Framework at glance

The book is divided into 2 parts consisting of 27 chapters plus 3 appendices making around ~900 pages. I recognize this book as 2 books in one. First part second part can be considered as the 2 books. First part ((ch01-ch12) ) as the author stated can be considered as introduction to Entity Framework. While second part (ch13-ch27) takes you much deeper into details of Entity Framework. So it can be considered as the advanced part of the book.

Chapter 01 - Introducing the ADO.NET Entity Framework

Rate: 10/10

As Julie stated, this chapter could be called, "It's time for Entity Framework" showing why it's important and why it's Microsoft recommended data access technology. Highlighting that Entity Framework is being used as part of some Microsoft products.

I really love how the chapter introduces almost everything about entity framework highlighting the chapters that will cover these topics in details. The Chapter is like scouting journey map that tells you what you are going to learn during this journey.

I think it is a must read chapter. It's the door for the book, where if you are already familiar with Entity Framework, you'll jump to the chapter(s) you wish to focus on. And if you are new to Entity Framework, the chapter will open you mind to what you are going to learn.

This chapter basically introduces you to critical pieces of Entity Framework. You'll learn about those things that give Entity Framework it's core value, understanding that Entity Framework is where you program against business models.

Julie shows in a simple clear example how database schema is represented with entities in Entity Framework EDM. With different database engines of your choice, you should only worry about your business object model. The chapter also introduces tools and APIs (at glance) that forms the core features of Entity Framework.

Chapter 02 - Exploring the Entity Data Model

Rate: 10/10

Highlights the benefit of using EDM and programming against conceptual model with detailed tutorial walkthrough on building your first EDM using Entity Framework with VS2010.

Start exploring your generated EDM under a microscope to learn more about EDM. Learn about different terms used descripting entities and their properties in EDM.

You’ll also learn about different windows in EDM Designer that will assist you modifying and gain control over the design time of your EDM.

You’ll explore XML parts (CSDL, SSDL & MSL) that forms the EDM. And if you are interested to diver deeper there is appendix that should assist you dig deeper into XML that forms EDM parts.

Chapter 03 - Querying Entity Data Models

Rate: 10/10

Learn the foundations of querying data using Entity Framework. No deep dive in this chapter, just warm up with query options you have. Have a look at generated code by VS2010 EF Designer of your EDM. Explore the classes and understand them clearly

Demonstrate how to querying data using Entity Framework applying same query with different styles & flavors of queries supported by Entity Framework through clean and descriptive walkthroughs.

The chapter will help you to gain a high level understanding of all of the query options and their basic uses.

I like that the chapter introduces LINQPad to readers. Because it gives them the ability to test queries without the need of building sample console application to test those queries when the EDM is read. Same thing for EfProf to analyze and profile the performance of your queries made with Entity Framework.

Chapter 04 - Exploring LINQ to Entities in Greater Depth

Rate: 9.75/10

Learn about critical features of querying your model using LINQ to Entities focusing on the most typically needed query features. You are going to dive deep so you better be prepared with some LINQ skills before you start reading this chapter.

You’ll learn:

  • How to do filtering, projection, sorting, joins, aggregation, grouping and query across relationships using LINQ to Entities. Learning about querying isn't going to stop by this chapter, there are a lot more examples and samples in subsequent chapters.
  • About projection, eager loading, differed loading, lazy loading and navigating using navigation properties. You'll also learn about anonymous types and how you can return anonymous types from your queries and how this can help you be flexible.
  • How to build nested queries to serve different query scenarios.
  • About different loading options of entity's related data such deferred loading, lazy loading and eager loading. Discover the pros and cons of each approach.

I really liked how Julie -when applicable- differentiate between C# & VB.Net syntax when using LINQ.

Chapter 05 - Exploring Entity SQL in Greater Depth

Rate: 9.5/10

Another deep dive about querying with Entity Framework, this time in Entity SQL.

You’ll learn:

  • About the differences between LINQ to Entity and Entity SQL and explore different scenarios where Entity SQL could a better choice.
  • About critical features of Entity SQL and what makes it great querying language for Entity Framework. You'll also learn about its limitations.
  • How to do filtering, projection, sorting, joins, aggregation, grouping and query across relationships.

The take on this chapter is that I wished that for certain queries Julie could provide the output results of queries. Especially those queries that looks similar to each others except for a slight difference that change the shape of the returned data.

Chapter 06 - Modifying Entities and Saving Changes

Rate: 10/10

Take a high-level look at the way in which the Entity Framework is able to track these changes and get the necessary data back to the database. This is like the ABC of Insert, Update, Delete operations using EF

You’ll learn:

  • How to perform updates, inserts, and deletions with Entity Framework object services. And go under the hood to see what happens in the database in response.
  • How Entity Framework manage to track changes of your entities behind the scene.

Chapter 07 - Using Stored Procedures with the EDM

Rate: 10/10

In this chapter you’ll learn:

  • How to override the Entity Framework’s command generation feature for a particular entities and direct it to use your custom stored procedures when persisting changes to database.
  • How to build and map stored procedures that returns data to existing entities in your EDM as well as stored procedures that return scalar values. You'll also learn how to map a result from a stored procedure to complex type.
  • About different mapping designer windows and model browser window in EF Designer inside VS2010
  • About combining entities that map to database views with stored procedures to provide fully functional entities that completely avoid direct table access.

Chapter 08 - Implementing a More Real-World Model

Rate: 10/10

On this chapter you'll start to meet the real world with Entity Framework creating a more realistic EDM based on a database of the kind you’re more likely to encounter in your work. However the model is still smaller than a typical enterprise model saving you distraction and confusion for faster and better understanding of real world EF applications.

You’ll learn:

  • How to build you model in separate assembly so that you can reuse it. And in fact it is going to be reused throughout the rest of the book.
  • How you can manage your entities by renaming them or their properties. And explore what kind of conflicts you might face. Also it shows you how the separation between the conceptual model and your database structure is of a great benefit.

The chapter is alike a walkthrough on all the previous chapters to build real-world model.

Chapter 09 - Data Binding with Windows Forms and WPF Applications

Rate: 10/10

Explore basic data-binding scenarios in Windows Forms and Windows Presentation Foundation (WPF).

See how the Entity Framework objects work with Visual Studio’s data-binding features. The chapter does not presume that you are familiar with Windows Forms or with WPF data-binding techniques in the VS2010 IDE and so it moves step-by-step walkthrough to be sure that the UI tasks don’t trip you up.

This chapter contains long walkthroughs on working with Entity Framework on Windows Forms and WPF,

You’ll learn about Data Source Controls in Windows Forms & the difference between object data source & Data Source that interacts directly with the database. The WPF part of the chapter shows how to use WPF new Data Binding capabilities provided through VS2010 with Entity Framework.

Chapter 10 - Working with Object Services

Rate: 10/10

In this chapter you’ll gain better understanding of the Object Services API, what it’s responsible for, what it does under the covers, and some of the ways that you can take advantage of it. You are going to have a  closer look at the ObjectContext, the most important Object Services class.

You’ll learn:

  • Learn how you can take charge of your entity objects using Object Services APIs.
  • How queries are processed and turned into objects, how these objects are managed during their life cycle and how Object Services is responsible for the way entities are related to each other.
  • How the ObjectQuery and the new ObjectSet work and how they relate to LINQ to Entities queries under the covers.
  • Beyond the basics and understand of how Object Services manages an entity’s state.

Chapter 11 - Customizing Entities

Rate: 10/10

In this chapter you’ll learn

  • How Entity Framework provides a number of ways to not only add your own logic, but also use your own classes and plug them into an ObjectContext.
  • How to use partial classes to add new logic to entities or override their existing logic. Understand the criteria and of creating partial classes.
  • How to change the rules for code generation and in doing so create classes from the model that are more to your liking.

Chapter 12 - Data Binding with RAD ASP.NET Applications

Rate: 10/10

this chapter is about how to build RAD ASP.NET web applications using entities that make use of the EntityDataSource control. You’ll take tour of some of the more interesting features of the EntityData Source control You’ll see what EntityDataSource do behind the scene to maintain your changes to your entities across page PostBacks.

You’ll also build a quick ASP.NET Dynamic Data website so that you can see how Dynamic Data simplifies some of the manual tasks you have to perform when using the EntityDataSource directly.

The chapter won’t delve too deeply into this area, as you can learn much more about these in many ASP.NET resources.

Chapter 13 - Creating and Using POCO Entities

Rate: 10/10

This chapter will introduce you to what is persistence ignorance and what are Plain Old CLR Objects also known as POCOs.

You’ll learn:

  • The basics of how to manually create and work with POCOs in Entity Framework to manage these classes so that it can perform its job of executing queries, returning objects, persisting changes to the database, and so forth.
  • How to generate POCOs using T4 templates.

Chapter 14 - Customizing Entity Data Models Using the EDM Designer

Rate: 10/10

You will spend much of your time in this chapter working directly with the XML. You’ll learn:

  • About some of the many ways in which you can customize an EDM, the benefits of these customizations, and when you would want to take advantage of them. All this through a step by step walkthroughs that will give you detailed information on how to apply mapping customization.
  • How to build Table per Type inheritance with EF. And how to perform queries against this model as well as insert, update & delete. You'll also understand what's happing behind the scene on database level.
  • How to map an entity to more than one table and to split single table to more than one entity.
  • How to create complex types and use them in your model.
  • How to build queries using the new mappings and interact with the objects that are based on the various entities

Chapter 15 - Defining EDM Mappings That Are Not Supported by the Designer

Rate: 10/10

In this chapter you’ll learn:

  • How to modify the XML manually to build model-defined functions, table per concrete type inheritance, and QueryView.
  • How to write model defined functions using Entity SQL and use them in your query model using LINQ to Entities.
  • How to build and use QueryView to Create Read-Only Entities and Other Specialized Mappings. You'll understand constrains to build QueryViews.

Chapter 16 - Gaining Additional Stored Procedure and View Support in the Raw XML

Rate: 10/10

Cover ways to implement stored procedures beyond the function mapping you already performed in the Designer. These additional implementations will create functions that you can call directly in your code. You’ll learn how to create native functions and views directly in your model.

Chapter 17 - Using EntityObjects in WCF Services

Rate: 10/10

Write a WCF service that makes use of EntityObject-based entities. If you have never built a WCF service before, have no fear. The walkthroughs will provide you with step-by-step details

You’ll learn about some of the complications that arise (and their solutions) while you work across the tiers of a distributed application. And take a quick look at WCF Data Services and WCF RIA Services in order to get an understanding of how they relate to the Entity Framework.

Chapter 18 - Using POCOs and Self-Tracking Entities in WCF Services

Rate: 10/10

Get introduced to Entity Framework new feature of Self-Tracking Entities. You’ll learn:

  • How to create WCF-Friendly POCO classes.
  • How to separate your models in separate class library project and reuse it in your WCF Services through a complete and clear walkthroughs.
  • How to build Entities using T4 template in VS2010 and build a WCF service that uses Self-Tracking Entities
  • About the impact of using POCO entities in WCF Data Services and WCF RIA Services instead of EntityObjects.

Chapter 19 - Working with Relationships and Associations

Rate: 10/10

In this chapter you’ll dig much deeper into how relations and associations in Entity Framework are built and managed.

You’ll learn:

  • How relationships and associations fit into the EDM and how they work both inside and outside the ObjectContext.
  • How to manipulate relationships between entities, adding or removing relationships between objects in the way that the Entity Framework expects; you will be able to solve problems that arise because of relationships; you will even enhance your ability to build more meaningful Entity Data Models.

The chapter is divided into two parts.

  1. The first part is devoted to teaching you how relationships and associations work in the Entity Framework, from the EDM to the EntityObjects.
  2. The second part will teach you how to perform a number of critical tasks relating to entity graphs as you work with sets of related entities.

Chapter 20 - Real World Apps: Connections, Transactions, Performance, and More

Rate: 9.5/10

In this chapter You’ll learn

  • More about working with entity connections and the database connections that they create for you, and how to explicitly open and control those connections, even when interleaving read and write operations to the database.
  • How transactions work by default, as well as how to replace the default database transactions that Entity Framework uses with .NET’s TransactionScope.
  • About different ways you can improve performance in Entity Framework, as well as the results of some performance comparisons made by the author.

You’ll also take a look at how to use Entity Framework in a few multithreading scenarios.

Chapter 21 - Manipulating Entities with ObjectStateManager and MetadataWorkspace

Rate: 9/10

Understand why ObjectStateManager & MetadataWorkspace classes are important APIs in Entity Framework. You’ll also learn:

  • How to use ObjectStateManager and MetadataWorkspace in your own applications to control and manipulate entity objects.
  • How to interact with entities and entity state through the ObjectStateManager
  • About interacting with the raw metadata using the MetadataWorkspace.

You'll build more samples that will give you great hands-on experience working with ObjectStateManager and MetadataWorkspace.The chapter also contains many code samples that you can use in your applications.

Chapter 22 - Handling Exceptions

Rate: 10/10

This chapter is short one and it is all about exceptions that are unique to the Entity Framework and how to handle them. Some exceptions are Entity Framework-specific exceptions, and others are .NET exceptions caused by faulty operations when using the Entity Framework.

The chapter tries to cover every possible scenario that might cause an exception when using Entity Framework and points your to the type of exceptions being thrown.

Chapter 23 - Planning for Concurrency Problems

Rate: 10/10

Learn about concurrency problem and its different types exploring different scenarios where concurrency problems can happen.

Learn how to set up your model so that the Entity Framework will alert you to conflicts when persisting data to the database, and then you’ll learn how to capture and handle OptimisticConcurrencyException

Explore different options to achieve concurrency checking when using Entity Framework.

Chapter 24 - Building Persistent Ignorant, Testable Applications

Rate: 8/10

This chapter is about bringing testability to applications that use Entity Framework. You’ll receive an introduction to testing and other agile coding practices while learning more about the Entity Framework and how to put these practices in action with Entity Framework. However this is a very narrow slice of agile programming & practices.

Chapter 25 - Domain-Centric Modeling

Rate: 9/10

Learn how to use the new model-first feature along with interacting with the design tools through a detailed walkthrough.

Also learn about Code First approach which is currently in CTP and the book actually discuss an old CTP. Current one is CTP5 and it is way different than the one mentioned in this chapter. But it will give you an idea of what is this about.

Get a short introduction to another future technology, SQL Server Modeling and its modeling language, currently code-named “M”.

Chapter 26 - Using Entities in Layered Client-Side Applications

Rate: 9.5/10

Explore ways in which you can disentangle the UI of a layered client application from its business and data access logic while retaining certain key benefits of the Entity Framework.

You’ll learn:

  • How to keep the data persistence code out of the user interface.
  • To focus on building application logic based on your domain needs, not based on the needs of a particular user interface through a detailed walkthroughs.

The chapter will help you gain a clear understanding of which code does and does not belong in the UI, most of this chapter will demonstrate restructuring the WPF application from Chapter 9. A side benefit is that you will get to leverage the UI that you’ve already created rather than building a new one.

Chapter 27 - Building Layered Web Applications

Rate: 8/10

Look at some better ways to use entities in better architected web applications.

You’ll build 2 different kind of ASP.Net web application where in the first you'll be using ASP.NET Web Forms application where you can take advantage of ASP.NET’s Session and ViewState features to retain object data across post backs. In the second you will use classes in a simple ASP.NET Model-View-Controller (MVC) application.

You’ll see how to separate the logic out using similar methods as you are supposed to learn in chapter 26. You’ll also learn a few tricks that are specific to entities in MVC applications

Appendices

There are 3 appendices. Appendix A about Entity Framework related assemblies & namespaces inside .Net 4.0. Appendix B is about Data binding with complex types. And finally appendix C gives additional details about EDM schema and Metadata.

Conclusion

This is almost everything about Entity Framework book. It’s long one, but that returns to the attempt to cover everything. And I guess the book succeeded. The book written carefully and fully revised for EF 4.0. I really appreciate the effort spent on the book to deliver this quality of well written walkthroughs & explanation.

I hope you find this review useful.

Pingbacks and trackbacks (2)+

Comments are closed