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

In Chapter 17, you built a custom WCF service using entities that inherit from EntityObjects. While some of the new Entity Framework features introduced in .NET 4, such as foreign key support and methods to change entity state, have made this much easier to do than in the previous version of Entity Framework, it is still challenging and requires that you know a lot about manipulating entities.

Removing EntityObjects from the payload removes some of these challenges. In the previous edition of this book, I demonstrated a common approach to building services in .NET 3.5, which was to use Data Transfer Objects (DTOs) to carry the object’s data between the client and the service. But the most time-consuming part of this task was converting the EntityObjects to DTOs and back again. The DTOs, however, provided two key benefits. The first was that they greatly reduced the complexity of the payload. The second was that they enabled you to inject state properties directly into the classes so that when the data came back to the service, you didn’t have to use extra logic to determine what was inserted, updated, deleted, or left untouched.

Now that Entity Framework supports POCO classes, the need for using DTOs is greatly reduced. You can do away with them completely if you want, although your architecture may require them for different reasons unrelated to the Entity Framework, or simply because your architecture is designed ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.