autobus-api_old/AutobusApi.Infrastructure/Data/Configurations/VehicleEnrollmentConfiguration.cs

70 lines
2.1 KiB
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Infrastructure.Data.Configurations;
public class VehicleEnrollmentConfiguration : EntityBaseConfiguration<VehicleEnrollment>
{
public override void Configure(EntityTypeBuilder<VehicleEnrollment> builder)
{
base.Configure(builder);
builder
.ToTable("vehicle_enrollments")
.HasKey(e => e.Id);
builder
.Property(ve => ve.DepartureDateTimeUtc)
.HasColumnName("departure_timestamp_utc")
.HasColumnType("timestamptz")
.IsRequired();
builder
.Property(ve => ve.RouteId)
.HasColumnName("route_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(ve => ve.Route)
.WithMany(r => r.VehicleEnrollments)
.HasForeignKey(ve => ve.RouteId)
.HasConstraintName("fk_vehicleEnrollments_routes_routeId")
.OnDelete(DeleteBehavior.Cascade);
builder
.Property(ve => ve.VehicleId)
.HasColumnName("vehicle_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(ve => ve.Vehicle)
.WithMany(v => v.Enrollments)
.HasForeignKey(ve => ve.VehicleId)
.HasConstraintName("fk_vehicleEnrollments_vehicles_vehicleId")
.OnDelete(DeleteBehavior.Cascade);
builder
.HasMany(ve => ve.RouteAddressDetails)
.WithOne(rad => rad.VehicleEnrollment)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasMany(ve => ve.Tickets)
.WithOne(t => t.VehicleEnrollment)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasMany(ve => ve.Crew)
.WithOne(c => c.VehicleEnrollment)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasMany(ve => ve.Reviews)
.WithOne(r => r.VehicleEnrollment)
.OnDelete(DeleteBehavior.Cascade);
}
}