AncestorIdConfiguration.cs 751 B

123456789101112131415161718192021
  1. using System;
  2. using Jellyfin.Data.Entities;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  5. namespace Jellyfin.Server.Implementations.ModelConfiguration;
  6. /// <summary>
  7. /// AncestorId configuration.
  8. /// </summary>
  9. public class AncestorIdConfiguration : IEntityTypeConfiguration<AncestorId>
  10. {
  11. /// <inheritdoc/>
  12. public void Configure(EntityTypeBuilder<AncestorId> builder)
  13. {
  14. builder.HasKey(e => new { e.ItemId, e.ParentItemId });
  15. builder.HasIndex(e => e.ParentItemId);
  16. builder.HasOne(e => e.ParentItem).WithMany(e => e.ParentAncestors).HasForeignKey(f => f.ParentItemId);
  17. builder.HasOne(e => e.Item).WithMany(e => e.Children).HasForeignKey(f => f.ItemId);
  18. }
  19. }