Chapter 15. Working with Relationships and Associations

At this point in the book, you have worked extensively with entities that are related to one another. You have also experienced a number of scenarios where it was necessary to do extra work to an object because of its associations. For example, when you map stored procedures to entities, you are required to account for any associations the entity was involved in, even when it doesn’t make sense to do so. Remember seeing the ReservationID of the BreakAwayModel as a parameter of the DeletePayment function? You learned that if an EntitySet is mapped using a QueryView, every other related entity also needs to be mapped using a QueryView. In building a WCF service in Chapter 14, you had to do a little extra work to make sure that when inserting new contacts, the context did not also attempt to create a new Trip entity.

So much is going on behind the scenes with respect to how the Entity Framework manages relationships that it causes a lot of unexpected behavior, seemingly strange errors, and many rules that we need to follow. The rules are in place to maintain the integrity of these relationships.

It’s important to remember that the Entity Data Model (EDM)—because it is based on an Entity Relationship Model (ERM)—is a model of entities and relationships, not a model of entities that happen to have relationships. In the EDM, relationships are represented as associations, which are actual objects in the model and have the same importance ...

Get Programming Entity Framework 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.