26 lines
829 B
C#
26 lines
829 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using OtaFleet.Api.Data.Entities;
|
|
|
|
namespace OtaFleet.Api.Data;
|
|
|
|
public class OtaDbContext : DbContext
|
|
{
|
|
public OtaDbContext(DbContextOptions<OtaDbContext> options) : base(options) { }
|
|
|
|
public DbSet<Vehicle> Vehicles => Set<Vehicle>();
|
|
public DbSet<VehicleGroup> VehicleGroups => Set<VehicleGroup>();
|
|
public DbSet<FirmwareUpdate> FirmwareUpdates => Set<FirmwareUpdate>();
|
|
public DbSet<Deployment> Deployments => Set<Deployment>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<Vehicle>()
|
|
.HasOne(v => v.Group)
|
|
.WithMany(g => g.Vehicles)
|
|
.HasForeignKey(v => v.GroupId)
|
|
.OnDelete(DeleteBehavior.SetNull);
|
|
}
|
|
}
|