using AutobusApi.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace AutobusApi.Infrastructure.Data.Configurations; public class CityConfiguration : EntityBaseConfiguration { public override void Configure(EntityTypeBuilder builder) { base.Configure(builder); builder .ToTable("cities") .HasKey(e => e.Id); builder .Property(c => c.Name) .HasColumnName("name") .HasColumnType("varchar(64)") .IsRequired(); builder .Property(r => r.RegionId) .HasColumnName("region_id") .HasColumnType("int") .IsRequired(); builder .HasOne(c => c.Region) .WithMany(r => r.Cities) .HasForeignKey(c => c.RegionId) .HasConstraintName("fk_cities_regions_regionId") .OnDelete(DeleteBehavior.Cascade); builder .HasMany(c => c.Addresses) .WithOne(a => a.City) .OnDelete(DeleteBehavior.Cascade); } }