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

76 lines
2.0 KiB
C#

using AutobusApi.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Persistence.Contexts.Configurations;
public class BusConfiguration : EntityBaseConfiguration<Bus>
{
public override void Configure(EntityTypeBuilder<Bus> builder)
{
builder
.ToTable("buses");
builder
.Property(b => b.Number)
.HasColumnName("number")
.HasColumnType("varchar(8)")
.IsRequired();
builder
.Property(b => b.Model)
.HasColumnName("model")
.HasColumnType("varchar(64)")
.IsRequired();
builder
.Property(b => b.Capacity)
.HasColumnName("capacity")
.HasColumnType("int")
.IsRequired();
builder
.Property(b => b.HasClimateControl)
.HasColumnName("has_climate_control")
.HasColumnType("boolean")
.IsRequired();
builder
.Property(b => b.HasWC)
.HasColumnName("has_wc")
.HasColumnType("boolean")
.IsRequired();
builder
.Property(b => b.HasWiFi)
.HasColumnName("has_wifi")
.HasColumnType("boolean")
.IsRequired();
builder
.Property(b => b.HasMultimedia)
.HasColumnName("has_multimedia")
.HasColumnType("boolean")
.IsRequired();
builder
.Property(b => b.HasOutlets)
.HasColumnName("has_outlets")
.HasColumnType("boolean")
.IsRequired();
builder
.Property(b => b.Id)
.HasColumnName("id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(b => b.Vehicle)
.WithOne()
.HasForeignKey<Bus>(b => b.Id)
.HasConstraintName("fk_buses_vehicles_id")
.OnDelete(DeleteBehavior.Cascade);
}
}