Chapter 13. Creating and Using POCO Entities

When it was first released, Entity Framework was roundly criticized by agile developers. These developers hold the tenets of domain-driven development and testability very high. The classes generated from the Entity Data Model (EDM) are very tightly bound to the Entity Framework APIs by either inheriting from the EntityObject or implement interfaces that allow the classes to participate in change tracking and relationship management.

The problem with this is that it is extremely difficult to separate the concerns of your application into smaller pieces of logic to make it more maintainable. Additionally, it is difficult to write unit tests with EntityObjects. Many of the methods that need to be tested perform some type of interaction with the database. In unit testing, you need to emulate this persistence. In other words, instead of literally querying the database, a test might supply some fake data to a class, or instead of sending data to the data store, a test might say “OK, let’s pretend that part just happened and we’ll move on now.”

In addition to the problems the dependent classes create for separation of concerns and for testing, it also makes it difficult for developers to change their backend infrastructure if needed. For example, an application might be written using another object relational mapping tool, such as NHibernate. If a developer wanted to switch to the Entity Framework, version 1 made it very difficult to just take ...

Get Programming Entity Framework, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.