From 4357d599e421bac37145eda1b35f687272e29132 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 6 Jul 2020 02:20:05 +0200 Subject: [PATCH] Working on the sortBy --- Kyoo.Common/Controllers/IRepository.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kyoo.Common/Controllers/IRepository.cs b/Kyoo.Common/Controllers/IRepository.cs index 2b2dbd22..f7e45d20 100644 --- a/Kyoo.Common/Controllers/IRepository.cs +++ b/Kyoo.Common/Controllers/IRepository.cs @@ -46,12 +46,14 @@ namespace Kyoo.Controllers string key = sortBy.Contains(':') ? sortBy.Substring(0, sortBy.IndexOf(':')) : sortBy; string order = sortBy.Contains(':') ? sortBy.Substring(sortBy.IndexOf(':') + 1) : null; - - Key = Expression.Lambda>(Expression.Property(Expression.Parameter(typeof(T), "x"), key)); + + ParameterExpression param = Expression.Parameter(typeof(T), "x"); + Key = Expression.Lambda>(Expression.Property(param, key), param); Descendant = order switch { "desc" => true, "asc" => false, + "" => false, _ => throw new ArgumentException($"The sort order, if set, should be :asc or :desc but it was :{order}.") }; }