autobus-api_old/AutobusApi.Persistence/Contexts/Configurations/RouteAddressConfiguration.cs

50 lines
1.4 KiB
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Persistence.Contexts.Configurations;
public class RouteAddressConfiguration : EntityBaseConfiguration<RouteAddress>
{
public override void Configure(EntityTypeBuilder<RouteAddress> builder)
{
base.Configure(builder);
builder
.ToTable("route_addresses")
.HasKey(e => e.Id);
builder
.Property(ra => ra.Order)
.HasColumnName("order")
.HasColumnType("int")
.IsRequired();
builder
.Property(ra => ra.AddressId)
.HasColumnName("address_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(ra => ra.Address)
.WithMany(a => a.RouteAddresses)
.HasForeignKey(ra => ra.AddressId)
.HasConstraintName("fk_routeAddresses_addresses_addressId")
.OnDelete(DeleteBehavior.Cascade);
builder
.Property(ra => ra.RouteId)
.HasColumnName("route_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(ra => ra.Route)
.WithMany(r => r.RouteAddresses)
.HasForeignKey(ra => ra.RouteId)
.HasConstraintName("fk_routeAddresses_routes_routeId")
.OnDelete(DeleteBehavior.Cascade);
}
}