예제 #1
0
 private void SaveChanges()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext.Attach(this.data);
         dbContext.SaveChanges();
     }
 }
예제 #2
0
 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();
     }
 }
예제 #4
0
 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();
            }
        }
예제 #7
0
        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();
            }
        }