Files
icarus/Icarus/Database/Contexts/GenreContext.cs
T
KD a89580ac70 #102: Moving Models and constants to their own library (#104)
* #102: Moving Models and constants to their own library

* #102: Updated sln file

* #102: Updated README to include step install migration tool
2024-08-05 20:05:57 -04:00

37 lines
943 B
C#

using Microsoft.EntityFrameworkCore;
using Icarus.Models;
namespace Icarus.Database.Contexts;
public class GenreContext : DbContext
{
#region Properties
public DbSet<Genre>? Genres { get; set; }
#endregion
public GenreContext(DbContextOptions<GenreContext> options) : base(options) { }
public GenreContext(string connString) : base(new DbContextOptionsBuilder<GenreContext>()
.UseMySQL(connString).Options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Genre>()
.ToTable("Genre");
}
public Genre RetrieveRecord(Genre genre)
{
var gnre = Genres!.FirstOrDefault(gnr => gnr.Id == genre.Id);
return gnre!;
}
public bool DoesRecordExist(Genre genre)
{
return Genres!.FirstOrDefault(gnr => gnr.Id == genre.Id) != null ? true : false;
}
}