Initial Commit
This commit is contained in:
25
OtaFleet.Api/Data/OtaDbContext.cs
Normal file
25
OtaFleet.Api/Data/OtaDbContext.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user