autobus-api_old/AutobusApi.Infrastructure/Data/Configurations/CountryConfiguration.cs

29 lines
763 B
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Infrastructure.Data.Configurations;
public class CountryConfiguration : EntityBaseConfiguration<Country>
{
public override void Configure(EntityTypeBuilder<Country> builder)
{
base.Configure(builder);
builder
.ToTable("countries")
.HasKey(e => e.Id);
builder
.Property(c => c.Name)
.HasColumnName("name")
.HasColumnType("varchar(64)")
.IsRequired();
builder
.HasMany(c => c.Regions)
.WithOne(r => r.Country)
.OnDelete(DeleteBehavior.Cascade);
}
}