mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fixing the loader
This commit is contained in:
parent
3e0c0db79c
commit
56c7339816
@ -65,6 +65,10 @@ namespace Kyoo.Controllers
|
||||
where T : class, IResource
|
||||
where T2 : class;
|
||||
|
||||
Task Load<T, T2>([NotNull] T obj, Expression<Func<T, IEnumerable<T2>>> member)
|
||||
where T : class, IResource
|
||||
where T2 : class;
|
||||
|
||||
// Library Items relations
|
||||
Task<ICollection<LibraryItem>> GetItemsFromLibrary(int id,
|
||||
Expression<Func<LibraryItem, bool>> where = null,
|
||||
|
@ -239,7 +239,15 @@ namespace Kyoo.Controllers
|
||||
where T : class, IResource
|
||||
where T2 : class
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
// TODO figure out why setting this method as abstract prevent the app from loading this assembly.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual Task Load<T, T2>(T obj, Expression<Func<T, IEnumerable<T2>>> member)
|
||||
where T : class, IResource
|
||||
where T2 : class
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ICollection<Library>> GetLibraries(Expression<Func<Library, bool>> where = null,
|
||||
|
@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Kyoo.Controllers
|
||||
{
|
||||
@ -39,22 +37,22 @@ namespace Kyoo.Controllers
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public override Task Load<T, T2>(T obj, Expression<Func<T, IEnumerable<T2>>> member)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
if (!Utility.IsPropertyExpression(member) || member == null)
|
||||
throw new ArgumentException($"{nameof(member)} is not a property.");
|
||||
return _database.Entry(obj).Collection(member).LoadAsync();
|
||||
}
|
||||
|
||||
public override Task Load<T, T2>(T obj, Expression<Func<T, T2>> member)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
if (!Utility.IsPropertyExpression(member) || member == null)
|
||||
throw new ArgumentException($"{nameof(member)} is not a property.");
|
||||
|
||||
EntityEntry<T> entry = _database.Entry(obj);
|
||||
|
||||
if (!typeof(IEnumerable).IsAssignableFrom(typeof(T2)))
|
||||
return entry.Reference(member).LoadAsync();
|
||||
|
||||
// TODO This is totally the wrong thing. We should run entry.Collection<T>(collectionMember).LoadAsync()
|
||||
// TODO where collectionMember would be member with T2 replaced by it's inner type (IEnumerable<T3>)
|
||||
Type collectionType = Utility.GetGenericDefinition(typeof(T2), typeof(IEnumerable<>));
|
||||
return Utility.RunGenericMethod<CollectionEntry>(entry, "Collection", collectionType, member).LoadAsync();
|
||||
return _database.Entry(obj).Reference(member).LoadAsync();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user