Files
Backend-Api/AccountMangement.Infrastructure.EFCore/Mappings/SubAccountRoleMapping.cs
2025-05-30 18:03:47 +03:30

31 lines
1.1 KiB
C#

using AccountManagement.Domain.SubAccountRoleAgg;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AccountMangement.Infrastructure.EFCore.Mappings
{
public class SubAccountRoleMapping : IEntityTypeConfiguration<SubAccountRole>
{
public void Configure(EntityTypeBuilder<SubAccountRole> builder)
{
builder.ToTable("SubAccountRoles");
builder.HasKey(x => x.id);
builder.Property(x => x.Title).HasMaxLength(60);
builder.HasMany(x => x.SubAccounts).WithOne(x => x.SubAccountRole).HasForeignKey(x => x.SubAccountRoleId);
builder.OwnsMany(x => x.RolePermissions, opt =>
{
opt.ToTable("SubAccountRolePermissions");
opt.HasKey(x => x.id);
opt.WithOwner(x => x.SubAccountRole);
});
builder.OwnsMany(x => x.RoleWorkshops, roleWorkshop =>
{
roleWorkshop.WithOwner(x => x.SubAccountRole).HasForeignKey(x => x.SubAccountId);
});
}
}
}