The error you are encountering is likely because the MovieCinema property is a collection in the Movie class, not a direct navigation property. You should include the MovieCinemas.Cinema property instead. Additionally, ensure that your context is properly set up and configured. Here's how you can modify your code:
In your MoviesController index action, modify your code to include the MovieCinemas.Cinema property:
public async Task<IActionResult> Index()
{
var allMovies = await _service.GetAll(includeProperties: "MovieCinemas.Cinema");
return View(allMovies);
}
In your EntityBaseRepository, modify the GetAll method to include the Include method properly:
public async Task<IEnumerable<T>> GetAll(params string[] includeProperties)
{
IQueryable<T> query = _context.Set<T>();
foreach (var includeProperty in includeProperties)
{
query = query.Include(includeProperty);
}
return await query.ToListAsync();
}
With these modifications, the Include method should properly handle the navigation property, and you should be able to access the Name of the Cinema in the Movie index. Make sure your database context and configurations are set up correctly to avoid any additional issues.