Context Load Navigations and Collections

This commit is contained in:
2025-07-21 12:24:54 +02:00
parent 93d3878b07
commit f2bc48bc52
10 changed files with 91 additions and 14 deletions

View File

@@ -4,7 +4,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Newtonsoft.Json;
namespace API.Schema.MangaContext;
@@ -15,8 +14,7 @@ public class Chapter : Identifiable, IComparable<Chapter>
[StringLength(64)] [Required] public string ParentMangaId { get; init; } = null!;
[JsonIgnore] public Manga ParentManga = null!;
[NotMapped]
public Dictionary<string, string> IdsOnMangaConnectors =>
[NotMapped] public Dictionary<string, string> IdsOnMangaConnectors =>
MangaConnectorIds.ToDictionary(id => id.MangaConnectorName, id => id.IdOnConnectorSite);
[JsonIgnore] public ICollection<MangaConnectorId<Chapter>> MangaConnectorIds = null!;

View File

@@ -20,9 +20,9 @@ public class Manga : Identifiable
[StringLength(64)] public string? LibraryId { get; private set; }
[JsonIgnore] public FileLibrary? Library = null!;
public ICollection<Author> Authors { get; internal set; }= null!;
public ICollection<MangaTag> MangaTags { get; internal set; }= null!;
public ICollection<Link> Links { get; internal set; }= null!;
public ICollection<Author> Authors { get; internal set; } = null!;
public ICollection<MangaTag> MangaTags { get; internal set; } = null!;
public ICollection<Link> Links { get; internal set; } = null!;
public ICollection<AltTitle> AltTitles { get; internal set; } = null!;
[Required] public float IgnoreChaptersBefore { get; internal set; }
[StringLength(1024)] [Required] public string DirectoryName { get; private set; }

View File

@@ -1,6 +1,7 @@
using System.Text.RegularExpressions;
using JikanDotNet;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace API.Schema.MangaContext.MetadataFetchers;
@@ -47,6 +48,11 @@ public class MyAnimeList : MetadataFetcher
public override void UpdateMetadata(MetadataEntry metadataEntry, MangaContext dbContext)
{
Manga dbManga = dbContext.Mangas.Find(metadataEntry.MangaId)!;
foreach (CollectionEntry collectionEntry in dbContext.Entry(dbManga).Collections)
collectionEntry.Load();
dbContext.Entry(dbManga).Navigation(nameof(Manga.Library)).Load();
MangaFull resultData;
try
{