I use Entity Framework, and I have a many-to-many relationship in the database between Users and Boxes, like this:
public class HistoryEntry
{
public int BoxId { get; set; }
public virtual Box Box { get; set; }
public int UserId { get; set; }
public virtual User User { get; set; }
public int ResultBoxId { get; set; }
public virtual Box ResultBox { get; set; }
}
The key of this “HistoryEntries” table would be a multicolumn key: it consists the BoxId and the UserId:
modelBuilder.Entity<HistoryEntry>().HasKey(entry =>
new
{
BoxId = entry.BoxId,
UserId = entry.UserId
});
However, I want to turn off the lazy loading and the proxy creation because I would use every query with eager loading.
How to rewrite my code in an “eager loading” style?
Use the
Includemethod to eager load the navigational properties.