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

44 lines
1.3 KiB
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Persistence.Contexts.Configurations;
public class TrainCarriageConfiguration : EntityBaseConfiguration<TrainCarriage>
{
public override void Configure(EntityTypeBuilder<TrainCarriage> builder)
{
base.Configure(builder);
builder
.ToTable("train_carriages")
.HasKey(e => e.Id);
builder
.Property(b => b.TrainId)
.HasColumnName("train_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(tc => tc.Train)
.WithMany(t => t.TrainCarriage)
.HasForeignKey(tc => tc.TrainId)
.HasConstraintName("fk_trainCarriages_trains_trainId")
.OnDelete(DeleteBehavior.Cascade);
builder
.Property(b => b.CarriageId)
.HasColumnName("carriage_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(tc => tc.Carriage)
.WithMany(c => c.TrainCarriage)
.HasForeignKey(tc => tc.TrainId)
.HasConstraintName("fk_trainCarriages_trains_carriageId")
.OnDelete(DeleteBehavior.Cascade);
}
}