public override IEnumerable <Movie> All() { // the skips the join on profile and alternative title and populates manually // to avoid repeatedly deserializing the same profile / movie var builder = new SqlBuilder() .LeftJoin <Movie, MovieFile>((m, f) => m.MovieFileId == f.Id); var profiles = _profileRepository.All().ToDictionary(x => x.Id); var titles = _alternativeTitleRepository.All() .GroupBy(x => x.MovieId) .ToDictionary(x => x.Key, y => y.ToList()); return(_database.QueryJoined <Movie, MovieFile>( builder, (movie, file) => { movie.MovieFile = file; movie.Profile = profiles[movie.ProfileId]; if (titles.TryGetValue(movie.Id, out var altTitles)) { movie.AlternativeTitles = altTitles; } return movie; })); }
public override IEnumerable <Movie> All() { // the skips the join on profile and populates manually // to avoid repeatedly deserializing the same profile var builder = new SqlBuilder() .LeftJoin <Movie, AlternativeTitle>((m, t) => m.Id == t.MovieId) .LeftJoin <Movie, MovieFile>((m, f) => m.Id == f.MovieId); var movieDictionary = new Dictionary <int, Movie>(); var profiles = _profileRepository.All().ToDictionary(x => x.Id); _ = _database.QueryJoined <Movie, AlternativeTitle, MovieFile>( builder, (movie, altTitle, file) => Map(movieDictionary, movie, profiles[movie.ProfileId], altTitle, file)); return(movieDictionary.Values.ToList()); }
public List <Profile> All() { return(_profileRepository.All().ToList()); }