mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 04:20:55 +00:00
36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using CartriX.Api.Models;
|
|
|
|
namespace CartriX.Api
|
|
{
|
|
public class AppDbContext : DbContext
|
|
{
|
|
public AppDbContext(DbContextOptions options) : base(options)
|
|
{
|
|
|
|
}
|
|
public DbSet<Printer> Printers { get; set; }
|
|
public DbSet<Cartridge> Cartridges { get; set; }
|
|
|
|
public DbSet<StatusPrinter> StatusPrinters { get; set; }
|
|
public DbSet<StatusCartridge> StatusCartridges { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<Cartridge>()
|
|
.HasOne(c => c.InPrinter)
|
|
.WithMany(p => p.CartridgesHave)
|
|
.HasForeignKey(c => c.InPrinterId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
modelBuilder.Entity<Cartridge>()
|
|
.HasMany(c => c.SupportedPrinterModels)
|
|
.WithMany(p => p.SupportedCartridgeModels)
|
|
.UsingEntity(j => j.ToTable("CartridgeSupportedPrinters"));
|
|
}
|
|
|
|
|
|
}
|
|
} |