86 lines
2.4 KiB
C#
86 lines
2.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 EmployeeConfiguration : EntityBaseConfiguration<Employee>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<Employee> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("employees")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(e => e.FisrtName)
|
|
.HasColumnName("first_name")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(e => e.LastName)
|
|
.HasColumnName("last_name")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(e => e.Patronymic)
|
|
.HasColumnName("patronymic")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(e => e.Sex)
|
|
.HasColumnName("sex")
|
|
.HasColumnType("varchar(16)")
|
|
.HasConversion(
|
|
e => e.ToString(),
|
|
s => (Sex)Enum.Parse(typeof(Sex), s)
|
|
)
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(e => e.BirthDate)
|
|
.HasColumnName("birth_date")
|
|
.HasColumnType("date")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(e => e.IdentityId)
|
|
.HasColumnName("identity_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasIndex(e => e.IdentityId)
|
|
.IsUnique();
|
|
|
|
builder
|
|
.Property(e => e.EmployerCompanyId)
|
|
.HasColumnName("employer_company_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(e => e.EmployerCompany)
|
|
.WithMany(c => c.Employees)
|
|
.HasForeignKey(e => e.EmployerCompanyId)
|
|
.HasConstraintName("fk_employees_companies_employerCompanyId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.HasMany(e => e.Documents)
|
|
.WithOne(d => d.Employee)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.HasMany(e => e.Shifts)
|
|
.WithOne(s => s.Employee)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|