29 lines
929 B
C#
29 lines
929 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using OnProfNext.Shared.Models;
|
|
|
|
namespace OnProfNext.Server.Configurations
|
|
{
|
|
public class ProjectUserConfiguration : IEntityTypeConfiguration<ProjectUser>
|
|
{
|
|
public void Configure(EntityTypeBuilder<ProjectUser> entity)
|
|
{
|
|
entity.ToTable("ProjectUsers");
|
|
|
|
// Composite Primary Key
|
|
entity.HasKey(pu => new { pu.ProjectId, pu.UserId });
|
|
|
|
entity.HasOne(pu => pu.Project)
|
|
.WithMany(p => p.ProjectUsers)
|
|
.HasForeignKey(pu => pu.ProjectId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
entity.HasOne(pu => pu.User)
|
|
.WithMany(u => u.ProjectUsers)
|
|
.HasForeignKey(pu => pu.UserId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|
|
}
|
|
|