Continuing work on the Genre and Year API functionality. It is now working, just need to add it to the api #41 #42

This commit is contained in:
amazing-username
2019-05-17 22:31:57 -04:00
parent a471d40cb6
commit 30abf31877
8 changed files with 279 additions and 13 deletions
+16 -1
View File
@@ -22,7 +22,9 @@ namespace Icarus.Models.Context
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Song>()
.ToTable("Song")
.ToTable("Song");
modelBuilder.Entity<Song>()
.HasOne(s => s.Album)
.WithMany(al => al.Songs)
.HasForeignKey(s => s.AlbumId)
@@ -33,6 +35,19 @@ namespace Icarus.Models.Context
.WithMany(ar => ar.Songs)
.HasForeignKey(s => s.ArtistId)
.HasConstraintName("ForeignKey_Song_Artist");
modelBuilder.Entity<Song>()
.HasOne(s => s.SongGenre)
.WithMany(gnr => gnr.Songs)
.HasForeignKey(s => s.GenreId)
.HasConstraintName("HasForeignKey_Song_Genre");
modelBuilder.Entity<Song>()
.HasOne(s => s.SongYear)
.WithMany(yr => yr.Songs)
.HasForeignKey(s => s.YearId)
.HasConstraintName("HasForeignKey_Song_Year");
modelBuilder.Entity<Song>()
.Property(s => s.Year)
.IsRequired(false);