From afb93ef0989f4a5c88a4a2969759e35cff9e1ca5 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sat, 21 Mar 2020 13:54:11 +0100 Subject: [PATCH] Remove client code for all EF.Functions Also switched to the EF Core standard error message for client-side evaluation. Closes #1312 --- ...qlFuzzyStringMatchDbFunctionsExtensions.cs | 37 +++-- ...qlNetTopologySuiteDbFunctionsExtensions.cs | 3 +- .../NpgsqlTrigramsDbFunctionsExtensions.cs | 57 +++---- .../Extensions/NpgsqlDbFunctionsExtensions.cs | 94 +---------- ...gsqlFullTextSearchDbFunctionsExtensions.cs | 44 ++--- .../NpgsqlFullTextSearchLinqExtensions.cs | 143 ++++++++-------- .../NpgsqlJsonDbFunctionsExtensions.cs | 17 +- ... => NpgsqlNetworkDbFunctionsExtensions.cs} | 155 ++++++++---------- ...cs => NpgsqlRangeDbFunctionsExtensions.cs} | 57 ++++--- .../Internal/NpgsqlNetworkTranslator.cs | 64 ++++---- .../Internal/NpgsqlRangeTranslator.cs | 30 ++-- .../Query/FromSqlQueryNpgsqlTest.cs | 28 +++- .../FullTextSearchDbFunctionsNpgsqlTest.cs | 2 +- .../Query/NavigationTest.cs | 8 +- .../NorthwindMiscellaneousQueryNpgsqlTest.cs | 42 +++-- test/EFCore.PG.Tests/NpgsqlDbFunctionsTest.cs | 23 --- 16 files changed, 356 insertions(+), 448 deletions(-) rename src/EFCore.PG/Extensions/{NpgsqlNetworkExtensions.cs => NpgsqlNetworkDbFunctionsExtensions.cs} (87%) rename src/EFCore.PG/Extensions/{NpgsqlRangeExtensions.cs => NpgsqlRangeDbFunctionsExtensions.cs} (84%) delete mode 100644 test/EFCore.PG.Tests/NpgsqlDbFunctionsTest.cs diff --git a/src/EFCore.PG.FuzzyStringMatch/Extensions/NpgsqlFuzzyStringMatchDbFunctionsExtensions.cs b/src/EFCore.PG.FuzzyStringMatch/Extensions/NpgsqlFuzzyStringMatchDbFunctionsExtensions.cs index e5f184061..265193792 100644 --- a/src/EFCore.PG.FuzzyStringMatch/Extensions/NpgsqlFuzzyStringMatchDbFunctionsExtensions.cs +++ b/src/EFCore.PG.FuzzyStringMatch/Extensions/NpgsqlFuzzyStringMatchDbFunctionsExtensions.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore { @@ -12,8 +13,8 @@ public static class NpgsqlFuzzyStringMatchDbFunctionsExtensions /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static string FuzzyStringMatchSoundex(this DbFunctions _, string text) => - throw new NotSupportedException(); + public static string FuzzyStringMatchSoundex(this DbFunctions _, string text) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchSoundex))); /// /// The difference function converts two strings to their Soundex codes and @@ -26,8 +27,8 @@ public static string FuzzyStringMatchSoundex(this DbFunctions _, string text) => /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static int FuzzyStringMatchDifference(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static int FuzzyStringMatchDifference(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchDifference))); /// /// Returns the Levenshtein distance between two strings. @@ -37,8 +38,8 @@ public static int FuzzyStringMatchDifference(this DbFunctions _, string source, /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static int FuzzyStringMatchLevenshtein(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static int FuzzyStringMatchLevenshtein(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchLevenshtein))); /// /// Returns the Levenshtein distance between two strings. @@ -48,8 +49,8 @@ public static int FuzzyStringMatchLevenshtein(this DbFunctions _, string source, /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static int FuzzyStringMatchLevenshtein(this DbFunctions _, string source, string target, int insertionCost, int deletionCost, int substitutionCost) => - throw new NotSupportedException(); + public static int FuzzyStringMatchLevenshtein(this DbFunctions _, string source, string target, int insertionCost, int deletionCost, int substitutionCost) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchLevenshtein))); /// /// levenshtein_less_equal is an accelerated version of the Levenshtein function for use when only small distances are of interest. @@ -61,8 +62,8 @@ public static int FuzzyStringMatchLevenshtein(this DbFunctions _, string source, /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static int FuzzyStringMatchLevenshteinLessEqual(this DbFunctions _, string source, string target, int maximumDistance) => - throw new NotSupportedException(); + public static int FuzzyStringMatchLevenshteinLessEqual(this DbFunctions _, string source, string target, int maximumDistance) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchLevenshteinLessEqual))); /// /// levenshtein_less_equal is an accelerated version of the Levenshtein function for use when only small distances are of interest. @@ -74,8 +75,8 @@ public static int FuzzyStringMatchLevenshteinLessEqual(this DbFunctions _, strin /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static int FuzzyStringMatchLevenshteinLessEqual(this DbFunctions _, string source, string target, int insertionCost, int deletionCost, int substitutionCost, int maximumDistance) => - throw new NotSupportedException(); + public static int FuzzyStringMatchLevenshteinLessEqual(this DbFunctions _, string source, string target, int insertionCost, int deletionCost, int substitutionCost, int maximumDistance) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchLevenshteinLessEqual))); /// /// The metaphone function converts a string to its Metaphone code. @@ -85,8 +86,8 @@ public static int FuzzyStringMatchLevenshteinLessEqual(this DbFunctions _, strin /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static string FuzzyStringMatchMetaphone(this DbFunctions _, string text, int maximumOutputLength) => - throw new NotSupportedException(); + public static string FuzzyStringMatchMetaphone(this DbFunctions _, string text, int maximumOutputLength) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchMetaphone))); /// /// The dmetaphone function converts a string to its primary Double Metaphone code. @@ -96,8 +97,8 @@ public static string FuzzyStringMatchMetaphone(this DbFunctions _, string text, /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static string FuzzyStringMatchDoubleMetaphone(this DbFunctions _, string text) => - throw new NotSupportedException(); + public static string FuzzyStringMatchDoubleMetaphone(this DbFunctions _, string text) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchDoubleMetaphone))); /// /// The dmetaphone_alt function converts a string to its alternate Double Metaphone code. @@ -107,7 +108,7 @@ public static string FuzzyStringMatchDoubleMetaphone(this DbFunctions _, string /// /// See https://www.postgresql.org/docs/current/fuzzystrmatch.html. /// - public static string FuzzyStringMatchDoubleMetaphoneAlt(this DbFunctions _, string text) => - throw new NotSupportedException(); + public static string FuzzyStringMatchDoubleMetaphoneAlt(this DbFunctions _, string text) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FuzzyStringMatchDoubleMetaphoneAlt))); } } diff --git a/src/EFCore.PG.NTS/Extensions/NpgsqlNetTopologySuiteDbFunctionsExtensions.cs b/src/EFCore.PG.NTS/Extensions/NpgsqlNetTopologySuiteDbFunctionsExtensions.cs index b8ba3af9b..7974bb660 100644 --- a/src/EFCore.PG.NTS/Extensions/NpgsqlNetTopologySuiteDbFunctionsExtensions.cs +++ b/src/EFCore.PG.NTS/Extensions/NpgsqlNetTopologySuiteDbFunctionsExtensions.cs @@ -1,5 +1,6 @@ using NetTopologySuite.Geometries; using System; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore { @@ -15,6 +16,6 @@ public static class NpgsqlNetTopologySuiteDbFunctionsExtensions /// public static TGeometry Transform(this DbFunctions _, TGeometry geometry, int srid) where TGeometry : Geometry - => throw new NotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Transform))); } } diff --git a/src/EFCore.PG.Trigrams/Extensions/NpgsqlTrigramsDbFunctionsExtensions.cs b/src/EFCore.PG.Trigrams/Extensions/NpgsqlTrigramsDbFunctionsExtensions.cs index cede9277b..850640876 100644 --- a/src/EFCore.PG.Trigrams/Extensions/NpgsqlTrigramsDbFunctionsExtensions.cs +++ b/src/EFCore.PG.Trigrams/Extensions/NpgsqlTrigramsDbFunctionsExtensions.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore { @@ -13,8 +14,8 @@ public static class NpgsqlTrigramsDbFunctionsExtensions /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static string[] TrigramsShow(this DbFunctions _, string text) => - throw new NotSupportedException(); + public static string[] TrigramsShow(this DbFunctions _, string text) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsShow))); /// /// Returns a number that indicates how similar the two arguments are. @@ -26,8 +27,8 @@ public static string[] TrigramsShow(this DbFunctions _, string text) => /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsSimilarity(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsSimilarity(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsSimilarity))); /// /// Returns a number that indicates the greatest similarity between the set of trigrams @@ -39,8 +40,8 @@ public static double TrigramsSimilarity(this DbFunctions _, string source, strin /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsWordSimilarity(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsWordSimilarity(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsWordSimilarity))); /// /// Same as word_similarity(text, text), but forces extent boundaries to match word boundaries. @@ -52,8 +53,8 @@ public static double TrigramsWordSimilarity(this DbFunctions _, string source, s /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsStrictWordSimilarity(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsStrictWordSimilarity(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsStrictWordSimilarity))); /// /// Returns true if its arguments have a similarity that is greater than the current similarity @@ -64,8 +65,8 @@ public static double TrigramsStrictWordSimilarity(this DbFunctions _, string sou /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static bool TrigramsAreSimilar(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static bool TrigramsAreSimilar(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsAreSimilar))); /// /// Returns true if the similarity between the trigram set in the first argument and a continuous @@ -77,8 +78,8 @@ public static bool TrigramsAreSimilar(this DbFunctions _, string source, string /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static bool TrigramsAreWordSimilar(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static bool TrigramsAreWordSimilar(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsAreWordSimilar))); /// /// Commutator of the <% operator. @@ -88,8 +89,8 @@ public static bool TrigramsAreWordSimilar(this DbFunctions _, string source, str /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static bool TrigramsAreNotWordSimilar(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static bool TrigramsAreNotWordSimilar(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsAreNotWordSimilar))); /// /// Returns true if its second argument has a continuous extent of an ordered trigram set that @@ -102,8 +103,8 @@ public static bool TrigramsAreNotWordSimilar(this DbFunctions _, string source, /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static bool TrigramsAreStrictWordSimilar(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static bool TrigramsAreStrictWordSimilar(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsAreStrictWordSimilar))); /// /// Commutator of the <<% operator. @@ -113,8 +114,8 @@ public static bool TrigramsAreStrictWordSimilar(this DbFunctions _, string sourc /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static bool TrigramsAreNotStrictWordSimilar(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static bool TrigramsAreNotStrictWordSimilar(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsAreNotStrictWordSimilar))); /// /// Returns the "distance" between the arguments, that is one minus the similarity() value. @@ -124,8 +125,8 @@ public static bool TrigramsAreNotStrictWordSimilar(this DbFunctions _, string so /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsSimilarityDistance(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsSimilarityDistance(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsSimilarityDistance))); /// /// Returns the "distance" between the arguments, that is one minus the word_similarity() value. @@ -135,8 +136,8 @@ public static double TrigramsSimilarityDistance(this DbFunctions _, string sourc /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsWordSimilarityDistance(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsWordSimilarityDistance(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsWordSimilarityDistance))); /// /// Commutator of the <<-> operator. @@ -146,8 +147,8 @@ public static double TrigramsWordSimilarityDistance(this DbFunctions _, string s /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsWordSimilarityDistanceInverted(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsWordSimilarityDistanceInverted(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsWordSimilarityDistanceInverted))); /// /// Returns the "distance" between the arguments, that is one minus the strict_word_similarity() value. @@ -157,8 +158,8 @@ public static double TrigramsWordSimilarityDistanceInverted(this DbFunctions _, /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsStrictWordSimilarityDistance(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsStrictWordSimilarityDistance(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsStrictWordSimilarityDistance))); /// /// Commutator of the <<<-> operator. @@ -168,7 +169,7 @@ public static double TrigramsStrictWordSimilarityDistance(this DbFunctions _, st /// /// See https://www.postgresql.org/docs/current/pgtrgm.html. /// - public static double TrigramsStrictWordSimilarityDistanceInverted(this DbFunctions _, string source, string target) => - throw new NotSupportedException(); + public static double TrigramsStrictWordSimilarityDistanceInverted(this DbFunctions _, string source, string target) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(TrigramsStrictWordSimilarityDistanceInverted))); } } diff --git a/src/EFCore.PG/Extensions/NpgsqlDbFunctionsExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlDbFunctionsExtensions.cs index d7f5cbf31..c2ba628d5 100644 --- a/src/EFCore.PG/Extensions/NpgsqlDbFunctionsExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlDbFunctionsExtensions.cs @@ -4,6 +4,7 @@ using System.Text; using System.Text.RegularExpressions; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore @@ -25,7 +26,7 @@ public static bool ILike( [CanBeNull] this DbFunctions _, [CanBeNull] string matchExpression, [CanBeNull] string pattern) - => ILikeCore(matchExpression, pattern, null); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ILike))); // ReSharper disable once InconsistentNaming /// @@ -44,95 +45,6 @@ public static bool ILike( [CanBeNull] string matchExpression, [CanBeNull] string pattern, [CanBeNull] string escapeCharacter) - => ILikeCore(matchExpression, pattern, escapeCharacter); - - /// - /// Regex special chars defined here: - /// https://msdn.microsoft.com/en-us/library/4edbef7e(v=vs.110).aspx - /// - static readonly char[] RegexSpecialChars = - { '.', '$', '^', '{', '[', '(', '|', ')', '*', '+', '?', '\\' }; - - static readonly string DefaultEscapeRegexCharsPattern = - BuildEscapeRegexCharsPattern(RegexSpecialChars); - - static readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(value: 1000.0); - - static string BuildEscapeRegexCharsPattern(IEnumerable regexSpecialChars) - => string.Join("|", regexSpecialChars.Select(c => @"\" + c)); - - // ReSharper disable once InconsistentNaming - static bool ILikeCore(string matchExpression, string pattern, string escapeCharacter) - { - //TODO: this fixes https://github.com/aspnet/EntityFramework/issues/8656 by insisting that - // the "escape character" is a string but just using the first character of that string, - // but we may later want to allow the complete string as the "escape character" - // in which case we need to change the way we construct the regex below. - var singleEscapeCharacter = - string.IsNullOrEmpty(escapeCharacter) - ? (char?)null - : escapeCharacter.First(); - - if (matchExpression == null || pattern == null) - return false; - - if (matchExpression.Equals(pattern)) - return true; - - if (matchExpression.Length == 0 || pattern.Length == 0) - return false; - - var escapeRegexCharsPattern = - singleEscapeCharacter == null - ? DefaultEscapeRegexCharsPattern - : BuildEscapeRegexCharsPattern(RegexSpecialChars.Where(c => c != singleEscapeCharacter)); - - var regexPattern = - Regex.Replace( - pattern, - escapeRegexCharsPattern, - c => @"\" + c, - default, - RegexTimeout); - - var stringBuilder = new StringBuilder(); - - for (var i = 0; i < regexPattern.Length; i++) - { - var c = regexPattern[i]; - var escaped = i > 0 && regexPattern[i - 1] == singleEscapeCharacter; - - switch (c) - { - case '_': - { - stringBuilder.Append(escaped ? '_' : '.'); - break; - } - case '%': - { - stringBuilder.Append(escaped ? "%" : ".*"); - break; - } - default: - { - if (c != singleEscapeCharacter) - { - stringBuilder.Append(c); - } - - break; - } - } - } - - regexPattern = stringBuilder.ToString(); - - return Regex.IsMatch( - matchExpression, - @"\A" + regexPattern + @"\s*\z", - RegexOptions.IgnoreCase | RegexOptions.Singleline, - RegexTimeout); - } + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ILike))); } } diff --git a/src/EFCore.PG/Extensions/NpgsqlFullTextSearchDbFunctionsExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlFullTextSearchDbFunctionsExtensions.cs index 6969563da..86df34d1e 100644 --- a/src/EFCore.PG/Extensions/NpgsqlFullTextSearchDbFunctionsExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlFullTextSearchDbFunctionsExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using Microsoft.EntityFrameworkCore.Diagnostics; using NpgsqlTypes; // ReSharper disable once CheckNamespace @@ -14,8 +15,8 @@ public static class NpgsqlFullTextSearchDbFunctionsExtensions /// /// https://www.postgresql.org/docs/current/static/functions-textsearch.html /// - public static NpgsqlTsVector ArrayToTsVector(this DbFunctions _, string[] lexemes) => - throw new NotSupportedException(); + public static NpgsqlTsVector ArrayToTsVector(this DbFunctions _, string[] lexemes) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ArrayToTsVector))); /// /// Reduce to tsvector. @@ -23,8 +24,8 @@ public static NpgsqlTsVector ArrayToTsVector(this DbFunctions _, string[] lexeme /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS /// - public static NpgsqlTsVector ToTsVector(this DbFunctions _, string document) => - throw new NotSupportedException(); + public static NpgsqlTsVector ToTsVector(this DbFunctions _, string document) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ToTsVector))); /// /// Reduce to tsvector using the text search configuration specified @@ -33,8 +34,8 @@ public static NpgsqlTsVector ToTsVector(this DbFunctions _, string document) => /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS /// - public static NpgsqlTsVector ToTsVector(this DbFunctions _, string config, string document) => - throw new NotSupportedException(); + public static NpgsqlTsVector ToTsVector(this DbFunctions _, string config, string document) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ToTsVector))); /// /// Produce tsquery from ignoring punctuation. @@ -42,8 +43,8 @@ public static NpgsqlTsVector ToTsVector(this DbFunctions _, string config, strin /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(PlainToTsQuery))); /// /// Produce tsquery from ignoring punctuation and using the text search @@ -52,8 +53,8 @@ public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string query) => /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string config, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string config, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(PlainToTsQuery))); /// /// Produce tsquery that searches for a phrase from ignoring punctuation. @@ -61,8 +62,8 @@ public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string config, st /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(PhraseToTsQuery))); /// /// Produce tsquery that searches for a phrase from ignoring punctuation @@ -71,8 +72,8 @@ public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string query) => /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string config, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string config, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(PhraseToTsQuery))); /// /// Normalize words in and convert to tsquery. If your input @@ -82,7 +83,8 @@ public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string config, s /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string query) => throw new NotSupportedException(); + public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ToTsQuery))); /// /// Normalize words in and convert to tsquery using the text search @@ -93,8 +95,8 @@ public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string config, s /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string config, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string config, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ToTsQuery))); /// /// Convert tsquery using the simplified websearch syntax. @@ -102,8 +104,8 @@ public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string config, string /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(WebSearchToTsQuery))); /// /// Convert tsquery using the simplified websearch syntax and the text @@ -112,7 +114,7 @@ public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string query) /// /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES /// - public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string config, string query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string config, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(WebSearchToTsQuery))); } } diff --git a/src/EFCore.PG/Extensions/NpgsqlFullTextSearchLinqExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlFullTextSearchLinqExtensions.cs index 0622ac399..1da1bde51 100644 --- a/src/EFCore.PG/Extensions/NpgsqlFullTextSearchLinqExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlFullTextSearchLinqExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using Microsoft.EntityFrameworkCore.Diagnostics; using NpgsqlTypes; // ReSharper disable once CheckNamespace @@ -12,91 +13,90 @@ public static class NpgsqlFullTextSearchLinqExtensions /// AND tsquerys together. Generates the "&&" operator. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static NpgsqlTsQuery And(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) => - throw new NotSupportedException(); + public static NpgsqlTsQuery And(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(And))); /// /// OR tsquerys together. Generates the "||" operator. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static NpgsqlTsQuery Or(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) => - throw new NotSupportedException(); + public static NpgsqlTsQuery Or(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(Or))); /// /// Negate a tsquery. Generates the "!!" operator. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static NpgsqlTsQuery ToNegative(this NpgsqlTsQuery query) => - throw new NotSupportedException(); + public static NpgsqlTsQuery ToNegative(this NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(ToNegative))); /// /// Returns whether contains . /// Generates the "@>" operator. /// http://www.postgresql.org/docs/current/static/functions-textsearch.html /// - public static bool Contains(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) => - throw new NotSupportedException(); + public static bool Contains(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(Contains))); /// /// Returns whether is contained within . /// Generates the "<@" operator. /// http://www.postgresql.org/docs/current/static/functions-textsearch.html /// - public static bool IsContainedIn(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) => - throw new NotSupportedException(); + public static bool IsContainedIn(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(IsContainedIn))); /// /// Returns the number of lexemes plus operators in . /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static int GetNodeCount(this NpgsqlTsQuery query) => throw new NotSupportedException(); + public static int GetNodeCount(this NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(GetNodeCount))); /// /// Get the indexable part of . /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static string GetQueryTree(this NpgsqlTsQuery query) => throw new NotSupportedException(); + public static string GetQueryTree(this NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(GetQueryTree))); /// /// Returns a string suitable for display containing a query match. /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-HEADLINE /// - public static string GetResultHeadline(this NpgsqlTsQuery query, string document) => - throw new NotSupportedException(); + public static string GetResultHeadline(this NpgsqlTsQuery query, string document) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(GetResultHeadline))); /// /// Returns a string suitable for display containing a query match. /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-HEADLINE /// - public static string GetResultHeadline(this NpgsqlTsQuery query, string document, string options) => - throw new NotSupportedException(); + public static string GetResultHeadline(this NpgsqlTsQuery query, string document, string options) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(GetResultHeadline))); /// /// Returns a string suitable for display containing a query match using the text /// search configuration specified by . /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-HEADLINE /// - public static string GetResultHeadline( - this NpgsqlTsQuery query, - string config, - string document, - string options) => throw new NotSupportedException(); + public static string GetResultHeadline(this NpgsqlTsQuery query, string config, string document, string options) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(GetResultHeadline))); /// /// Searches for occurrences of , and replaces /// each occurrence with a . All parameters are of type tsquery. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static NpgsqlTsQuery Rewrite(this NpgsqlTsQuery query, NpgsqlTsQuery target, NpgsqlTsQuery substitute) => - throw new NotSupportedException(); + public static NpgsqlTsQuery Rewrite(this NpgsqlTsQuery query, NpgsqlTsQuery target, NpgsqlTsQuery substitute) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(Rewrite))); /// /// Returns a tsquery that searches for a match to followed by a match /// to . /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static NpgsqlTsQuery ToPhrase(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) => - throw new NotSupportedException(); + public static NpgsqlTsQuery ToPhrase(this NpgsqlTsQuery query1, NpgsqlTsQuery query2) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(ToPhrase))); /// /// Returns a tsquery that searches for a match to followed by a match @@ -104,22 +104,23 @@ public static NpgsqlTsQuery ToPhrase(this NpgsqlTsQuery query1, NpgsqlTsQuery qu /// the <N> tsquery operator /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY /// - public static NpgsqlTsQuery ToPhrase(this NpgsqlTsQuery query1, NpgsqlTsQuery query2, int distance) => - throw new NotSupportedException(); + public static NpgsqlTsQuery ToPhrase(this NpgsqlTsQuery query1, NpgsqlTsQuery query2, int distance) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsQuery) + "." + nameof(ToPhrase))); /// /// This method generates the "@@" match operator. The parameter is /// assumed to be a plain search query and will be converted to a tsquery using plainto_tsquery. /// http://www.postgresql.org/docs/current/static/textsearch-intro.html#TEXTSEARCH-MATCHING /// - public static bool Matches(this NpgsqlTsVector vector, string query) => throw new NotSupportedException(); + public static bool Matches(this NpgsqlTsVector vector, string query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Matches))); /// /// This method generates the "@@" match operator. /// http://www.postgresql.org/docs/current/static/textsearch-intro.html#TEXTSEARCH-MATCHING /// - public static bool Matches(this NpgsqlTsVector vector, NpgsqlTsQuery query) => - throw new NotSupportedException(); + public static bool Matches(this NpgsqlTsVector vector, NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Matches))); /// /// Returns a vector which combines the lexemes and positional information of @@ -127,101 +128,99 @@ public static bool Matches(this NpgsqlTsVector vector, NpgsqlTsQuery query) => /// during the concatenation. /// https://www.postgresql.org/docs/10/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static NpgsqlTsVector Concat(this NpgsqlTsVector vector1, NpgsqlTsVector vector2) => - throw new NotSupportedException(); + public static NpgsqlTsVector Concat(this NpgsqlTsVector vector1, NpgsqlTsVector vector2) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Concat))); /// /// Assign weight to each element of and return a new /// weighted tsvector. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, NpgsqlTsVector.Lexeme.Weight weight) => - throw new NotSupportedException(); + public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, NpgsqlTsVector.Lexeme.Weight weight) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(SetWeight))); /// /// Assign weight to elements of that are in and /// return a new weighted tsvector. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static NpgsqlTsVector SetWeight( - this NpgsqlTsVector vector, - NpgsqlTsVector.Lexeme.Weight weight, - string[] lexemes) => - throw new NotSupportedException(); + public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, NpgsqlTsVector.Lexeme.Weight weight, string[] lexemes) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(SetWeight))); /// /// Assign weight to each element of and return a new /// weighted tsvector. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, char weight) => - throw new NotSupportedException(); + public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, char weight) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(SetWeight))); /// /// Assign weight to elements of that are in and /// return a new weighted tsvector. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, char weight, string[] lexemes) => - throw new NotSupportedException(); + public static NpgsqlTsVector SetWeight(this NpgsqlTsVector vector, char weight, string[] lexemes) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(SetWeight))); /// /// Return a new vector with removed from /// https://www.postgresql.org/docs/current/static/functions-textsearch.html /// - public static NpgsqlTsVector Delete(this NpgsqlTsVector vector, string lexeme) => - throw new NotSupportedException(); + public static NpgsqlTsVector Delete(this NpgsqlTsVector vector, string lexeme) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Delete))); /// /// Return a new vector with removed from /// https://www.postgresql.org/docs/current/static/functions-textsearch.html /// - public static NpgsqlTsVector Delete(this NpgsqlTsVector vector, string[] lexemes) => - throw new NotSupportedException(); + public static NpgsqlTsVector Delete(this NpgsqlTsVector vector, string[] lexemes) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Delete))); /// /// Returns a new vector with only lexemes having weights specified in . /// https://www.postgresql.org/docs/current/static/functions-textsearch.html /// - public static NpgsqlTsVector Filter(this NpgsqlTsVector vector, char[] weights) => - throw new NotSupportedException(); + public static NpgsqlTsVector Filter(this NpgsqlTsVector vector, char[] weights) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Filter))); /// /// Returns the number of lexemes in . /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static int GetLength(this NpgsqlTsVector vector) => throw new NotSupportedException(); + public static int GetLength(this NpgsqlTsVector vector) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(GetLength))); /// /// Removes weights and positions from and returns /// a new stripped tsvector. /// http://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSVECTOR /// - public static NpgsqlTsVector ToStripped(this NpgsqlTsVector vector) => throw new NotSupportedException(); + public static NpgsqlTsVector ToStripped(this NpgsqlTsVector vector) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(ToStripped))); /// /// Calculates the rank of for . /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float Rank(this NpgsqlTsVector vector, NpgsqlTsQuery query) => throw new NotSupportedException(); + public static float Rank(this NpgsqlTsVector vector, NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Rank))); /// /// Calculates the rank of for while normalizing /// the result according to the behaviors specified by . /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float Rank( - this NpgsqlTsVector vector, - NpgsqlTsQuery query, - NpgsqlTsRankingNormalization normalization) => throw new NotSupportedException(); + public static float Rank(this NpgsqlTsVector vector, NpgsqlTsQuery query, NpgsqlTsRankingNormalization normalization) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Rank))); /// /// Calculates the rank of for with custom /// weighting for word instances depending on their labels (D, C, B or A). /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float Rank(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query) => - throw new NotSupportedException(); + public static float Rank(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Rank))); /// /// Calculates the rank of for while normalizing @@ -229,19 +228,16 @@ public static float Rank(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQu /// and using custom weighting for word instances depending on their labels (D, C, B or A). /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float Rank( - this NpgsqlTsVector vector, - float[] weights, - NpgsqlTsQuery query, - NpgsqlTsRankingNormalization normalization) => throw new NotSupportedException(); + public static float Rank(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query, NpgsqlTsRankingNormalization normalization) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(Rank))); /// /// Calculates the rank of for using the cover /// density method. /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float RankCoverDensity(this NpgsqlTsVector vector, NpgsqlTsQuery query) => - throw new NotSupportedException(); + public static float RankCoverDensity(this NpgsqlTsVector vector, NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(RankCoverDensity))); /// /// Calculates the rank of for using the cover @@ -249,18 +245,16 @@ public static float RankCoverDensity(this NpgsqlTsVector vector, NpgsqlTsQuery q /// . /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float RankCoverDensity( - this NpgsqlTsVector vector, - NpgsqlTsQuery query, - NpgsqlTsRankingNormalization normalization) => throw new NotSupportedException(); + public static float RankCoverDensity(this NpgsqlTsVector vector, NpgsqlTsQuery query, NpgsqlTsRankingNormalization normalization) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(RankCoverDensity))); /// /// Calculates the rank of for using the cover /// density method with custom weighting for word instances depending on their labels (D, C, B or A). /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float RankCoverDensity(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query) => - throw new NotSupportedException(); + public static float RankCoverDensity(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(RankCoverDensity))); /// /// Calculates the rank of for using the cover density @@ -268,10 +262,7 @@ public static float RankCoverDensity(this NpgsqlTsVector vector, float[] weights /// and using custom weighting for word instances depending on their labels (D, C, B or A). /// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-RANKING /// - public static float RankCoverDensity( - this NpgsqlTsVector vector, - float[] weights, - NpgsqlTsQuery query, - NpgsqlTsRankingNormalization normalization) => throw new NotSupportedException(); + public static float RankCoverDensity(this NpgsqlTsVector vector, float[] weights, NpgsqlTsQuery query, NpgsqlTsRankingNormalization normalization) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(NpgsqlTsVector) + "." + nameof(RankCoverDensity))); } } diff --git a/src/EFCore.PG/Extensions/NpgsqlJsonDbFunctionsExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlJsonDbFunctionsExtensions.cs index 3a4964f36..6ffd67353 100644 --- a/src/EFCore.PG/Extensions/NpgsqlJsonDbFunctionsExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlJsonDbFunctionsExtensions.cs @@ -2,6 +2,8 @@ using System.Runtime.CompilerServices; using System.Text.Json; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; +using NpgsqlTypes; namespace Npgsql.EntityFrameworkCore.PostgreSQL.Extensions { @@ -27,7 +29,7 @@ public static class NpgsqlJsonDbFunctionsExtensions /// See https://www.postgresql.org/docs/current/functions-json.html. /// public static bool JsonContains(this DbFunctions _, object json, object contained) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonContains))); /// /// Checks if is contained in as top-level entries. @@ -45,7 +47,7 @@ public static bool JsonContains(this DbFunctions _, object json, object containe /// See https://www.postgresql.org/docs/current/functions-json.html. /// public static bool JsonContained(this DbFunctions _, object contained, object json) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonContained))); /// /// Checks if exists as a top-level key within . @@ -61,7 +63,7 @@ public static bool JsonContained(this DbFunctions _, object contained, object js /// See https://www.postgresql.org/docs/current/functions-json.html. /// public static bool JsonExists(this DbFunctions _, object json, string key) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonExists))); /// /// Checks if any of the given exist as top-level keys within . @@ -77,7 +79,7 @@ public static bool JsonExists(this DbFunctions _, object json, string key) /// See https://www.postgresql.org/docs/current/functions-json.html. /// public static bool JsonExistAny(this DbFunctions _, object json, params string[] keys) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonExistAny))); /// /// Checks if all of the given exist as top-level keys within . @@ -93,7 +95,7 @@ public static bool JsonExistAny(this DbFunctions _, object json, params string[] /// See https://www.postgresql.org/docs/current/functions-json.html. /// public static bool JsonExistAll(this DbFunctions _, object json, params string[] keys) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonExistAll))); /// /// Returns the type of the outermost JSON value as a text string. @@ -107,9 +109,6 @@ public static bool JsonExistAll(this DbFunctions _, object json, params string[] /// See https://www.postgresql.org/docs/current/functions-json.html. /// public static string JsonTypeof(this DbFunctions _, object json) - => throw ClientEvaluationNotSupportedException(); - - static NotSupportedException ClientEvaluationNotSupportedException([CallerMemberName] string method = default) - => new NotSupportedException($"{method} is only intended for use via SQL translation as part of an EF Core LINQ query."); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(JsonTypeof))); } } diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkDbFunctionsExtensions.cs similarity index 87% rename from src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs rename to src/EFCore.PG/Extensions/NpgsqlNetworkDbFunctionsExtensions.cs index fd78ce54b..659800349 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkDbFunctionsExtensions.cs @@ -4,6 +4,7 @@ using System.Net.NetworkInformation; using System.Runtime.CompilerServices; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore @@ -14,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore /// /// See: https://www.postgresql.org/docs/current/static/functions-net.html /// - public static class NpgsqlNetworkExtensions + public static class NpgsqlNetworkDbFunctionsExtensions { #region RelationalOperators @@ -31,7 +32,7 @@ public static class NpgsqlNetworkExtensions /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool LessThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(LessThan))); /// /// Determines whether an (IPAddress Address, int Subnet) is less than another (IPAddress Address, int Subnet). @@ -46,7 +47,7 @@ public static bool LessThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAd /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool LessThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(LessThan))); /// /// Determines whether an is less than another . @@ -61,7 +62,7 @@ public static bool LessThan([CanBeNull] this DbFunctions _, (IPAddress Address, /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool LessThan([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(LessThan))); /// /// Determines whether an is less than or equal to another . @@ -76,7 +77,7 @@ public static bool LessThan([CanBeNull] this DbFunctions _, PhysicalAddress maca /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(LessThanOrEqual))); /// /// Determines whether an (IPAddress Address, int Subnet) is less than or equal to another (IPAddress Address, int Subnet). @@ -91,7 +92,7 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, IPAddress ine /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(LessThanOrEqual))); /// /// Determines whether an is less than or equal to another . @@ -106,7 +107,7 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(LessThanOrEqual))); /// /// Determines whether an is greater than or equal to another . @@ -121,7 +122,7 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddre /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(GreaterThanOrEqual))); /// /// Determines whether an (IPAddress Address, int Subnet) is greater than or equal to another (IPAddress Address, int Subnet). @@ -136,7 +137,7 @@ public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, IPAddress /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(GreaterThanOrEqual))); /// /// Determines whether an is greater than or equal to another . @@ -151,7 +152,7 @@ public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(GreaterThanOrEqual))); /// /// Determines whether an is greater than another . @@ -166,7 +167,7 @@ public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAd /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool GreaterThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(GreaterThan))); /// /// Determines whether an (IPAddress Address, int Subnet) is greater than another (IPAddress Address, int Subnet). @@ -181,7 +182,7 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, IPAddress inet, I /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(GreaterThan))); /// /// Determines whether an is greater than another . @@ -196,7 +197,7 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Addres /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool GreaterThan([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(GreaterThan))); #endregion @@ -215,7 +216,7 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, PhysicalAddress m /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedBy))); /// /// Determines whether an is contained within a network. @@ -230,7 +231,7 @@ public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, I /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedBy))); /// /// Determines whether an (IPAddress Address, int Subnet) is contained within another (IPAddress Address, int Subnet). @@ -245,7 +246,7 @@ public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, ( /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedBy))); /// /// Determines whether an is contained within or equal to another . @@ -260,7 +261,7 @@ public static bool ContainedBy([CanBeNull] this DbFunctions _, (IPAddress Addres /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedByOrEqual))); /// /// Determines whether an is contained within or equal to a network. @@ -275,7 +276,7 @@ public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedByOrEqual))); /// /// Determines whether an (IPAddress Address, int Subnet) is contained within or equal to another (IPAddress Address, int Subnet). @@ -290,7 +291,7 @@ public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedByOrEqual))); /// /// Determines whether an contains another . @@ -305,7 +306,7 @@ public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, (IPAddress /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool Contains([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Contains))); /// /// Determines whether a network contains another . @@ -320,7 +321,7 @@ public static bool Contains([CanBeNull] this DbFunctions _, IPAddress inet, IPAd /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Contains))); /// /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). @@ -335,7 +336,7 @@ public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Contains))); /// /// Determines whether an contains or is equal to another . @@ -350,7 +351,7 @@ public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrEqual))); /// /// Determines whether a network contains or is equal to another . @@ -365,7 +366,7 @@ public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, IPAddress ine /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrEqual))); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). @@ -380,7 +381,7 @@ public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrEqual))); /// /// Determines whether an contains or is contained by another . @@ -395,7 +396,7 @@ public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrContainedBy))); /// /// Determines whether a network contains or is contained by an . @@ -410,7 +411,7 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddre /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrContainedBy))); /// /// Determines whether an contains or is contained by a network. @@ -425,7 +426,7 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddr /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrContainedBy))); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is contained by another (IPAddress Address, int Subnet). @@ -440,7 +441,7 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddre /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainsOrContainedBy))); #endregion @@ -458,7 +459,7 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddr /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress BitwiseNot([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseNot))); /// /// Computes the bitwise NOT operation on an (IPAddress Address, int Subnet). @@ -472,7 +473,7 @@ public static IPAddress BitwiseNot([CanBeNull] this DbFunctions _, IPAddress ine /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) BitwiseNot([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseNot))); /// /// Computes the bitwise NOT operation on an . @@ -486,7 +487,7 @@ public static (IPAddress Address, int Subnet) BitwiseNot([CanBeNull] this DbFunc /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static PhysicalAddress BitwiseNot([CanBeNull] this DbFunctions _, PhysicalAddress macaddr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseNot))); /// /// Computes the bitwise AND of two instances. @@ -501,7 +502,7 @@ public static PhysicalAddress BitwiseNot([CanBeNull] this DbFunctions _, Physica /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress BitwiseAnd([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseAnd))); /// /// Computes the bitwise AND of two (IPAddress Address, int Subnet) instances. @@ -516,7 +517,7 @@ public static IPAddress BitwiseAnd([CanBeNull] this DbFunctions _, IPAddress ine /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) BitwiseAnd([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseAnd))); /// /// Computes the bitwise AND of two instances. @@ -531,7 +532,7 @@ public static (IPAddress Address, int Subnet) BitwiseAnd([CanBeNull] this DbFunc /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static PhysicalAddress BitwiseAnd([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseAnd))); /// /// Computes the bitwise OR of two instances. @@ -546,7 +547,7 @@ public static PhysicalAddress BitwiseAnd([CanBeNull] this DbFunctions _, Physica /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress BitwiseOr([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseOr))); /// /// Computes the bitwise OR of two (IPAddress Address, int Subnet) instances. @@ -561,7 +562,7 @@ public static IPAddress BitwiseOr([CanBeNull] this DbFunctions _, IPAddress inet /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) BitwiseOr([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseOr))); /// /// Computes the bitwise OR of two instances. @@ -576,7 +577,7 @@ public static (IPAddress Address, int Subnet) BitwiseOr([CanBeNull] this DbFunct /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static PhysicalAddress BitwiseOr([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(BitwiseOr))); #endregion @@ -595,7 +596,7 @@ public static PhysicalAddress BitwiseOr([CanBeNull] this DbFunctions _, Physical /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress Add([CanBeNull] this DbFunctions _, IPAddress inet, int value) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Add))); /// /// Adds the to the (IPAddress Address, int Subnet). @@ -610,7 +611,7 @@ public static IPAddress Add([CanBeNull] this DbFunctions _, IPAddress inet, int /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) Add([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int value) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Add))); /// /// Subtracts the from the . @@ -625,7 +626,7 @@ public static (IPAddress Address, int Subnet) Add([CanBeNull] this DbFunctions _ /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress Subtract([CanBeNull] this DbFunctions _, IPAddress inet, int value) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Subtract))); /// /// Subtracts the from the (IPAddress Address, int Subnet). @@ -640,7 +641,7 @@ public static IPAddress Subtract([CanBeNull] this DbFunctions _, IPAddress inet, /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int value) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Subtract))); /// /// Subtracts one from another . @@ -655,7 +656,7 @@ public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFuncti /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static int Subtract([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Subtract))); /// /// Subtracts one (IPAddress Address, int Subnet) from another (IPAddress Address, int Subnet). @@ -670,7 +671,7 @@ public static int Subtract([CanBeNull] this DbFunctions _, IPAddress inet, IPAdd /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static int Subtract([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Subtract))); #endregion @@ -688,7 +689,7 @@ public static int Subtract([CanBeNull] this DbFunctions _, (IPAddress Address, i /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static string Abbreviate([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Abbreviate))); /// /// Returns the abbreviated display format as text. @@ -702,7 +703,7 @@ public static string Abbreviate([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static string Abbreviate([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Abbreviate))); /// /// Returns the broadcast address for a network. @@ -716,7 +717,7 @@ public static string Abbreviate([CanBeNull] this DbFunctions _, (IPAddress Addre /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress Broadcast([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Broadcast))); /// /// Returns the broadcast address for a network. @@ -730,7 +731,7 @@ public static IPAddress Broadcast([CanBeNull] this DbFunctions _, IPAddress inet /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress Broadcast([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Broadcast))); /// /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. @@ -744,7 +745,7 @@ public static IPAddress Broadcast([CanBeNull] this DbFunctions _, (IPAddress Add /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static int Family([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Family))); /// /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. @@ -758,7 +759,7 @@ public static int Family([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static int Family([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Family))); /// /// Extracts the host (i.e. the IP address) as text. @@ -772,7 +773,7 @@ public static int Family([CanBeNull] this DbFunctions _, (IPAddress Address, int /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static string Host([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Host))); /// /// Extracts the host (i.e. the IP address) as text. @@ -786,7 +787,7 @@ public static string Host([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static string Host([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Host))); /// /// Constructs the host mask for the network. @@ -800,7 +801,7 @@ public static string Host([CanBeNull] this DbFunctions _, (IPAddress Address, in /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress HostMask([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(HostMask))); /// /// Constructs the host mask for the network. @@ -814,7 +815,7 @@ public static IPAddress HostMask([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress HostMask([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(HostMask))); /// /// Extracts the length of the subnet mask. @@ -828,7 +829,7 @@ public static IPAddress HostMask([CanBeNull] this DbFunctions _, (IPAddress Addr /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static int MaskLength([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(MaskLength))); /// /// Extracts the length of the subnet mask. @@ -842,7 +843,7 @@ public static int MaskLength([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static int MaskLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(MaskLength))); /// /// Constructs the subnet mask for the network. @@ -856,7 +857,7 @@ public static int MaskLength([CanBeNull] this DbFunctions _, (IPAddress Address, /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress Netmask([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Netmask))); /// /// Constructs the subnet mask for the network. @@ -870,7 +871,7 @@ public static IPAddress Netmask([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress Netmask([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Netmask))); /// /// Extracts the network part of the address. @@ -884,7 +885,7 @@ public static IPAddress Netmask([CanBeNull] this DbFunctions _, (IPAddress Addre /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Network))); /// /// Extracts the network part of the address. @@ -898,7 +899,7 @@ public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctio /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Network))); /// /// Sets the length of the subnet mask. @@ -913,7 +914,7 @@ public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctio /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static IPAddress SetMaskLength([CanBeNull] this DbFunctions _, IPAddress inet, int length) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(SetMaskLength))); /// /// Sets the length of the subnet mask. @@ -928,7 +929,7 @@ public static IPAddress SetMaskLength([CanBeNull] this DbFunctions _, IPAddress /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) SetMaskLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int length) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(SetMaskLength))); /// /// Extracts the IP address and subnet mask as text. @@ -942,7 +943,7 @@ public static (IPAddress Address, int Subnet) SetMaskLength([CanBeNull] this DbF /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static string Text([CanBeNull] this DbFunctions _, IPAddress inet) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Text))); /// /// Extracts the IP address and subnet mask as text. @@ -956,7 +957,7 @@ public static string Text([CanBeNull] this DbFunctions _, IPAddress inet) /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static string Text([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Text))); /// /// Tests if the addresses are in the same family. @@ -971,7 +972,7 @@ public static string Text([CanBeNull] this DbFunctions _, (IPAddress Address, in /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool SameFamily([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(SameFamily))); /// /// Tests if the addresses are in the same family. @@ -986,7 +987,7 @@ public static bool SameFamily([CanBeNull] this DbFunctions _, IPAddress inet, IP /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool SameFamily([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(SameFamily))); /// /// Constructs the smallest network which includes both of the given networks. @@ -1001,7 +1002,7 @@ public static bool SameFamily([CanBeNull] this DbFunctions _, (IPAddress Address /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Merge))); /// /// Constructs the smallest network which includes both of the given networks. @@ -1016,7 +1017,7 @@ public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Merge))); /// /// Sets the last 3 bytes of the MAC address to zero. For macaddr8, the last 5 bytes are set to zero. @@ -1030,7 +1031,7 @@ public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static PhysicalAddress Truncate([CanBeNull] this DbFunctions _, PhysicalAddress macAddress) - => throw ClientEvaluationNotSupportedException(); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Truncate))); /// /// Sets the 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 address. @@ -1044,21 +1045,7 @@ public static PhysicalAddress Truncate([CanBeNull] this DbFunctions _, PhysicalA /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static PhysicalAddress Set7BitMac8([CanBeNull] this DbFunctions _, PhysicalAddress macAddress) - => throw ClientEvaluationNotSupportedException(); - - #endregion - - #region Utilities - - /// - /// Helper method to throw a with the name of the throwing method. - /// - /// The method that throws the exception. - /// - /// A . - /// - static NotSupportedException ClientEvaluationNotSupportedException([CallerMemberName] string method = default) - => new NotSupportedException($"{method} is only intended for use via SQL translation as part of an EF Core LINQ query."); + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Set7BitMac8))); #endregion } diff --git a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlRangeDbFunctionsExtensions.cs similarity index 84% rename from src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs rename to src/EFCore.PG/Extensions/NpgsqlRangeDbFunctionsExtensions.cs index 92fb513c0..c5f7fd871 100644 --- a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlRangeDbFunctionsExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.CompilerServices; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using NpgsqlTypes; // ReSharper disable once CheckNamespace @@ -9,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore /// /// Provides extension methods for supporting PostgreSQL translation. /// - public static class NpgsqlRangeExtensions + public static class NpgsqlRangeDbFunctionsExtensions { /// /// Determines whether a range contains a specified value. @@ -21,7 +22,8 @@ public static class NpgsqlRangeExtensions /// true if the range contains the specified value; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool Contains(this NpgsqlRange range, T value) => throw ClientEvaluationNotSupportedException(); + public static bool Contains(this NpgsqlRange range, T value) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Contains))); /// /// Determines whether a range contains a specified range. @@ -33,7 +35,8 @@ public static class NpgsqlRangeExtensions /// true if the range contains the specified range; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool Contains(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool Contains(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Contains))); /// /// Determines whether a range is contained by a specified range. @@ -45,7 +48,8 @@ public static class NpgsqlRangeExtensions /// true if the range contains the specified range; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool ContainedBy(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool ContainedBy(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(ContainedBy))); /// /// Determines whether a range overlaps another range. @@ -57,7 +61,8 @@ public static class NpgsqlRangeExtensions /// true if the ranges overlap (share points in common); otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool Overlaps(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool Overlaps(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Overlaps))); /// /// Determines whether a range is strictly to the left of another range. @@ -69,7 +74,8 @@ public static class NpgsqlRangeExtensions /// true if the first range is strictly to the left of the second; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool IsStrictlyLeftOf(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool IsStrictlyLeftOf(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsStrictlyLeftOf))); /// /// Determines whether a range is strictly to the right of another range. @@ -81,7 +87,8 @@ public static class NpgsqlRangeExtensions /// true if the first range is strictly to the right of the second; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool IsStrictlyRightOf(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool IsStrictlyRightOf(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsStrictlyRightOf))); /// /// Determines whether a range does not extend to the left of another range. @@ -93,7 +100,8 @@ public static class NpgsqlRangeExtensions /// true if the first range does not extend to the left of the second; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool DoesNotExtendLeftOf(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool DoesNotExtendLeftOf(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DoesNotExtendLeftOf))); /// /// Determines whether a range does not extend to the right of another range. @@ -105,7 +113,8 @@ public static class NpgsqlRangeExtensions /// true if the first range does not extend to the right of the second; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool DoesNotExtendRightOf(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool DoesNotExtendRightOf(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(DoesNotExtendRightOf))); /// /// Determines whether a range is adjacent to another range. @@ -117,7 +126,8 @@ public static class NpgsqlRangeExtensions /// true if the ranges are adjacent; otherwise, false. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static bool IsAdjacentTo(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static bool IsAdjacentTo(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IsAdjacentTo))); /// /// Returns the set union, which means unique elements that appear in either of two ranges. @@ -129,7 +139,8 @@ public static class NpgsqlRangeExtensions /// The unique elements that appear in either range. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static NpgsqlRange Union(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static NpgsqlRange Union(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Union))); /// /// Returns the set intersection, which means elements that appear in each of two ranges. @@ -141,7 +152,8 @@ public static class NpgsqlRangeExtensions /// The elements that appear in both ranges. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static NpgsqlRange Intersect(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static NpgsqlRange Intersect(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Intersect))); /// /// Returns the set difference, which means the elements of one range that do not appear in a second range. @@ -153,7 +165,8 @@ public static class NpgsqlRangeExtensions /// The elements that appear in the first range, but not the second range. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static NpgsqlRange Except(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); + public static NpgsqlRange Except(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Except))); /// /// Returns the smallest range which includes both of the given ranges. @@ -165,21 +178,7 @@ public static class NpgsqlRangeExtensions /// The smallest range which includes both of the given rangesge. /// /// {method} is only intended for use via SQL translation as part of an EF Core LINQ query. - public static NpgsqlRange Merge(this NpgsqlRange a, NpgsqlRange b) => throw ClientEvaluationNotSupportedException(); - - #region Utilities - - /// - /// Helper method to throw a with the name of the throwing method. - /// - /// The method that throws the exception. - /// - /// A . - /// - [NotNull] - static NotSupportedException ClientEvaluationNotSupportedException([CallerMemberName] string method = default) - => new NotSupportedException($"{method} is only intended for use via SQL translation as part of an EF Core LINQ query."); - - #endregion + public static NpgsqlRange Merge(this NpgsqlRange a, NpgsqlRange b) + => throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(Merge))); } } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs index 8ebccd6fc..da1eb414c 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs @@ -55,33 +55,33 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO if (method == PhysicalAddressParse) return _sqlExpressionFactory.Convert(arguments[0], typeof(PhysicalAddress), _sqlExpressionFactory.FindMapping(typeof(PhysicalAddress))); - if (method.DeclaringType != typeof(NpgsqlNetworkExtensions)) + if (method.DeclaringType != typeof(NpgsqlNetworkDbFunctionsExtensions)) return null; return method.Name switch { - nameof(NpgsqlNetworkExtensions.LessThan) => _sqlExpressionFactory.LessThan(arguments[1], arguments[2]), - nameof(NpgsqlNetworkExtensions.LessThanOrEqual) => _sqlExpressionFactory.LessThanOrEqual(arguments[1], arguments[2]), - nameof(NpgsqlNetworkExtensions.GreaterThanOrEqual) => _sqlExpressionFactory.GreaterThanOrEqual(arguments[1], arguments[2]), - nameof(NpgsqlNetworkExtensions.GreaterThan) => _sqlExpressionFactory.GreaterThan(arguments[1], arguments[2]), - - nameof(NpgsqlNetworkExtensions.ContainedBy) => BoolReturningOnTwoNetworkTypes("<<"), - nameof(NpgsqlNetworkExtensions.ContainedByOrEqual) => BoolReturningOnTwoNetworkTypes("<<="), - nameof(NpgsqlNetworkExtensions.Contains) => BoolReturningOnTwoNetworkTypes(">>"), - nameof(NpgsqlNetworkExtensions.ContainsOrEqual) => BoolReturningOnTwoNetworkTypes(">>="), - nameof(NpgsqlNetworkExtensions.ContainsOrContainedBy) => BoolReturningOnTwoNetworkTypes("&&"), - - nameof(NpgsqlNetworkExtensions.BitwiseNot) => new SqlUnaryExpression(ExpressionType.Not, + nameof(NpgsqlNetworkDbFunctionsExtensions.LessThan) => _sqlExpressionFactory.LessThan(arguments[1], arguments[2]), + nameof(NpgsqlNetworkDbFunctionsExtensions.LessThanOrEqual) => _sqlExpressionFactory.LessThanOrEqual(arguments[1], arguments[2]), + nameof(NpgsqlNetworkDbFunctionsExtensions.GreaterThanOrEqual) => _sqlExpressionFactory.GreaterThanOrEqual(arguments[1], arguments[2]), + nameof(NpgsqlNetworkDbFunctionsExtensions.GreaterThan) => _sqlExpressionFactory.GreaterThan(arguments[1], arguments[2]), + + nameof(NpgsqlNetworkDbFunctionsExtensions.ContainedBy) => BoolReturningOnTwoNetworkTypes("<<"), + nameof(NpgsqlNetworkDbFunctionsExtensions.ContainedByOrEqual) => BoolReturningOnTwoNetworkTypes("<<="), + nameof(NpgsqlNetworkDbFunctionsExtensions.Contains) => BoolReturningOnTwoNetworkTypes(">>"), + nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrEqual) => BoolReturningOnTwoNetworkTypes(">>="), + nameof(NpgsqlNetworkDbFunctionsExtensions.ContainsOrContainedBy) => BoolReturningOnTwoNetworkTypes("&&"), + + nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseNot) => new SqlUnaryExpression(ExpressionType.Not, arguments[1], arguments[1].Type, arguments[1].TypeMapping), - nameof(NpgsqlNetworkExtensions.BitwiseAnd) => _sqlExpressionFactory.And(arguments[1], arguments[2]), - nameof(NpgsqlNetworkExtensions.BitwiseOr) => _sqlExpressionFactory.Or(arguments[1], arguments[2]), + nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseAnd) => _sqlExpressionFactory.And(arguments[1], arguments[2]), + nameof(NpgsqlNetworkDbFunctionsExtensions.BitwiseOr) => _sqlExpressionFactory.Or(arguments[1], arguments[2]), // Add/Subtract accept inet + int, so we can't use the default type mapping inference logic which assumes // same-typed operands - nameof(NpgsqlNetworkExtensions.Add) + nameof(NpgsqlNetworkDbFunctionsExtensions.Add) => new SqlBinaryExpression( ExpressionType.Add, _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]), @@ -89,7 +89,7 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO arguments[1].Type, arguments[1].TypeMapping), - nameof(NpgsqlNetworkExtensions.Subtract) when arguments[2].Type == typeof(int) + nameof(NpgsqlNetworkDbFunctionsExtensions.Subtract) when arguments[2].Type == typeof(int) => new SqlBinaryExpression( ExpressionType.Subtract, _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]), @@ -97,7 +97,7 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO arguments[1].Type, arguments[1].TypeMapping), - nameof(NpgsqlNetworkExtensions.Subtract) + nameof(NpgsqlNetworkDbFunctionsExtensions.Subtract) when arguments[2].Type == typeof(IPAddress) || arguments[2].Type == typeof((IPAddress, int)) => new SqlBinaryExpression( ExpressionType.Subtract, @@ -106,20 +106,20 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO arguments[1].Type, _sqlExpressionFactory.FindMapping(typeof(long))), - nameof(NpgsqlNetworkExtensions.Abbreviate) => NullPropagatingFunction("abbrev", new[] { arguments[1] }, typeof(string)), - nameof(NpgsqlNetworkExtensions.Broadcast) => NullPropagatingFunction("broadcast", new[] { arguments[1] }, typeof(IPAddress), _inetMapping), - nameof(NpgsqlNetworkExtensions.Family) => NullPropagatingFunction("family", new[] { arguments[1] }, typeof(int)), - nameof(NpgsqlNetworkExtensions.Host) => NullPropagatingFunction("host", new[] { arguments[1] }, typeof(string)), - nameof(NpgsqlNetworkExtensions.HostMask) => NullPropagatingFunction("hostmask", new[] { arguments[1] }, typeof(IPAddress), _inetMapping), - nameof(NpgsqlNetworkExtensions.MaskLength) => NullPropagatingFunction("masklen", new[] { arguments[1] }, typeof(int)), - nameof(NpgsqlNetworkExtensions.Netmask) => NullPropagatingFunction("netmask", new[] { arguments[1] }, typeof(IPAddress), _inetMapping), - nameof(NpgsqlNetworkExtensions.Network) => NullPropagatingFunction("network", new[] { arguments[1] }, typeof((IPAddress Address, int Subnet)), _cidrMapping), - nameof(NpgsqlNetworkExtensions.SetMaskLength) => NullPropagatingFunction("set_masklen", new[] { arguments[1], arguments[2] }, arguments[1].Type, arguments[1].TypeMapping), - nameof(NpgsqlNetworkExtensions.Text) => NullPropagatingFunction("text", new[] { arguments[1] }, typeof(string)), - nameof(NpgsqlNetworkExtensions.SameFamily) => NullPropagatingFunction("inet_same_family", new[] { arguments[1], arguments[2] }, typeof(bool)), - nameof(NpgsqlNetworkExtensions.Merge) => NullPropagatingFunction("inet_merge", new[] { arguments[1], arguments[2] }, typeof((IPAddress Address, int Subnet)), _cidrMapping), - nameof(NpgsqlNetworkExtensions.Truncate) => NullPropagatingFunction("trunc", new[] { arguments[1] }, typeof(PhysicalAddress), arguments[1].TypeMapping), - nameof(NpgsqlNetworkExtensions.Set7BitMac8) => NullPropagatingFunction("macaddr8_set7bit", new[] { arguments[1] }, typeof(PhysicalAddress), _macaddr8Mapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.Abbreviate) => NullPropagatingFunction("abbrev", new[] { arguments[1] }, typeof(string)), + nameof(NpgsqlNetworkDbFunctionsExtensions.Broadcast) => NullPropagatingFunction("broadcast", new[] { arguments[1] }, typeof(IPAddress), _inetMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.Family) => NullPropagatingFunction("family", new[] { arguments[1] }, typeof(int)), + nameof(NpgsqlNetworkDbFunctionsExtensions.Host) => NullPropagatingFunction("host", new[] { arguments[1] }, typeof(string)), + nameof(NpgsqlNetworkDbFunctionsExtensions.HostMask) => NullPropagatingFunction("hostmask", new[] { arguments[1] }, typeof(IPAddress), _inetMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.MaskLength) => NullPropagatingFunction("masklen", new[] { arguments[1] }, typeof(int)), + nameof(NpgsqlNetworkDbFunctionsExtensions.Netmask) => NullPropagatingFunction("netmask", new[] { arguments[1] }, typeof(IPAddress), _inetMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.Network) => NullPropagatingFunction("network", new[] { arguments[1] }, typeof((IPAddress Address, int Subnet)), _cidrMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.SetMaskLength) => NullPropagatingFunction("set_masklen", new[] { arguments[1], arguments[2] }, arguments[1].Type, arguments[1].TypeMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.Text) => NullPropagatingFunction("text", new[] { arguments[1] }, typeof(string)), + nameof(NpgsqlNetworkDbFunctionsExtensions.SameFamily) => NullPropagatingFunction("inet_same_family", new[] { arguments[1], arguments[2] }, typeof(bool)), + nameof(NpgsqlNetworkDbFunctionsExtensions.Merge) => NullPropagatingFunction("inet_merge", new[] { arguments[1], arguments[2] }, typeof((IPAddress Address, int Subnet)), _cidrMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.Truncate) => NullPropagatingFunction("trunc", new[] { arguments[1] }, typeof(PhysicalAddress), arguments[1].TypeMapping), + nameof(NpgsqlNetworkDbFunctionsExtensions.Set7BitMac8) => NullPropagatingFunction("macaddr8_set7bit", new[] { arguments[1] }, typeof(PhysicalAddress), _macaddr8Mapping), _ => (SqlExpression)null }; diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs index 24e7f2db7..ea6d5adcc 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs @@ -37,10 +37,10 @@ public NpgsqlRangeTranslator(ISqlExpressionFactory sqlExpressionFactory) [CanBeNull] public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) { - if (method.DeclaringType != typeof(NpgsqlRangeExtensions)) + if (method.DeclaringType != typeof(NpgsqlRangeDbFunctionsExtensions)) return null; - if (method.Name == nameof(NpgsqlRangeExtensions.Merge)) + if (method.Name == nameof(NpgsqlRangeDbFunctionsExtensions.Merge)) { var inferredMapping = ExpressionExtensions.InferTypeMapping(arguments[0], arguments[1]); return _sqlExpressionFactory.Function( @@ -57,10 +57,10 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO return method.Name switch { - nameof(NpgsqlRangeExtensions.Contains) when arguments[0].Type == arguments[1].Type => BoolReturningOnTwoRanges("@>"), + nameof(NpgsqlRangeDbFunctionsExtensions.Contains) when arguments[0].Type == arguments[1].Type => BoolReturningOnTwoRanges("@>"), // Default to element contained in range - nameof(NpgsqlRangeExtensions.Contains) => + nameof(NpgsqlRangeDbFunctionsExtensions.Contains) => new SqlCustomBinaryExpression( _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), // TODO: Infer the range mapping from the subtype's... arguments[0].TypeMapping is NpgsqlRangeTypeMapping rangeMapping @@ -70,17 +70,17 @@ arguments[0].TypeMapping is NpgsqlRangeTypeMapping rangeMapping typeof(bool), _boolMapping), - nameof(NpgsqlRangeExtensions.ContainedBy) => BoolReturningOnTwoRanges("<@"), - nameof(NpgsqlRangeExtensions.Overlaps) => BoolReturningOnTwoRanges("&&"), - nameof(NpgsqlRangeExtensions.IsStrictlyLeftOf) => BoolReturningOnTwoRanges("<<"), - nameof(NpgsqlRangeExtensions.IsStrictlyRightOf) => BoolReturningOnTwoRanges(">>"), - nameof(NpgsqlRangeExtensions.DoesNotExtendRightOf) => BoolReturningOnTwoRanges("&<"), - nameof(NpgsqlRangeExtensions.DoesNotExtendLeftOf) => BoolReturningOnTwoRanges("&>"), - nameof(NpgsqlRangeExtensions.IsAdjacentTo) => BoolReturningOnTwoRanges("-|-"), - - nameof(NpgsqlRangeExtensions.Union) => RangeReturningOnTwoRanges("+"), - nameof(NpgsqlRangeExtensions.Intersect) => RangeReturningOnTwoRanges("*"), - nameof(NpgsqlRangeExtensions.Except) => RangeReturningOnTwoRanges("-"), + nameof(NpgsqlRangeDbFunctionsExtensions.ContainedBy) => BoolReturningOnTwoRanges("<@"), + nameof(NpgsqlRangeDbFunctionsExtensions.Overlaps) => BoolReturningOnTwoRanges("&&"), + nameof(NpgsqlRangeDbFunctionsExtensions.IsStrictlyLeftOf) => BoolReturningOnTwoRanges("<<"), + nameof(NpgsqlRangeDbFunctionsExtensions.IsStrictlyRightOf) => BoolReturningOnTwoRanges(">>"), + nameof(NpgsqlRangeDbFunctionsExtensions.DoesNotExtendRightOf) => BoolReturningOnTwoRanges("&<"), + nameof(NpgsqlRangeDbFunctionsExtensions.DoesNotExtendLeftOf) => BoolReturningOnTwoRanges("&>"), + nameof(NpgsqlRangeDbFunctionsExtensions.IsAdjacentTo) => BoolReturningOnTwoRanges("-|-"), + + nameof(NpgsqlRangeDbFunctionsExtensions.Union) => RangeReturningOnTwoRanges("+"), + nameof(NpgsqlRangeDbFunctionsExtensions.Intersect) => RangeReturningOnTwoRanges("*"), + nameof(NpgsqlRangeDbFunctionsExtensions.Except) => RangeReturningOnTwoRanges("-"), _ => null }; diff --git a/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs index 0c73d2d1f..3e7600aca 100644 --- a/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs @@ -12,14 +12,38 @@ public FromSqlQueryNpgsqlTest(NorthwindQueryNpgsqlFixture f { } - [Fact(Skip = "https://github.com/aspnet/EntityFramework/issues/6563")] + [Fact(Skip = "https://github.com/aspnet/EntityFramework/issues/{6563,20364}")] public override void Bad_data_error_handling_invalid_cast() {} - [Fact(Skip = "https://github.com/aspnet/EntityFramework/issues/6563")] + [Fact(Skip = "https://github.com/aspnet/EntityFramework/issues/{6563,20364}")] public override void Bad_data_error_handling_invalid_cast_projection() {} [Fact(Skip="https://github.com/aspnet/EntityFrameworkCore/pull/15423")] public override void FromSqlRaw_does_not_parameterize_interpolated_string() {} + [ConditionalFact(Skip = "https://github.com/dotnet/efcore/issues/20364")] + public override void Bad_data_error_handling_invalid_cast_key() + => base.Bad_data_error_handling_invalid_cast_key(); + + [ConditionalFact(Skip = "https://github.com/dotnet/efcore/issues/20364")] + public override void Bad_data_error_handling_invalid_cast_no_tracking() + => base.Bad_data_error_handling_invalid_cast_no_tracking(); + + [ConditionalFact(Skip = "https://github.com/dotnet/efcore/issues/20364")] + public override void Bad_data_error_handling_null() + => base.Bad_data_error_handling_null(); + + [ConditionalFact(Skip = "https://github.com/dotnet/efcore/issues/20364")] + public override void Bad_data_error_handling_null_no_tracking() + => base.Bad_data_error_handling_null_no_tracking(); + + [ConditionalFact(Skip = "https://github.com/dotnet/efcore/issues/20364")] + public override void Bad_data_error_handling_null_projection() + => base.Bad_data_error_handling_null_projection(); + + [ConditionalFact(Skip = "https://github.com/dotnet/efcore/issues/20364")] + public override void FromSqlRaw_queryable_simple_columns_out_of_order_and_not_enough_columns_throws() + => base.FromSqlRaw_queryable_simple_columns_out_of_order_and_not_enough_columns_throws(); + protected override DbParameter CreateDbParameter(string name, object value) => new NpgsqlParameter { diff --git a/test/EFCore.PG.FunctionalTests/Query/FullTextSearchDbFunctionsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/FullTextSearchDbFunctionsNpgsqlTest.cs index 8b34c2cf1..6c720b8b6 100644 --- a/test/EFCore.PG.FunctionalTests/Query/FullTextSearchDbFunctionsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/FullTextSearchDbFunctionsNpgsqlTest.cs @@ -53,7 +53,7 @@ public void ArrayToTsVector_From_Columns_Throws_NotSupportedException() { using var context = CreateContext(); - Assert.Throws( + Assert.Throws( () => context.Customers .Select(c => EF.Functions.ArrayToTsVector(new[] { c.CompanyName, c.Address })) .First()); diff --git a/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs b/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs index 2d9b4a64d..d95923d9e 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NavigationTest.cs @@ -26,11 +26,11 @@ public void Duplicate_entries_are_not_created_for_navigations_to_principal() var entityType = model.GetEntityTypes().First(); Assert.Equal( - "ForeignKey: GoTPerson {'LoverId'} -> GoTPerson {'Id'} Unique ToDependent: LoverReverse ToPrincipal: Lover", + "ForeignKey: GoTPerson {'LoverId'} -> GoTPerson {'Id'} Unique ToDependent: LoverReverse ToPrincipal: Lover ClientSetNull", entityType.GetForeignKeys().First().ToString()); Assert.Equal( - "ForeignKey: GoTPerson {'SiblingReverseId'} -> GoTPerson {'Id'} ToDependent: Siblings ToPrincipal: SiblingReverse", + "ForeignKey: GoTPerson {'SiblingReverseId'} -> GoTPerson {'Id'} ToDependent: Siblings ToPrincipal: SiblingReverse ClientSetNull", entityType.GetForeignKeys().Skip(1).First().ToString()); } @@ -50,11 +50,11 @@ public void Duplicate_entries_are_not_created_for_navigations_to_dependant() var entityType = model.GetEntityTypes().First(); Assert.Equal( - "ForeignKey: GoTPerson {'LoverId'} -> GoTPerson {'Id'} Unique ToDependent: LoverReverse ToPrincipal: Lover", + "ForeignKey: GoTPerson {'LoverId'} -> GoTPerson {'Id'} Unique ToDependent: LoverReverse ToPrincipal: Lover ClientSetNull", entityType.GetForeignKeys().First().ToString()); Assert.Equal( - "ForeignKey: GoTPerson {'SiblingReverseId'} -> GoTPerson {'Id'} ToDependent: Siblings ToPrincipal: SiblingReverse", + "ForeignKey: GoTPerson {'SiblingReverseId'} -> GoTPerson {'Id'} ToDependent: Siblings ToPrincipal: SiblingReverse ClientSetNull", entityType.GetForeignKeys().Skip(1).First().ToString()); } diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs index c04e54b53..45554ee30 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs @@ -134,12 +134,17 @@ await AssertQuery( [MemberData(nameof(IsAsyncData))] public async Task Array_Any_Like(bool async) { + using var context = CreateContext(); + var collection = new[] { "A%", "B%", "C%" }; + var query = context.Set().Where(c => collection.Any(y => EF.Functions.Like(c.Address, y))); + var result = async ? await query.ToListAsync() : query.ToList(); - await AssertQuery( - async, - ss => ss.Set().Where(c => collection.Any(y => EF.Functions.Like(c.Address, y))), - entryCount: 22); + Assert.Equal(new[] + { + "ANATR", "BERGS", "BOLID", "CACTU", "COMMI", "CONSH", "FISSA", "FRANK", "GODOS", "GOURL", "HILAA", + "HUNGC", "LILAS", "LINOD", "PERIC", "QUEEN", "RANCH", "RICAR", "SUPRD", "TORTU", "TRADH", "WANDK" + }, result.Select(e => e.CustomerID)); AssertSql( @"@__collection_0='System.String[]' (DbType = Object) @@ -153,11 +158,13 @@ await AssertQuery( [MemberData(nameof(IsAsyncData))] public async Task Array_All_Like(bool async) { + using var context = CreateContext(); + var collection = new[] { "A%", "B%", "C%" }; + var query = context.Set().Where(c => collection.All(y => EF.Functions.Like(c.Address, y))); + var result = async ? await query.ToListAsync() : query.ToList(); - await AssertQuery( - async, - ss => ss.Set().Where(c => collection.All(y => EF.Functions.Like(c.Address, y)))); + Assert.Empty(result); AssertSql( @"@__collection_0='System.String[]' (DbType = Object) @@ -171,12 +178,17 @@ await AssertQuery( [MemberData(nameof(IsAsyncData))] public async Task Array_Any_ILike(bool async) { + using var context = CreateContext(); + var collection = new[] { "a%", "b%", "c%" }; + var query = context.Set().Where(c => collection.Any(y => EF.Functions.ILike(c.Address, y))); + var result = async ? await query.ToListAsync() : query.ToList(); - await AssertQuery( - async, - ss => ss.Set().Where(c => collection.Any(y => EF.Functions.ILike(c.Address, y))), - entryCount: 22); + Assert.Equal(new[] + { + "ANATR", "BERGS", "BOLID", "CACTU", "COMMI", "CONSH", "FISSA", "FRANK", "GODOS", "GOURL", "HILAA", + "HUNGC", "LILAS", "LINOD", "PERIC", "QUEEN", "RANCH", "RICAR", "SUPRD", "TORTU", "TRADH", "WANDK" + }, result.Select(e => e.CustomerID)); AssertSql( @"@__collection_0='System.String[]' (DbType = Object) @@ -190,11 +202,13 @@ await AssertQuery( [MemberData(nameof(IsAsyncData))] public async Task Array_All_ILike(bool async) { + using var context = CreateContext(); + var collection = new[] { "a%", "b%", "c%" }; + var query = context.Set().Where(c => collection.All(y => EF.Functions.ILike(c.Address, y))); + var result = async ? await query.ToListAsync() : query.ToList(); - await AssertQuery( - async, - ss => ss.Set().Where(c => collection.All(y => EF.Functions.ILike(c.Address, y)))); + Assert.Empty(result); AssertSql( @"@__collection_0='System.String[]' (DbType = Object) diff --git a/test/EFCore.PG.Tests/NpgsqlDbFunctionsTest.cs b/test/EFCore.PG.Tests/NpgsqlDbFunctionsTest.cs deleted file mode 100644 index 63a2047ec..000000000 --- a/test/EFCore.PG.Tests/NpgsqlDbFunctionsTest.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Xunit; - -// ReSharper disable InconsistentNaming - -namespace Npgsql.EntityFrameworkCore.PostgreSQL -{ - public class NpgsqlDbFunctionsTest - { - readonly DbFunctions _functions = EF.Functions; - - [Fact] - public void ILike_when_no_wildcards() - { - Assert.True(_functions.ILike("abc", "abc")); - Assert.True(_functions.ILike("abc", "ABC")); - Assert.True(_functions.ILike("ABC", "abc")); - - Assert.False(_functions.ILike("ABC", "ab")); - Assert.False(_functions.ILike("ab", "abc")); - } - } -}