* #102: Moving Models and constants to their own library * #102: Updated sln file * #102: Updated README to include step install migration tool
This commit was merged in pull request #104.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class AlbumContext : DbContext
|
||||
{
|
||||
public DbSet<Album>? Albums { get; set; }
|
||||
|
||||
public AlbumContext(DbContextOptions<AlbumContext> options) : base(options) { }
|
||||
public AlbumContext(string connString) : base(new DbContextOptionsBuilder<AlbumContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Album>()
|
||||
.ToTable("Album");
|
||||
}
|
||||
|
||||
public Album RetrieveRecord(Album album)
|
||||
{
|
||||
var albm = Albums!.FirstOrDefault(alb => alb.Id == album.Id);
|
||||
return albm!;
|
||||
}
|
||||
|
||||
public bool DoesRecordExist(Album album)
|
||||
{
|
||||
return Albums!.FirstOrDefault(alb => alb.Id == album.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user