From f5f0a8bb6157f4ae6478b128db03bb78b4b12da0 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 8 Feb 2020 16:25:24 +0100 Subject: [PATCH] Fixing a bug with libraries link --- Kyoo/Controllers/LibraryManager.cs | 11 +++++++++-- Kyoo/Startup.cs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index c28e7d02..127555f7 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -2,6 +2,7 @@ using Kyoo.Models.Watch; using System.Collections.Generic; using System.Linq; +using Microsoft.EntityFrameworkCore; namespace Kyoo.Controllers { @@ -194,8 +195,14 @@ namespace Kyoo.Controllers public IEnumerable GetShowsInLibrary(long libraryID) { - return (from link in _database.LibraryLinks where link.LibraryID == libraryID select link).AsEnumerable() - .Select(link => link.Show ?? link.Collection.AsShow()) + return (from link in _database.LibraryLinks where link.LibraryID == libraryID select link) + .AsEnumerable() + .Select(link => + { + _database.Entry(link).Reference(l => l.Show).Load(); + _database.Entry(link).Reference(l => l.Collection).Load(); + return link.Show ?? link.Collection.AsShow(); + }) .OrderBy(x => x.Title); } diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index b8e88e24..128835fd 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -33,13 +33,13 @@ namespace Kyoo services.AddControllers().AddNewtonsoftJson(); services.AddHttpClient(); - services.AddDbContext(options => options.UseSqlite(Configuration.GetConnectionString("Database")), ServiceLifetime.Singleton); + services.AddDbContext(options => options.UseSqlite(Configuration.GetConnectionString("Database"))); // services.AddIdentity() // .AddEntityFrameworkStores() // services.AddIdentityServer(); - services.AddSingleton(); + services.AddScoped(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton();