The one-to-many EF Lazy-Load pattern

If we take a wider look at the amount of source code we have written, we can easily note how each Foreign Key spawned:

  • A single-object entity property with the same type of the entity we’re referring to in the class containing the Foreign Key
  • A type-defined listing property in the related class

This pattern won’t change as long as we’re defining one-to-many relationships only; an object to the left, leading to a list of related objects to the right.

Are we done with our entities? Yes. Are we ready to deploy our code-first Database? Hardly. Before doing that, we need to take care of two more things:

  1. Set up an appropriate Database Context.
  2. Enable the Code-First Migrations support within our project.

Get ASP.NET Core 2 and Angular 5 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.