39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
using AutobusApi.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Persistence.Contexts.Configurations;
|
|
|
|
public class VehicleConfiguration : EntityBaseConfiguration<Vehicle>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<Vehicle> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.UseTptMappingStrategy()
|
|
.ToTable("vehicles")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(v => v.CompanyId)
|
|
.HasColumnName("company_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(v => v.Company)
|
|
.WithMany(c => c.Vehicles)
|
|
.HasForeignKey(v => v.CompanyId)
|
|
.HasConstraintName("fk_vehicles_companies_companyId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.HasMany(v => v.Enrollments)
|
|
.WithOne(ve => ve.Vehicle)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
|
|
}
|
|
}
|