I would like to connect the database tables with EF Core 3.1, based on the code below. The problem is, that the ModellNavigation and the ManufacturerNavigation returns with null. What am I doing wrong? Please help me with this.
public IEnumerable<ViewModel> GetAll()
{
List<ViewModel> models = new List<ViewModel>();
foreach(Detail detail in _context.Detail)
{
ViewModel viewModel = new ViewModel
{
ID = detail.DetailId,
Manufacturer = detail.ModellNavigation.ManufacturerNavigation.Name,
Modell = detail.ModellNavigation.Name,
Consumption = detail.Consumption,
Color = detail.Color,
Year = detail.Year,
Horsepower = detail.Horsepower
};
models.Add(viewModel);
}
return models;
}
public partial class Detail { public int DetailId { get; set; } public decimal Consumption { get; set; } public string Color { get; set; } public DateTime Year { get; set; } public int Horsepower { get; set; } public int Modell { get; set; } public virtual Modell ModellNavigation { get; set; } }- Peter Ruzsin.Include- Aluan Haddad