private void SaveChanges() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { dbContext.Attach(this.data); dbContext.SaveChanges(); } }
private void LoadAlbums() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { dbContext .Attach(this.data) .Collection(artist => artist.Albums) .Load(); } }
private void LoadSongs() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { dbContext .Attach(this.data) .Collection(album => album.Songs) .Load(); } }
private bool LoadFavorite() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(dbContext .Attach(this.data) .Collection(artist => artist.Albums) .Query() .GroupJoin(dbContext.Songs, album => album.AlbumId, song => song.SongId, (album, songs) => songs) .All(songs => songs.All(song => song.Favorite))); } }
private bool LoadFavorite() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(this.anySongs && dbContext .Attach(this.data) .Collection(album => album.Songs) .Query() .All(song => song.Favorite)); } }
private void FavoriteAllSongs(bool favorite) { this.LoadSongs(); using (MusicLibraryContext dbContext = new MusicLibraryContext()) { foreach (Song song in this.data.Songs) { song.Favorite = favorite; dbContext .Attach(song) .Property(_song => _song.Favorite) .IsModified = true; } dbContext.SaveChanges(); } }
private void FavoriteAllSongs(bool favorite) { this.LoadAlbums(); using (MusicLibraryContext dbContext = new MusicLibraryContext()) { foreach (Album album in this.data.Albums) { List <Song> songs = dbContext.Songs.Where(song => song.AlbumId == album.AlbumId).ToList(); foreach (Song song in songs) { song.Favorite = favorite; dbContext .Attach(song) .Property(_song => _song.Favorite) .IsModified = true; } } dbContext.SaveChanges(); } }