Posts

Showing posts with the label lazy-loading

How to include navigation property without direct access to foreign key ID using Entity Framework?

How to include navigation property without direct access to foreign key ID using Entity Framework? I have two tables set up as one-to-many with the "one" model being Artist : Artist public class Artist { public Artist() { this.Albums = new HashSet<Album>(); } public int ArtistID { get; set; } public string UserID { get; set; } [Display(Name = "Artist name")] public string ArtistName { get; set; } public virtual ICollection<Album> Albums { get; set; } } and the "many" being Album : Album public class Album { public int AlbumID { get; set; } public int ArtistID { get; set; } public string StringExt { get; set; } public virtual Artist Artist { get; set; } } Now on an album page load, my url uses an id of type string called ID (for example https://website.com/to/albumName) to load the album page. Here's the controller: ID // GET: To public ActionResult Inde...