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

42 lines
1.1 KiB
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Persistence.Contexts.Configurations;
public class CityConfiguration : EntityBaseConfiguration<City>
{
public override void Configure(EntityTypeBuilder<City> 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);
}
}