66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Nashel.BuildingBlocks.Domain;
|
|
using Nashel.Modules.Identity.Domain.Aggregates;
|
|
using Nashel.Modules.Identity.Domain.Entities;
|
|
|
|
namespace Nashel.Modules.Identity.Infrastructure.Persistence.Configurations;
|
|
|
|
public class UserProfileConfiguration : IEntityTypeConfiguration<UserProfile>
|
|
{
|
|
public void Configure(EntityTypeBuilder<UserProfile> builder)
|
|
{
|
|
builder.ToTable("UserProfiles", "identity");
|
|
|
|
builder.HasKey(x => x.Id);
|
|
|
|
builder.Property(x => x.FirstName)
|
|
.IsRequired()
|
|
.HasMaxLength(100);
|
|
|
|
builder.Property(x => x.LastName)
|
|
.IsRequired()
|
|
.HasMaxLength(100);
|
|
|
|
builder.Property(x => x.Patronymic)
|
|
.HasMaxLength(100);
|
|
|
|
builder.Property(x => x.CompanyName)
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(x => x.Inn)
|
|
.HasMaxLength(10);
|
|
|
|
builder.Property(x => x.Description)
|
|
.HasMaxLength(2048);
|
|
|
|
builder.Property(x => x.AvatarUrl)
|
|
.HasMaxLength(500);
|
|
|
|
// Optional 1:1 relationship with WorkSchedule
|
|
builder.HasOne(x => x.WorkSchedule)
|
|
.WithOne()
|
|
.HasForeignKey<WorkSchedule>(x => x.Id)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
// Many-to-Many relationship with Competencies
|
|
builder.HasMany(x => x.Competencies)
|
|
.WithMany()
|
|
.UsingEntity<Dictionary<string, object>>(
|
|
"UserProfileCompetencies",
|
|
j => j.HasOne<Competency>().WithMany().HasForeignKey("CompetencyId"),
|
|
j => j.HasOne<UserProfile>().WithMany().HasForeignKey("UserProfileId"),
|
|
j =>
|
|
{
|
|
j.ToTable("UserProfileCompetencies", "identity");
|
|
j.HasKey("UserProfileId", "CompetencyId");
|
|
});
|
|
|
|
// 1:1 relationship with Account
|
|
builder.HasOne<Account>()
|
|
.WithOne(x => x.Profile)
|
|
.HasForeignKey<UserProfile>(x => x.Id)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|