#region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; #endregion namespace Lumina.DataAccess.Common.Configuration; /// /// Configures the entity mapping for the entity. /// public class LibraryScanConfiguration : IEntityTypeConfiguration { /// /// Configures the entity. /// /// The builder to be used to configure the entity. public void Configure(EntityTypeBuilder builder) { builder.ToTable("LibraryScans"); builder.HasKey(library => library.Id); builder.Property(library => library.Id) .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it .HasColumnOrder(0); // one user with many library scans builder.HasOne(libraryScan => libraryScan.User) .WithMany(user => user.LibraryScans) .HasForeignKey(libraryScan => libraryScan.UserId) .IsRequired(); // one library with many library scans builder.HasOne(libraryScan => libraryScan.Library) .WithMany(library => library.LibraryScans) .HasForeignKey(libraryScan => libraryScan.LibraryId) .IsRequired(); builder.Property(libraryScan => libraryScan.Status) .IsRequired() .HasConversion() .HasColumnOrder(1); // audit builder.Property(permission => permission.CreatedOnUtc) .IsRequired() .HasColumnOrder(2); builder.Property(permission => permission.CreatedBy) .IsRequired() .HasColumnOrder(3); builder.Property(permission => permission.UpdatedOnUtc) .HasDefaultValue(null) .HasColumnOrder(4); builder.Property(permission => permission.UpdatedBy) .HasDefaultValue(null) .HasColumnOrder(5); } }