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

39 lines
1.0 KiB
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Persistence.Contexts.Configurations;
public class TrainConfiguration : EntityBaseConfiguration<Train>
{
public override void Configure(EntityTypeBuilder<Train> 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<Train>(b => b.Id)
.HasConstraintName("fk_trains_vehicles_id")
.OnDelete(DeleteBehavior.Cascade);
}
}