aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/LinkedChildConfiguration.cs
blob: 2abccd41f003e60a786a3a3f0cfad7d3be0b4b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Jellyfin.Database.Implementations.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Jellyfin.Database.Implementations.ModelConfiguration;

/// <summary>
/// LinkedChildEntity configuration.
/// </summary>
public class LinkedChildConfiguration : IEntityTypeConfiguration<LinkedChildEntity>
{
    /// <inheritdoc/>
    public void Configure(EntityTypeBuilder<LinkedChildEntity> builder)
    {
        builder.ToTable("LinkedChildren");
        builder.HasKey(e => new { e.ParentId, e.ChildId });
        builder.HasIndex(e => new { e.ParentId, e.SortOrder });
        builder.HasIndex(e => new { e.ParentId, e.ChildType });
        builder.HasIndex(e => new { e.ChildId, e.ChildType });

        builder.HasOne(e => e.Parent)
            .WithMany(e => e.LinkedChildEntities)
            .HasForeignKey(e => e.ParentId)
            .OnDelete(DeleteBehavior.NoAction);

        builder.HasOne(e => e.Child)
            .WithMany(e => e.LinkedChildOfEntities)
            .HasForeignKey(e => e.ChildId)
            .OnDelete(DeleteBehavior.NoAction);
    }
}