From 5c9b85972d1ab2ee2651acd4179de95826040ccb Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 14 May 2020 21:37:35 +0100 Subject: [PATCH] Fixed: SQL error searching for movie by name --- .../Datastore/WhereBuilderFixture.cs | 10 ++++++++++ src/NzbDrone.Core/Datastore/WhereBuilder.cs | 2 +- src/NzbDrone.Core/Movies/MovieRepository.cs | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/Datastore/WhereBuilderFixture.cs b/src/NzbDrone.Core.Test/Datastore/WhereBuilderFixture.cs index 1d6b6cb3f..b1cccc8d5 100644 --- a/src/NzbDrone.Core.Test/Datastore/WhereBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/WhereBuilderFixture.cs @@ -169,6 +169,16 @@ public void where_in_list_2() _subject.ToString().Should().Be($"((\"Movies\".\"CleanTitle\" = @Clause1_P1) AND (\"Movies\".\"Id\" IN (1, 2, 3)))"); } + [Test] + public void where_in_string_list() + { + var list = new List { "first", "second", "third" }; + + _subject = Where(x => list.Contains(x.CleanTitle)); + + _subject.ToString().Should().Be($"(\"Movies\".\"CleanTitle\" IN @Clause1_P1)"); + } + [Test] public void enum_as_int() { diff --git a/src/NzbDrone.Core/Datastore/WhereBuilder.cs b/src/NzbDrone.Core/Datastore/WhereBuilder.cs index e42d0e990..e1b6fb7f9 100644 --- a/src/NzbDrone.Core/Datastore/WhereBuilder.cs +++ b/src/NzbDrone.Core/Datastore/WhereBuilder.cs @@ -275,7 +275,7 @@ private void ParseContainsExpression(MethodCallExpression expression) { var list = expression.Object; - if (list != null && (list.Type == typeof(string) || list.Type == typeof(List))) + if (list != null && (list.Type == typeof(string))) { ParseStringContains(expression); return; diff --git a/src/NzbDrone.Core/Movies/MovieRepository.cs b/src/NzbDrone.Core/Movies/MovieRepository.cs index 03f55de70..b53a9458d 100644 --- a/src/NzbDrone.Core/Movies/MovieRepository.cs +++ b/src/NzbDrone.Core/Movies/MovieRepository.cs @@ -101,8 +101,9 @@ public bool MoviePathExists(string path) public List FindByTitles(List titles) { - return Query(Builder().OrWhere(x => titles.Contains(x.CleanTitle)) - .OrWhere(x => titles.Contains(x.CleanTitle))); + var distinct = titles.Distinct().ToList(); + return Query(Builder().OrWhere(x => distinct.Contains(x.CleanTitle)) + .OrWhere(x => distinct.Contains(x.CleanTitle))); } public List FindByTitleInexact(string cleanTitle)