using AutobusApi.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace AutobusApi.Infrastructure.Data.Configurations; public class RegionConfiguration : EntityBaseConfiguration { public override void Configure(EntityTypeBuilder builder) { base.Configure(builder); builder .ToTable("regions") .HasKey(e => e.Id); builder .Property(r => r.Name) .HasColumnName("name") .HasColumnType("varchar(64)") .IsRequired(); builder .Property(r => r.CountryId) .HasColumnName("country_id") .HasColumnType("int") .IsRequired(); builder .HasOne(r => r.Country) .WithMany(c => c.Regions) .HasForeignKey(r => r.CountryId) .HasConstraintName("fk_regions_coutries_countryId") .OnDelete(DeleteBehavior.Cascade); builder .HasMany(r => r.Cities) .WithOne(c => c.Region) .OnDelete(DeleteBehavior.Cascade); } }