Сопоставитель .NET 8 EF Include() не работает — возвращает пустой список рейтингов ⇐ C#
-
Anonymous
Сопоставитель .NET 8 EF Include() не работает — возвращает пустой список рейтингов
This is my code that get each type of entreprises and must include the ratings :
public async Task GetTopFiveBytypeyEntreprises() { List hotels = await apiDbContext.Entreprises .Include(e => e.Ratings) // Include Ratings navigation property .Where(x => x.Type.Equals("Hotel")) .OrderByDescending(x => x.Supported) .Take(4) .ToListAsync(); List restaurants = await apiDbContext.Entreprises .Include(e => e.Ratings) // Include Ratings navigation property .Where(x => x.Type.Equals("Restaurant")) .OrderByDescending(x => x.Supported) .Take(4) .ToListAsync(); List activities = await apiDbContext.Entreprises .Include(e => e.Ratings) // Include Ratings navigation property .Where(x => x.Type.Equals("Activity")) .OrderByDescending(x => x.Supported) .Take(4) .ToListAsync(); return new TopFiveTypeDTo() { Hotels = hotels, Restaurant = restaurants, Activities = activities }; } The output doesn't use the .Include() - it just returns an empty list of ratings
Источник: https://stackoverflow.com/questions/780 ... of-ratings
This is my code that get each type of entreprises and must include the ratings :
public async Task GetTopFiveBytypeyEntreprises() { List hotels = await apiDbContext.Entreprises .Include(e => e.Ratings) // Include Ratings navigation property .Where(x => x.Type.Equals("Hotel")) .OrderByDescending(x => x.Supported) .Take(4) .ToListAsync(); List restaurants = await apiDbContext.Entreprises .Include(e => e.Ratings) // Include Ratings navigation property .Where(x => x.Type.Equals("Restaurant")) .OrderByDescending(x => x.Supported) .Take(4) .ToListAsync(); List activities = await apiDbContext.Entreprises .Include(e => e.Ratings) // Include Ratings navigation property .Where(x => x.Type.Equals("Activity")) .OrderByDescending(x => x.Supported) .Take(4) .ToListAsync(); return new TopFiveTypeDTo() { Hotels = hotels, Restaurant = restaurants, Activities = activities }; } The output doesn't use the .Include() - it just returns an empty list of ratings
Источник: https://stackoverflow.com/questions/780 ... of-ratings
Мобильная версия