58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using AutobusApi.Domain.Entities;
|
|
using AutobusApi.Domain.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Persistence.Contexts.Configurations;
|
|
|
|
public class CarriageConfiguration : EntityBaseConfiguration<Carriage>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<Carriage> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("carriages")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(b => b.Type)
|
|
.HasColumnName("type")
|
|
.HasColumnType("varchar(16)")
|
|
.HasConversion(
|
|
e => e.ToString(),
|
|
s => (CarriageType)Enum.Parse(typeof(CarriageType), s)
|
|
)
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(b => b.Capacity)
|
|
.HasColumnName("capacity")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(b => b.Number)
|
|
.HasColumnName("number")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(b => b.HasWiFi)
|
|
.HasColumnName("has_wifi")
|
|
.HasColumnType("boolean")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(b => b.HasOutlets)
|
|
.HasColumnName("has_outlets")
|
|
.HasColumnType("boolean")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasMany(c => c.TrainCarriage)
|
|
.WithOne(tc => tc.Carriage)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|