O'Reilly logo

ASP.NET Core: Cloud-ready, Enterprise Web Application Development by James Singleton, Valerio De Sanctis, Mugilan T. S. Ragupathi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining relationships

Now that we have built our main entity skeleton we need to create some relationships between them. We want to be able to do stuff like retrieving an Item, browsing to their related Comments, then getting the ApplicationUser for each one of them, and also the other way around. We can easily do that by implementing a set of related entity properties: EF will load them on demand using its default lazy-load retrieval feature.

The first thing we'll do is to add a new region to our Item class, containing two new properties:

#region Related Properties /// <summary> /// Current Item's Author: this property will be loaded on first use using EF's Lazy-Loading feature. /// </summary> [ForeignKey("UserId")] public virtual ApplicationUser ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required