[CHANGE] Updated string maxsize on entities. Setup lib dbcontext
This commit is contained in:
@@ -21,11 +21,13 @@ public sealed class ApplicationDbContext : DbContext
|
||||
sg.ToTable("settings_groups");
|
||||
sg.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<SettingsModel>(settingsEntity =>
|
||||
{
|
||||
settingsEntity.ToTable("settings");
|
||||
settingsEntity.HasKey(x => x.Key);
|
||||
});
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
@@ -1,11 +1,89 @@
|
||||
using Manager.Data.Models.LibraryContext;
|
||||
using Manager.Data.Models.LibraryContext.Join;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Manager.Data.Contexts;
|
||||
|
||||
public class LibraryDbContext : DbContext
|
||||
public sealed class LibraryDbContext : DbContext
|
||||
{
|
||||
public LibraryDbContext(DbContextOptions<LibraryDbContext> options) : base(options)
|
||||
{
|
||||
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
ChangeTracker.LazyLoadingEnabled = false;
|
||||
}
|
||||
|
||||
public DbSet<CaptionEntity> Captions { get; set; }
|
||||
public DbSet<ChannelEntity> Channels { get; set; }
|
||||
public DbSet<ClientAccountEntity> Accounts { get; set; }
|
||||
public DbSet<HttpCookieEntity> HttpCookies { get; set; }
|
||||
public DbSet<MediaEntity> Media { get; set; }
|
||||
public DbSet<MediaFormatEntity> MediaFormats { get; set; }
|
||||
public DbSet<PlaylistEntity> Playlists { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CaptionEntity>(ce =>
|
||||
{
|
||||
ce.ToTable("captions");
|
||||
ce.HasKey(x => new { x.MediaId, x.LanguageCode });
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ChannelEntity>(channel =>
|
||||
{
|
||||
channel.ToTable("channels");
|
||||
channel.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ClientAccountEntity>(cae =>
|
||||
{
|
||||
cae.ToTable("client_accounts");
|
||||
cae.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<HttpCookieEntity>(httpce =>
|
||||
{
|
||||
httpce.ToTable("http_cookies");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MediaEntity>(me =>
|
||||
{
|
||||
me.ToTable("media");
|
||||
me.HasKey(x => x.Id);
|
||||
me.HasMany(x => x.Formats)
|
||||
.WithOne()
|
||||
.HasForeignKey(mf => mf.MediaId);
|
||||
me.HasMany(x => x.Captions)
|
||||
.WithOne()
|
||||
.HasForeignKey(ce => ce.MediaId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MediaFormatEntity>(mfe =>
|
||||
{
|
||||
mfe.ToTable("media_formats");
|
||||
mfe.HasKey(x => new { x.MediaId, x.Itag });
|
||||
});
|
||||
|
||||
modelBuilder.Entity<PlaylistEntity>(ple =>
|
||||
{
|
||||
ple.ToTable("playlists");
|
||||
ple.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
/* Join tables */
|
||||
|
||||
modelBuilder.Entity<PlaylistMedia>(pmj =>
|
||||
{
|
||||
pmj.ToTable("join_playlist_media");
|
||||
pmj.HasKey(x => new { x.PlaylistId, x.MediaId });
|
||||
|
||||
pmj.HasOne<PlaylistEntity>()
|
||||
.WithMany(pe => pe.PlaylistMedias)
|
||||
.HasForeignKey(fk => fk.PlaylistId);
|
||||
pmj.HasOne<MediaEntity>()
|
||||
.WithMany(me => me.PlaylistMedias)
|
||||
.HasForeignKey(fk => fk.MediaId);
|
||||
});
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user