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

48 lines
1.4 KiB
C#

using AutobusApi.Domain.Entities;
using AutobusApi.Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AutobusApi.Infrastructure.Data.Configurations;
public class EmployeeDocumentConfiguration : EntityBaseConfiguration<EmployeeDocument>
{
public override void Configure(EntityTypeBuilder<EmployeeDocument> builder)
{
base.Configure(builder);
builder
.ToTable("employee_documents")
.HasKey(e => e.Id);
builder
.Property(ed => ed.Type)
.HasColumnName("type")
.HasColumnType("varchar(32)")
.HasConversion(
e => e.ToString(),
s => (EmployeeDocumentType)Enum.Parse(typeof(EmployeeDocumentType), s)
)
.IsRequired();
builder
.Property(ed => ed.Information)
.HasColumnName("information")
.HasColumnType("varchar(256)")
.IsRequired();
builder
.Property(ed => ed.EmployeeId)
.HasColumnName("employee_id")
.HasColumnType("int")
.IsRequired();
builder
.HasOne(ed => ed.Employee)
.WithMany(e => e.Documents)
.HasForeignKey(ed => ed.EmployeeId)
.HasConstraintName("fk_employeeDocuments_employees_employeeId")
.OnDelete(DeleteBehavior.Cascade);
}
}