From 963d6fdd7aff91e3570b40b584cfd24ea0d19517 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Mon, 25 Sep 2023 19:54:55 +0600 Subject: [PATCH 1/3] Fix isNullTranstion which chokes if use ToLower --- .../Translations/IsNullTranslation.fs | 12 +++++++----- .../Translations/IsNullTranslationTests.fs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/EFCore.FSharp/Translations/IsNullTranslation.fs b/src/EFCore.FSharp/Translations/IsNullTranslation.fs index 6b6a51c..2a3ac8e 100644 --- a/src/EFCore.FSharp/Translations/IsNullTranslation.fs +++ b/src/EFCore.FSharp/Translations/IsNullTranslation.fs @@ -9,8 +9,10 @@ let isNullMethodTranslator (sqlExp: ISqlExpressionFactory) = if method.DeclaringType.IsValueType then null else - let expression = arguments |> Seq.head - - match method.Name with - | "IsNull" -> sqlExp.IsNull(expression) :> _ - | _ -> null } + let expression = arguments |> Seq.tryHead + match expression with + | Some expression -> + match method.Name with + | "IsNull" -> sqlExp.IsNull(expression) :> _ + | _ -> null + | None -> null } diff --git a/tests/EFCore.FSharp.Tests/Translations/IsNullTranslationTests.fs b/tests/EFCore.FSharp.Tests/Translations/IsNullTranslationTests.fs index fe63f03..183ff8a 100644 --- a/tests/EFCore.FSharp.Tests/Translations/IsNullTranslationTests.fs +++ b/tests/EFCore.FSharp.Tests/Translations/IsNullTranslationTests.fs @@ -104,6 +104,21 @@ let OptionTranslationQueryTests = headOrDefault } + Expect.equal blog blogWithContent "Record in context should match" + } + + test "Do not break ToLower" { + use ctx = createContext () + saveBlogs ctx + + let blog = + query { + for blog in ctx.Blogs do + where (blog.Content.ToLower() = "some text") + select blog + headOrDefault + } + Expect.equal blog blogWithContent "Record in context should match" } ] From 7be2b83e1bf71064c4fb00a7f7539e76ff70c994 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Mon, 25 Sep 2023 20:01:38 +0600 Subject: [PATCH 2/3] Simplify match --- src/EFCore.FSharp/Translations/IsNullTranslation.fs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/EFCore.FSharp/Translations/IsNullTranslation.fs b/src/EFCore.FSharp/Translations/IsNullTranslation.fs index 2a3ac8e..6b39895 100644 --- a/src/EFCore.FSharp/Translations/IsNullTranslation.fs +++ b/src/EFCore.FSharp/Translations/IsNullTranslation.fs @@ -11,8 +11,7 @@ let isNullMethodTranslator (sqlExp: ISqlExpressionFactory) = else let expression = arguments |> Seq.tryHead match expression with - | Some expression -> - match method.Name with - | "IsNull" -> sqlExp.IsNull(expression) :> _ - | _ -> null - | None -> null } + | Some expression + when method.Name = "IsNull" -> + sqlExp.IsNull(expression) :> _ + | _ -> null } From 7fb18fb99610503291641faaec99c88b9deebf7a Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Mon, 20 Nov 2023 12:14:21 +0600 Subject: [PATCH 3/3] Fix formatting --- src/EFCore.FSharp/Translations/IsNullTranslation.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/EFCore.FSharp/Translations/IsNullTranslation.fs b/src/EFCore.FSharp/Translations/IsNullTranslation.fs index 6b39895..8dba65c 100644 --- a/src/EFCore.FSharp/Translations/IsNullTranslation.fs +++ b/src/EFCore.FSharp/Translations/IsNullTranslation.fs @@ -11,7 +11,5 @@ let isNullMethodTranslator (sqlExp: ISqlExpressionFactory) = else let expression = arguments |> Seq.tryHead match expression with - | Some expression - when method.Name = "IsNull" -> - sqlExp.IsNull(expression) :> _ + | Some expression when method.Name = "IsNull" -> sqlExp.IsNull(expression) :> _ | _ -> null }