using AutobusApi.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace AutobusApi.Infrastructure.Data.Configurations; public class TrainConfiguration : EntityBaseConfiguration { public override void Configure(EntityTypeBuilder builder) { builder .ToTable("trains"); builder .Property(b => b.Number) .HasColumnName("number") .HasColumnType("varchar(8)") .IsRequired(); builder .HasMany(t => t.TrainCarriage) .WithOne(tc => tc.Train) .OnDelete(DeleteBehavior.Cascade); builder .Property(b => b.Id) .HasColumnName("id") .HasColumnType("int") .IsRequired(); builder .HasOne(b => b.Vehicle) .WithOne() .HasForeignKey(b => b.Id) .HasConstraintName("fk_trains_vehicles_id") .OnDelete(DeleteBehavior.Cascade); } }