rdt-client/server/RdtClient.Data/Data/DataContext.cs
Roger Far cccf30c87d Improved logging by switching to Serilog.
Refactored out hardcoded logpath and DB connection string and made them configurable through appsettings.json.
Add persistent store path in docker-compose.
2021-01-09 11:05:33 -07:00

37 lines
No EOL
1.1 KiB
C#

using System.Linq;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using RdtClient.Data.Models.Data;
namespace RdtClient.Data.Data
{
public class DataContext : IdentityDbContext
{
public DataContext(DbContextOptions options) : base(options)
{
}
public DbSet<Download> Downloads { get; set; }
public DbSet<Setting> Settings { get; set; }
public DbSet<Torrent> Torrents { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
var cascadeFKs = builder.Model.GetEntityTypes()
.SelectMany(t => t.GetForeignKeys())
.Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade);
foreach (var fk in cascadeFKs)
{
fk.DeleteBehavior = DeleteBehavior.Restrict;
}
}
}
}