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

28 lines
742 B
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Infrastructure.Data.Configurations;
public class RouteConfiguration : EntityBaseConfiguration<Route>
{
public override void Configure(EntityTypeBuilder<Route> builder)
{
base.Configure(builder);
builder
.ToTable("routes")
.HasKey(e => e.Id);
builder
.HasMany(r => r.VehicleEnrollments)
.WithOne(ve => ve.Route)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasMany(r => r.RouteAddresses)
.WithOne(ra => ra.Route)
.OnDelete(DeleteBehavior.Cascade);
}
}