static void Main() { var ctx = new MusicDbContext(); MusicData dbContext = new MusicData(ctx); for (int i = 0; i < 3; i++) { var artist = new Artist() { Name = "Artist" + i, }; dbContext.Artists.Add(artist); var album = new Album() { Title = "Album" + i}; album.Artists.Add(artist); dbContext.Albums.Add(album); var song = new Song("Song" + i, artist); song.Albums.Add(album); dbContext.Songs.Add(song); } dbContext.SaveChanges(); }
public IHttpActionResult Create(ArtistModel artist) { if (!this.ModelState.IsValid) { return this.BadRequest(ModelState); } var newArtist = new Artist { Name = artist.Name, Country = artist.Country, DateOfBirth = artist.DateOfBirth }; this.data.Artists.Add(newArtist); this.data.SaveChanges(); artist.Id = newArtist.Id; return this.Ok(newArtist); }
public Song(string title, Artist artist) { this.Title = title; this.Artist = artist; this.albums = new HashSet<Album>(); }