using System.Collections.Generic; using System.IO; using Microsoft.EntityFrameworkCore; using Ombi.Helpers; using Ombi.Store.Entities; namespace Ombi.Store.Context { public abstract class ExternalContext : DbContext { protected ExternalContext(DbContextOptions options) : base(options) { } /// /// This allows a sub class to call the base class 'DbContext' non typed constructor /// This is need because instances of the subclasses will use a specific typed DbContextOptions /// which can not be converted into the parameter in the above constructor /// /// protected ExternalContext(DbContextOptions options) : base(options) { } public DbSet PlexServerContent { get; set; } public DbSet PlexSeasonsContent { get; set; } public DbSet PlexEpisode { get; set; } public DbSet PlexWatchlistHistory { get; set; } public DbSet RadarrCache { get; set; } public DbSet CouchPotatoCache { get; set; } public DbSet EmbyContent { get; set; } public DbSet EmbyEpisode { get; set; } public DbSet JellyfinEpisode { get; set; } public DbSet JellyfinContent { get; set; } public DbSet SonarrCache { get; set; } public DbSet LidarrArtistCache { get; set; } public DbSet LidarrAlbumCache { get; set; } public DbSet SonarrEpisodeCache { get; set; } public DbSet SickRageCache { get; set; } public DbSet SickRageEpisodeCache { get; set; } public DbSet UserPlayedMovie { get; set; } public DbSet UserPlayedEpisode { get; set; } protected override void OnModelCreating(ModelBuilder builder) { builder.Entity().HasMany(x => (ICollection) x.Episodes) .WithOne(x => (PlexServerContent) x.Series) .HasPrincipalKey(x => x.Key) .HasForeignKey(x => x.GrandparentKey); builder.Entity() .HasOne(p => (EmbyContent) p.Series) .WithMany(b => (ICollection) b.Episodes) .HasPrincipalKey(x => x.EmbyId) .HasForeignKey(p => p.ParentId); builder.Entity() .HasOne(p => (JellyfinContent) p.Series) .WithMany(b => (ICollection) b.Episodes) .HasPrincipalKey(x => x.JellyfinId) .HasForeignKey(p => p.ParentId); base.OnModelCreating(builder); } } }