using Microsoft.EntityFrameworkCore; using Icarus.Models; namespace Icarus.Database.Contexts; public class SongContext : DbContext { public DbSet? Songs { get; set; } public SongContext(string connString) : base(new DbContextOptionsBuilder() .UseMySQL(connString).Options) { } public SongContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .ToTable("Song"); modelBuilder.Entity() .Property(s => s.Year) .IsRequired(false); modelBuilder.Entity() .Property(s => s.GenreId) .IsRequired(false); modelBuilder.Entity() .Property(s => s.ArtistId) .IsRequired(false); modelBuilder.Entity() .Property(s => s.AlbumId) .IsRequired(false); modelBuilder.Entity() .Property(s => s.CoverArtId) .IsRequired(false); } public Song RetrieveRecord(Song song) { var sng = Songs!.FirstOrDefault(sng => sng.Id == song.Id); return sng!; } public bool DoesRecordExist(Song song) { return Songs!.FirstOrDefault(sng => sng.Id == song.Id) != null ? true : false; } }