8.14. Foreign Keys

In previous versions of EF, foreign key fields on entities were hidden from the developer in the generated model. Developers were expected to access the related entity directly instead of querying foreign key fields. This could mean making some additional database queries to join entities and writing some tedious code.

For example, in our code we might be creating a UI for managing FilmShowings. It would be a lot easier if when creating a new film showing we could just set the related FilmID property:

NewFilmShowing.FilmID = FilmID;

In EF4, you can. It may be worth questioning whether you should be working this way, but I think on the whole it avoids additional database queries.

8.14.1. Code-Only/POCOs

One of the biggest ...

Get Introducing .NET 4.0: with Visual Studio 2010 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.