#region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; #endregion namespace Lumina.DataAccess.Common.Configuration; /// /// Configures the entity mapping for the entity. /// public class LibraryScanResultConfiguration : IEntityTypeConfiguration { /// /// Configures the entity. /// /// The builder to be used to configure the entity. public void Configure(EntityTypeBuilder builder) { builder.ToTable("LibraryScanResults"); // composite key for efficient scan-specific lookups (paths are enforced as UNIQUE within the same scan) builder.HasKey(libraryScanResult => new { libraryScanResult.LibraryScanId, libraryScanResult.Path }); // one library scan with many library scan results builder.HasOne(libraryScanResult => libraryScanResult.LibraryScan) .WithMany(libraryScan => libraryScan.LibraryScanResults) .HasForeignKey(libraryScanResult => libraryScanResult.LibraryScanId) .IsRequired() .OnDelete(DeleteBehavior.Cascade); builder.Property(libraryScanResult => libraryScanResult.Id) .ValueGeneratedNever() .HasColumnOrder(0); builder.Property(libraryScanResult => libraryScanResult.Path) .HasMaxLength(1024) .IsRequired() .HasColumnOrder(1); builder.Property(libraryScanResult => libraryScanResult.ContentHash) .HasMaxLength(24) // xxHash128 as Base64 .IsRequired() .HasColumnOrder(2); builder.Property(libraryScanResult => libraryScanResult.FileSize) .IsRequired() .HasColumnOrder(3); builder.Property(libraryScanResult => libraryScanResult.Ticks) .IsRequired() .HasColumnOrder(4); builder.Property(libraryScanResult => libraryScanResult.Status) .IsRequired() .HasConversion() .HasMaxLength(10) .HasColumnOrder(5); // Indexes builder.HasIndex(libraryScanResult => new { libraryScanResult.ContentHash, libraryScanResult.FileSize, libraryScanResult.Path }); builder.HasIndex(libraryScanResult => libraryScanResult.Path); } }