using back.DataModels; using Microsoft.EntityFrameworkCore; namespace back.persistance.data.relations; public class PersonRelationEstablisher : IRelationEstablisher { public void EstablishRelation(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity.Property(e => e.IsArchived).HasDefaultValue(0); entity.Property(e => e.IsFavorite).HasDefaultValue(0); entity.Property(e => e.IsPublic).HasDefaultValue(1); entity.HasOne(d => d.CreatedByNavigation).WithMany(p => p.Photos) .HasForeignKey(d => d.CreatedBy) .OnDelete(DeleteBehavior.ClientSetNull); entity.HasOne(d => d.Event).WithMany(p => p.Photos).HasForeignKey(d => d.EventId); entity.HasMany(d => d.People).WithMany(p => p.PhotosNavigation) .UsingEntity>( "PhotoPerson", r => r.HasOne().WithMany() .HasForeignKey("PersonId") .OnDelete(DeleteBehavior.ClientSetNull), l => l.HasOne().WithMany() .HasForeignKey("PhotoId") .OnDelete(DeleteBehavior.ClientSetNull), j => { j.HasKey("PhotoId", "PersonId"); j.ToTable("PhotoPersons"); }); entity.HasMany(d => d.Tags).WithMany(p => p.Photos) .UsingEntity>( "PhotoTag", r => r.HasOne().WithMany() .HasForeignKey("TagId") .OnDelete(DeleteBehavior.ClientSetNull), l => l.HasOne().WithMany() .HasForeignKey("PhotoId") .OnDelete(DeleteBehavior.ClientSetNull), j => { j.HasKey("PhotoId", "TagId"); j.ToTable("PhotoTags"); }); entity.HasMany(d => d.Users).WithMany(p => p.Photos) .UsingEntity>( "PhotoUserBuyer", r => r.HasOne().WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.ClientSetNull), l => l.HasOne().WithMany() .HasForeignKey("PhotoId") .OnDelete(DeleteBehavior.ClientSetNull), j => { j.HasKey("PhotoId", "UserId"); j.ToTable("PhotoUserBuyers"); }); }); } }