From fa1c29180ebe198cd265aaf4b47ca33021a2dad5 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Tue, 15 May 2018 11:22:34 -0400 Subject: [PATCH 01/13] Add support for PostgreSQL network operators - cidr - inet - macaddr - macaddr8 --- .../NpgsqlNetworkAddressExtensions.cs | 77 +++++++ .../NpgsqlCompositeMethodCallTranslator.cs | 3 +- .../NpgsqlNetworkAddressTranslator.cs | 115 +++++++++++ .../Query/NetworkAddressQueryNpgsqlFixture.cs | 135 +++++++++++++ .../Query/NetworkAddressQueryNpgsqlTest.cs | 191 ++++++++++++++++++ 5 files changed, 520 insertions(+), 1 deletion(-) create mode 100644 src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs create mode 100644 src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs create mode 100644 test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs create mode 100644 test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs diff --git a/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs new file mode 100644 index 000000000..d51f9ea9d --- /dev/null +++ b/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs @@ -0,0 +1,77 @@ +#region License + +// The PostgreSQL License +// +// Copyright (C) 2016 The Npgsql Development Team +// +// Permission to use, copy, modify, and distribute this software and its +// documentation for any purpose, without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph and the following two paragraphs appear in all copies. +// +// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY +// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, +// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. +// +// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS +// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +#endregion + +using System; +using System.Net; +using NpgsqlTypes; + +namespace Npgsql.EntityFrameworkCore.PostgreSQL +{ + /// + /// Provides extension methods supporting PostgreSQL network address operator translation. + /// + public static class NpgsqlNetworkAddressExtensions + { + /// + /// Determines whether an contains another . + /// + /// The IP address to search. + /// The IP address to locate. + /// + /// true if the contains the other ; otherwise, false. + /// + public static bool Contains(this IPAddress ipAddress, IPAddress other) => throw new NotImplementedException(); + + /// + /// Determines whether an contains another . + /// + /// The inet to search. + /// The inet to locate. + /// + /// true if the contains the other ; otherwise, false. + /// + public static bool Contains(this NpgsqlInet inet, NpgsqlInet other) => throw new NotImplementedException(); + + /// + /// Determines whether an contains or is equal to another . + /// + /// The IP address to search. + /// The IP address to locate. + /// + /// true if the contains or is equal to the other ; otherwise, false. + /// + public static bool ContainsOrEquals(this IPAddress ipAddress, IPAddress other) => throw new NotImplementedException(); + + /// + /// Determines whether an contains or is equal to another . + /// + /// The inet to search. + /// The inet to locate. + /// + /// true if the contains or is equal to the other ; otherwise, false. + /// + public static bool ContainsOrEquals(this NpgsqlInet inet, NpgsqlInet other) => throw new NotImplementedException(); + } +} diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs index 709e65836..d68830d9a 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs @@ -59,7 +59,8 @@ public class NpgsqlCompositeMethodCallTranslator : RelationalCompositeMethodCall new NpgsqlStringTrimStartTranslator(), new NpgsqlRegexIsMatchTranslator(), new NpgsqlFullTextSearchMethodTranslator(), - new NpgsqlRangeTranslator() + new NpgsqlRangeTranslator(), + new NpgsqlNetworkAddressTranslator() }; /// diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs new file mode 100644 index 000000000..fe556563c --- /dev/null +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -0,0 +1,115 @@ +#region License + +// The PostgreSQL License +// +// Copyright (C) 2016 The Npgsql Development Team +// +// Permission to use, copy, modify, and distribute this software and its +// documentation for any purpose, without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph and the following two paragraphs appear in all copies. +// +// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY +// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, +// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. +// +// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS +// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +#endregion + +using System; +using System.Linq.Expressions; +using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; +using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; + +namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal +{ + /// + /// Provides translation services for PostgreSQL network address (inet, cidr) operators. + /// + /// + /// See: https://www.postgresql.org/docs/current/static/functions-net.html + /// + public class NpgsqlNetworkAddressTranslator : IMethodCallTranslator + { + /// + [CanBeNull] + public Expression Translate(MethodCallExpression methodCallExpression) => + TryTranslateOperator(methodCallExpression); + + /// + /// Attempts to translate the as a PostgreSQL network address operator. + /// + /// The to be translated. + /// + /// The expression if successful; otherwise, null. + /// + [CanBeNull] + static Expression TryTranslateOperator([NotNull] MethodCallExpression expression) + { + switch (expression.Method.Name) + { + case nameof(NpgsqlNetworkAddressExtensions.Contains): + return MakeBinaryExpression(expression, ">>", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEquals): + return MakeBinaryExpression(expression, ">>=", typeof(bool)); + +// case nameof(NpgsqlNetworkAddressExtensions.Overlaps): +// return MakeBinaryExpression(expression, "&&", typeof(bool)); +// +// case nameof(NpgsqlNetworkAddressExtensions.IsStrictlyLeftOf): +// return MakeBinaryExpression(expression, "<<", typeof(bool)); +// +// case nameof(NpgsqlNetworkAddressExtensions.IsStrictlyRightOf): +// return MakeBinaryExpression(expression, ">>", typeof(bool)); +// +// case nameof(NpgsqlNetworkAddressExtensions.DoesNotExtendRightOf): +// return MakeBinaryExpression(expression, "&<", typeof(bool)); +// +// case nameof(NpgsqlNetworkAddressExtensions.DoesNotExtendLeftOf): +// return MakeBinaryExpression(expression, "&>", typeof(bool)); +// +// case nameof(NpgsqlNetworkAddressExtensions.IsAdjacentTo): +// return MakeBinaryExpression(expression, "-|-", typeof(bool)); + + default: + return null; + } + } + + /// + /// Constructs a . + /// + /// The containing two parameters. + /// The symbolic operator for PostgreSQL. + /// The return type of the operator. + /// + /// A . + /// + [NotNull] + static Expression MakeBinaryExpression([NotNull] MethodCallExpression expression, [NotNull] string symbol, [NotNull] Type returnType) => + new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], symbol, returnType); + +// [NpgsqlBinaryOperator(Symbol = "<", ReturnType = typeof(bool))] LessThan, +// [NpgsqlBinaryOperator(Symbol = "<=", ReturnType = typeof(bool))] LessThanOrEqual, +// [NpgsqlBinaryOperator(Symbol = "=", ReturnType = typeof(bool))] Equal, +// [NpgsqlBinaryOperator(Symbol = ">=", ReturnType = typeof(bool))] GreaterThanOrEqual, +// [NpgsqlBinaryOperator(Symbol = ">", ReturnType = typeof(bool))] GreaterThan, +// [NpgsqlBinaryOperator(Symbol = "<>", ReturnType = typeof(bool))] NotEqual, +// [NpgsqlBinaryOperator(Symbol = "<<", ReturnType = typeof(bool))] ContainedWithin, +// [NpgsqlBinaryOperator(Symbol = "<<=", ReturnType = typeof(bool))] ContainedWithinOrEquals, +// [NpgsqlBinaryOperator(Symbol = "~", ReturnType = typeof(bool))] Not, +// [NpgsqlBinaryOperator(Symbol = "&", ReturnType = typeof(bool))] And, +// [NpgsqlBinaryOperator(Symbol = "|", ReturnType = typeof(bool))] Or, +// [NpgsqlBinaryOperator(Symbol = "+", ReturnType = typeof(bool))] Addition, +// [NpgsqlBinaryOperator(Symbol = "-", ReturnType = typeof(bool))] Subtraction, + } +} diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs new file mode 100644 index 000000000..b046d2aa0 --- /dev/null +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs @@ -0,0 +1,135 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Net; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; +using NpgsqlTypes; + +namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query +{ + /// + /// Represents a fixture suitable for testing network address operators. + /// + public class NetworkAddressQueryNpgsqlFixture : IDisposable + { + /// + /// The used for testing. + /// + private readonly NpgsqlTestStore _testStore; + + /// + /// The used for testing. + /// + private readonly DbContextOptions _options; + + /// + /// The logger factory used for testing. + /// + public TestSqlLoggerFactory TestSqlLoggerFactory { get; } + + /// + /// Initializes a . + /// + // ReSharper disable once UnusedMember.Global + public NetworkAddressQueryNpgsqlFixture() + { + TestSqlLoggerFactory = new TestSqlLoggerFactory(); + + _testStore = NpgsqlTestStore.CreateScratch(); + + _options = + new DbContextOptionsBuilder() + .UseNpgsql(_testStore.ConnectionString, b => b.ApplyConfiguration()) + .UseInternalServiceProvider( + new ServiceCollection() + .AddEntityFrameworkNpgsql() + .AddSingleton(TestSqlLoggerFactory) + .BuildServiceProvider()) + .Options; + + using (NetContext context = CreateContext()) + { + context.Database.EnsureCreated(); + + context.NetTestEntities + .AddRange( + new NetTestEntity { Id = 1, InetMappedToIPAddress = new IPAddress(1), CidrMappedToNpgsqlInet = new IPAddress(1) }, + new NetTestEntity { Id = 2, InetMappedToIPAddress = new IPAddress(2), CidrMappedToNpgsqlInet = new IPAddress(2) }, + new NetTestEntity { Id = 3, InetMappedToIPAddress = new IPAddress(3), CidrMappedToNpgsqlInet = new IPAddress(3) }, + new NetTestEntity { Id = 4, InetMappedToIPAddress = new IPAddress(4), CidrMappedToNpgsqlInet = new IPAddress(4) }, + new NetTestEntity { Id = 5, InetMappedToIPAddress = new IPAddress(5), CidrMappedToNpgsqlInet = new IPAddress(5) }, + new NetTestEntity { Id = 6, InetMappedToIPAddress = new IPAddress(6), CidrMappedToNpgsqlInet = new IPAddress(6) }, + new NetTestEntity { Id = 7, InetMappedToIPAddress = new IPAddress(7), CidrMappedToNpgsqlInet = new IPAddress(7) }, + new NetTestEntity { Id = 8, InetMappedToIPAddress = new IPAddress(8), CidrMappedToNpgsqlInet = new IPAddress(8) }, + new NetTestEntity { Id = 9, InetMappedToIPAddress = new IPAddress(9), CidrMappedToNpgsqlInet = new IPAddress(9) }, + new NetTestEntity { Id = 10, InetMappedToIPAddress = new IPAddress(10), CidrMappedToNpgsqlInet = new IPAddress(10) }); + + context.SaveChanges(); + } + } + + /// + /// Creates a new . + /// + /// + /// A for testing. + /// + public NetContext CreateContext() + { + return new NetContext(_options); + } + + /// + public void Dispose() + { + _testStore.Dispose(); + } + } + + /// + /// Represents an entity suitable for testing network address operators. + /// + public class NetTestEntity + { + /// + /// The primary key. + /// + [Key] + public int Id { get; set; } + + /// + /// The network address. + /// + [Column(TypeName = "inet")] + public IPAddress InetMappedToIPAddress { get; set; } + + /// + /// The network address. + /// + [Column(TypeName = "cidr")] + public NpgsqlInet CidrMappedToNpgsqlInet { get; set; } + } + + /// + /// Represents a database suitable for testing network address operators. + /// + public class NetContext : DbContext + { + /// + /// Represents a set of entities with properties. + /// + public DbSet NetTestEntities { get; set; } + + /// + /// Initializes a . + /// + /// + /// The options to be used for configuration. + /// + public NetContext(DbContextOptions options) : base(options) { } + } +} diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs new file mode 100644 index 000000000..d9557be76 --- /dev/null +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -0,0 +1,191 @@ +using System.Linq; +using System.Net; +using NpgsqlTypes; +using Xunit; + +namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query +{ + /// + /// Provides unit tests for network address operator translations. + /// + public class NetworkAddressQueryNpgsqlTest : IClassFixture + { + /// + /// Provides resources for unit tests. + /// + NetworkAddressQueryNpgsqlFixture Fixture { get; } + + /// + /// Initializes resources for unit tests. + /// + /// + /// The fixture of resources for testing. + /// + public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) + { + Fixture = fixture; + Fixture.TestSqlLoggerFactory.Clear(); + } + + /// + /// Asserts that the SQL fragment appears in the logs. + /// + /// The SQL statement or fragment to search for in the logs. + public void AssertContainsSql(string sql) + { + Assert.Contains(sql, Fixture.TestSqlLoggerFactory.Sql); + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddressContainsIPAddress() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress address = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => x.InetMappedToIPAddress.Contains(address)) + .ToArray(); + + AssertContainsSql("WHERE x.\"InetMappedToIPAddress\" >> @__address_0"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void NpgsqlInetContainsNpgsqlInet() + { + using (NetContext context = Fixture.CreateContext()) + { + NpgsqlInet npgsqlInet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => x.CidrMappedToNpgsqlInet.Contains(npgsqlInet)) + .ToArray(); + + AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >> @__npgsqlInet_0"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddressDoesNotContainsIPAddress() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress address = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => !x.InetMappedToIPAddress.Contains(address)) + .ToArray(); + + AssertContainsSql("WHERE NOT (x.\"InetMappedToIPAddress\" >> @__address_0 = TRUE)"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void NpgsqlInetDoesNotContainsNpgsqlInet() + { + using (NetContext context = Fixture.CreateContext()) + { + NpgsqlInet npgsqlInet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => !x.CidrMappedToNpgsqlInet.Contains(npgsqlInet)) + .ToArray(); + + AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >> @__npgsqlInet_0 = TRUE)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddressContainsOrEqualsIPAddress() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress address = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => x.InetMappedToIPAddress.ContainsOrEquals(address)) + .ToArray(); + + AssertContainsSql("WHERE x.\"InetMappedToIPAddress\" >>= @__address_0"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void NpgsqlInetContainsOrEqualsNpgsqlInet() + { + using (NetContext context = Fixture.CreateContext()) + { + NpgsqlInet npgsqlInet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => x.CidrMappedToNpgsqlInet.ContainsOrEquals(npgsqlInet)) + .ToArray(); + + AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddressDoesNotContainOrEqualIPAddress() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress address = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => !x.InetMappedToIPAddress.ContainsOrEquals(address)) + .ToArray(); + + AssertContainsSql("WHERE NOT (x.\"InetMappedToIPAddress\" >>= @__address_0 = TRUE)"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void NpgsqlInetDoesNotContainOrEqualNpgsqlInet() + { + using (NetContext context = Fixture.CreateContext()) + { + NpgsqlInet npgsqlInet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => !x.CidrMappedToNpgsqlInet.ContainsOrEquals(npgsqlInet)) + .ToArray(); + + AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0 = TRUE)"); + } + } + } +} From 7c27bb0de443b9e307d4726fbbaa58e52e92f6cd Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Tue, 15 May 2018 13:37:04 -0400 Subject: [PATCH 02/13] Incorporate feedback from range-operators --- .../NpgsqlNetworkAddressTranslator.cs | 50 +----- .../Query/NetworkAddressQueryNpgsqlFixture.cs | 135 -------------- .../Query/NetworkAddressQueryNpgsqlTest.cs | 170 ++++++++++++++++-- 3 files changed, 158 insertions(+), 197 deletions(-) delete mode 100644 test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs index fe556563c..9fea7fbbb 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -23,7 +23,6 @@ #endregion -using System; using System.Linq.Expressions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; @@ -41,63 +40,20 @@ public class NpgsqlNetworkAddressTranslator : IMethodCallTranslator { /// [CanBeNull] - public Expression Translate(MethodCallExpression methodCallExpression) => - TryTranslateOperator(methodCallExpression); - - /// - /// Attempts to translate the as a PostgreSQL network address operator. - /// - /// The to be translated. - /// - /// The expression if successful; otherwise, null. - /// - [CanBeNull] - static Expression TryTranslateOperator([NotNull] MethodCallExpression expression) + public Expression Translate(MethodCallExpression expression) { switch (expression.Method.Name) { case nameof(NpgsqlNetworkAddressExtensions.Contains): - return MakeBinaryExpression(expression, ">>", typeof(bool)); + return new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], ">>", typeof(bool)); case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEquals): - return MakeBinaryExpression(expression, ">>=", typeof(bool)); - -// case nameof(NpgsqlNetworkAddressExtensions.Overlaps): -// return MakeBinaryExpression(expression, "&&", typeof(bool)); -// -// case nameof(NpgsqlNetworkAddressExtensions.IsStrictlyLeftOf): -// return MakeBinaryExpression(expression, "<<", typeof(bool)); -// -// case nameof(NpgsqlNetworkAddressExtensions.IsStrictlyRightOf): -// return MakeBinaryExpression(expression, ">>", typeof(bool)); -// -// case nameof(NpgsqlNetworkAddressExtensions.DoesNotExtendRightOf): -// return MakeBinaryExpression(expression, "&<", typeof(bool)); -// -// case nameof(NpgsqlNetworkAddressExtensions.DoesNotExtendLeftOf): -// return MakeBinaryExpression(expression, "&>", typeof(bool)); -// -// case nameof(NpgsqlNetworkAddressExtensions.IsAdjacentTo): -// return MakeBinaryExpression(expression, "-|-", typeof(bool)); + return new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], ">>=", typeof(bool)); default: return null; } } - - /// - /// Constructs a . - /// - /// The containing two parameters. - /// The symbolic operator for PostgreSQL. - /// The return type of the operator. - /// - /// A . - /// - [NotNull] - static Expression MakeBinaryExpression([NotNull] MethodCallExpression expression, [NotNull] string symbol, [NotNull] Type returnType) => - new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], symbol, returnType); - // [NpgsqlBinaryOperator(Symbol = "<", ReturnType = typeof(bool))] LessThan, // [NpgsqlBinaryOperator(Symbol = "<=", ReturnType = typeof(bool))] LessThanOrEqual, // [NpgsqlBinaryOperator(Symbol = "=", ReturnType = typeof(bool))] Equal, diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs deleted file mode 100644 index b046d2aa0..000000000 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlFixture.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Net; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.TestUtilities; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; -using NpgsqlTypes; - -namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query -{ - /// - /// Represents a fixture suitable for testing network address operators. - /// - public class NetworkAddressQueryNpgsqlFixture : IDisposable - { - /// - /// The used for testing. - /// - private readonly NpgsqlTestStore _testStore; - - /// - /// The used for testing. - /// - private readonly DbContextOptions _options; - - /// - /// The logger factory used for testing. - /// - public TestSqlLoggerFactory TestSqlLoggerFactory { get; } - - /// - /// Initializes a . - /// - // ReSharper disable once UnusedMember.Global - public NetworkAddressQueryNpgsqlFixture() - { - TestSqlLoggerFactory = new TestSqlLoggerFactory(); - - _testStore = NpgsqlTestStore.CreateScratch(); - - _options = - new DbContextOptionsBuilder() - .UseNpgsql(_testStore.ConnectionString, b => b.ApplyConfiguration()) - .UseInternalServiceProvider( - new ServiceCollection() - .AddEntityFrameworkNpgsql() - .AddSingleton(TestSqlLoggerFactory) - .BuildServiceProvider()) - .Options; - - using (NetContext context = CreateContext()) - { - context.Database.EnsureCreated(); - - context.NetTestEntities - .AddRange( - new NetTestEntity { Id = 1, InetMappedToIPAddress = new IPAddress(1), CidrMappedToNpgsqlInet = new IPAddress(1) }, - new NetTestEntity { Id = 2, InetMappedToIPAddress = new IPAddress(2), CidrMappedToNpgsqlInet = new IPAddress(2) }, - new NetTestEntity { Id = 3, InetMappedToIPAddress = new IPAddress(3), CidrMappedToNpgsqlInet = new IPAddress(3) }, - new NetTestEntity { Id = 4, InetMappedToIPAddress = new IPAddress(4), CidrMappedToNpgsqlInet = new IPAddress(4) }, - new NetTestEntity { Id = 5, InetMappedToIPAddress = new IPAddress(5), CidrMappedToNpgsqlInet = new IPAddress(5) }, - new NetTestEntity { Id = 6, InetMappedToIPAddress = new IPAddress(6), CidrMappedToNpgsqlInet = new IPAddress(6) }, - new NetTestEntity { Id = 7, InetMappedToIPAddress = new IPAddress(7), CidrMappedToNpgsqlInet = new IPAddress(7) }, - new NetTestEntity { Id = 8, InetMappedToIPAddress = new IPAddress(8), CidrMappedToNpgsqlInet = new IPAddress(8) }, - new NetTestEntity { Id = 9, InetMappedToIPAddress = new IPAddress(9), CidrMappedToNpgsqlInet = new IPAddress(9) }, - new NetTestEntity { Id = 10, InetMappedToIPAddress = new IPAddress(10), CidrMappedToNpgsqlInet = new IPAddress(10) }); - - context.SaveChanges(); - } - } - - /// - /// Creates a new . - /// - /// - /// A for testing. - /// - public NetContext CreateContext() - { - return new NetContext(_options); - } - - /// - public void Dispose() - { - _testStore.Dispose(); - } - } - - /// - /// Represents an entity suitable for testing network address operators. - /// - public class NetTestEntity - { - /// - /// The primary key. - /// - [Key] - public int Id { get; set; } - - /// - /// The network address. - /// - [Column(TypeName = "inet")] - public IPAddress InetMappedToIPAddress { get; set; } - - /// - /// The network address. - /// - [Column(TypeName = "cidr")] - public NpgsqlInet CidrMappedToNpgsqlInet { get; set; } - } - - /// - /// Represents a database suitable for testing network address operators. - /// - public class NetContext : DbContext - { - /// - /// Represents a set of entities with properties. - /// - public DbSet NetTestEntities { get; set; } - - /// - /// Initializes a . - /// - /// - /// The options to be used for configuration. - /// - public NetContext(DbContextOptions options) : base(options) { } - } -} diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index d9557be76..9dd6e6186 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -1,5 +1,13 @@ -using System.Linq; +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; using System.Net; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; using NpgsqlTypes; using Xunit; @@ -8,7 +16,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query /// /// Provides unit tests for network address operator translations. /// - public class NetworkAddressQueryNpgsqlTest : IClassFixture + public class NetworkAddressQueryNpgsqlTest : IClassFixture { /// /// Provides resources for unit tests. @@ -18,23 +26,14 @@ public class NetworkAddressQueryNpgsqlTest : IClassFixture /// Initializes resources for unit tests. /// - /// - /// The fixture of resources for testing. - /// + /// The fixture of resources for testing. public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) { Fixture = fixture; Fixture.TestSqlLoggerFactory.Clear(); } - /// - /// Asserts that the SQL fragment appears in the logs. - /// - /// The SQL statement or fragment to search for in the logs. - public void AssertContainsSql(string sql) - { - Assert.Contains(sql, Fixture.TestSqlLoggerFactory.Sql); - } + #region Tests /// /// Tests translation for . @@ -97,7 +96,7 @@ public void IPAddressDoesNotContainsIPAddress() /// Tests inverse translation for . /// [Fact] - public void NpgsqlInetDoesNotContainsNpgsqlInet() + public void NpgsqlInetDoesNotContainNpgsqlInet() { using (NetContext context = Fixture.CreateContext()) { @@ -116,7 +115,7 @@ public void NpgsqlInetDoesNotContainsNpgsqlInet() /// Tests translation for . /// [Fact] - public void IPAddressContainsOrEqualsIPAddress() + public void IPAddressContainOrEqualIPAddress() { using (NetContext context = Fixture.CreateContext()) { @@ -187,5 +186,146 @@ public void NpgsqlInetDoesNotContainOrEqualNpgsqlInet() AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0 = TRUE)"); } } + + #endregion + + #region Fixtures + + /// + /// Represents a fixture suitable for testing network address operators. + /// + public class NetworkAddressQueryNpgsqlFixture : IDisposable + { + /// + /// The used for testing. + /// + private readonly NpgsqlTestStore _testStore; + + /// + /// The used for testing. + /// + private readonly DbContextOptions _options; + + /// + /// The logger factory used for testing. + /// + public TestSqlLoggerFactory TestSqlLoggerFactory { get; } + + /// + /// Initializes a . + /// + // ReSharper disable once UnusedMember.Global + public NetworkAddressQueryNpgsqlFixture() + { + TestSqlLoggerFactory = new TestSqlLoggerFactory(); + + _testStore = NpgsqlTestStore.CreateScratch(); + + _options = + new DbContextOptionsBuilder() + .UseNpgsql(_testStore.ConnectionString, b => b.ApplyConfiguration()) + .UseInternalServiceProvider( + new ServiceCollection() + .AddEntityFrameworkNpgsql() + .AddSingleton(TestSqlLoggerFactory) + .BuildServiceProvider()) + .Options; + + using (NetContext context = CreateContext()) + { + context.Database.EnsureCreated(); + + context.NetTestEntities + .AddRange( + new NetTestEntity { Id = 1, InetMappedToIPAddress = new IPAddress(1), CidrMappedToNpgsqlInet = new IPAddress(1) }, + new NetTestEntity { Id = 2, InetMappedToIPAddress = new IPAddress(2), CidrMappedToNpgsqlInet = new IPAddress(2) }, + new NetTestEntity { Id = 3, InetMappedToIPAddress = new IPAddress(3), CidrMappedToNpgsqlInet = new IPAddress(3) }, + new NetTestEntity { Id = 4, InetMappedToIPAddress = new IPAddress(4), CidrMappedToNpgsqlInet = new IPAddress(4) }, + new NetTestEntity { Id = 5, InetMappedToIPAddress = new IPAddress(5), CidrMappedToNpgsqlInet = new IPAddress(5) }, + new NetTestEntity { Id = 6, InetMappedToIPAddress = new IPAddress(6), CidrMappedToNpgsqlInet = new IPAddress(6) }, + new NetTestEntity { Id = 7, InetMappedToIPAddress = new IPAddress(7), CidrMappedToNpgsqlInet = new IPAddress(7) }, + new NetTestEntity { Id = 8, InetMappedToIPAddress = new IPAddress(8), CidrMappedToNpgsqlInet = new IPAddress(8) }, + new NetTestEntity { Id = 9, InetMappedToIPAddress = new IPAddress(9), CidrMappedToNpgsqlInet = new IPAddress(9) }, + new NetTestEntity { Id = 10, InetMappedToIPAddress = new IPAddress(10), CidrMappedToNpgsqlInet = new IPAddress(10) }); + + context.SaveChanges(); + } + } + + /// + /// Creates a new . + /// + /// + /// A for testing. + /// + public NetContext CreateContext() + { + return new NetContext(_options); + } + + /// + public void Dispose() + { + _testStore.Dispose(); + } + } + + /// + /// Represents an entity suitable for testing network address operators. + /// + public class NetTestEntity + { + /// + /// The primary key. + /// + [Key] + public int Id { get; set; } + + /// + /// The network address. + /// + [Column(TypeName = "inet")] + public IPAddress InetMappedToIPAddress { get; set; } + + /// + /// The network address. + /// + [Column(TypeName = "cidr")] + public NpgsqlInet CidrMappedToNpgsqlInet { get; set; } + } + + /// + /// Represents a database suitable for testing network address operators. + /// + public class NetContext : DbContext + { + /// + /// Represents a set of entities with properties. + /// + public DbSet NetTestEntities { get; set; } + + /// + /// Initializes a . + /// + /// + /// The options to be used for configuration. + /// + public NetContext(DbContextOptions options) : base(options) { } + } + + #endregion + + #region Helpers + + /// + /// Asserts that the SQL fragment appears in the logs. + /// + /// The SQL statement or fragment to search for in the logs. + public void AssertContainsSql(string sql) + { + Assert.Contains(sql, Fixture.TestSqlLoggerFactory.Sql); + } + + #endregion } } From eb2269ad4072a201619276314c085152829859a2 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Wed, 16 May 2018 22:37:56 -0400 Subject: [PATCH 03/13] Add test to show value param duplication - Also some weird SQL being generated. --- .../Query/NetworkAddressQueryNpgsqlTest.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index 9dd6e6186..76029f399 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -187,6 +187,27 @@ public void NpgsqlInetDoesNotContainOrEqualNpgsqlInet() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void Demonstrate_ValueTypeParametersAreDuplicated() + { + using (NetContext context = Fixture.CreateContext()) + { + NpgsqlInet npgsqlInet = new IPAddress(0); + + bool[] _ = + context.NetTestEntities + .Where(x => x.CidrMappedToNpgsqlInet.ContainsOrEquals(npgsqlInet)) + .Select(x => x.CidrMappedToNpgsqlInet.Equals(npgsqlInet)) + .ToArray(); + + AssertContainsSql("SELECT x.\"CidrMappedToNpgsqlInet\" = @__npgsqlInet_0"); + AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); + } + } + #endregion #region Fixtures From 0b6b635dddf3056e2972f067ecf2c7fcb9454612 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Wed, 16 May 2018 23:49:22 -0400 Subject: [PATCH 04/13] Update namespaces and overloads - Updated namespaces in extensions to match style. - Changed network extensions to use DbFunctions per #407. - Added XML docs to indicate these extensionss throw outside of EF Core. --- .../Extensions/NpgsqlRangeExtensions.cs | 36 +++++++++ .../NpgsqlNetworkAddressExtensions.cs | 28 +++++-- .../Query/NetworkAddressQueryNpgsqlTest.cs | 74 +++++++++---------- 3 files changed, 96 insertions(+), 42 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs index 8f3821c90..3bdf2688a 100644 --- a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs @@ -43,6 +43,9 @@ public static class NpgsqlRangeExtensions /// /// true if the range contains the specified value; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -54,6 +57,9 @@ public static class NpgsqlRangeExtensions /// /// true if the range contains the specified range; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -65,6 +71,9 @@ public static class NpgsqlRangeExtensions /// /// true if the range contains the specified range; otherwise, false. /// + /// + /// This 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) where T : IComparable => b.Contains(a); /// @@ -76,6 +85,9 @@ public static class NpgsqlRangeExtensions /// /// true if the ranges overlap (share points in common); otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -87,6 +99,9 @@ public static class NpgsqlRangeExtensions /// /// true if the first range is strictly to the left of the second; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -98,6 +113,9 @@ public static class NpgsqlRangeExtensions /// /// true if the first range is strictly to the right of the second; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -109,6 +127,9 @@ public static class NpgsqlRangeExtensions /// /// true if the first range does not extend to the left of the second; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -120,6 +141,9 @@ public static class NpgsqlRangeExtensions /// /// true if the first range does not extend to the right of the second; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -131,6 +155,9 @@ public static class NpgsqlRangeExtensions /// /// true if the ranges are adjacent; otherwise, false. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -142,6 +169,9 @@ public static class NpgsqlRangeExtensions /// /// The unique elements that appear in either range. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -153,6 +183,9 @@ public static class NpgsqlRangeExtensions /// /// The elements that appear in both ranges. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); /// @@ -164,6 +197,9 @@ public static class NpgsqlRangeExtensions /// /// The elements that appear in the first range, but not the second range. /// + /// + /// This 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) where T : IComparable => throw new NotSupportedException(); } } diff --git a/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs index d51f9ea9d..12ae0cef2 100644 --- a/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs +++ b/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs @@ -25,9 +25,11 @@ using System; using System.Net; +using JetBrains.Annotations; using NpgsqlTypes; -namespace Npgsql.EntityFrameworkCore.PostgreSQL +// ReSharper disable once CheckNamespace +namespace Microsoft.EntityFrameworkCore { /// /// Provides extension methods supporting PostgreSQL network address operator translation. @@ -37,41 +39,57 @@ public static class NpgsqlNetworkAddressExtensions /// /// Determines whether an contains another . /// + /// The DbFunctions instance. /// The IP address to search. /// The IP address to locate. /// /// true if the contains the other ; otherwise, false. /// - public static bool Contains(this IPAddress ipAddress, IPAddress other) => throw new NotImplementedException(); + /// + /// 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 _, [CanBeNull] IPAddress ipAddress, [CanBeNull] IPAddress other) => throw new NotSupportedException(); /// /// Determines whether an contains another . /// + /// The DbFunctions instance. /// The inet to search. /// The inet to locate. /// /// true if the contains the other ; otherwise, false. /// - public static bool Contains(this NpgsqlInet inet, NpgsqlInet other) => throw new NotImplementedException(); + /// + /// 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 _, NpgsqlInet inet, NpgsqlInet other) => throw new NotSupportedException(); /// /// Determines whether an contains or is equal to another . /// + /// The DbFunctions instance. /// The IP address to search. /// The IP address to locate. /// /// true if the contains or is equal to the other ; otherwise, false. /// - public static bool ContainsOrEquals(this IPAddress ipAddress, IPAddress other) => throw new NotImplementedException(); + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool ContainsOrEquals([CanBeNull] this DbFunctions _, [CanBeNull] IPAddress ipAddress, [CanBeNull] IPAddress other) => throw new NotSupportedException(); /// /// Determines whether an contains or is equal to another . /// + /// The DbFunctions instance. /// The inet to search. /// The inet to locate. /// /// true if the contains or is equal to the other ; otherwise, false. /// - public static bool ContainsOrEquals(this NpgsqlInet inet, NpgsqlInet other) => throw new NotImplementedException(); + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool ContainsOrEquals([CanBeNull] this DbFunctions _, NpgsqlInet inet, NpgsqlInet other) => throw new NotSupportedException(); } } diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index 76029f399..71543694e 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -36,7 +36,28 @@ public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) #region Tests /// - /// Tests translation for . + /// Demonstrates parameter duplication. + /// + [Fact(Skip = nameof(NetworkAddressQueryNpgsqlTest))] + public void Demonstrate_ValueTypeParametersAreDuplicated() + { + using (NetContext context = Fixture.CreateContext()) + { + NpgsqlInet npgsqlInet = new IPAddress(0); + + bool[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainsOrEquals(x.CidrMappedToNpgsqlInet, npgsqlInet)) + .Select(x => x.CidrMappedToNpgsqlInet.Equals(npgsqlInet)) + .ToArray(); + + AssertContainsSql("SELECT x.\"CidrMappedToNpgsqlInet\" = @__npgsqlInet_0"); + AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); + } + } + + /// + /// Tests translation for . /// [Fact] public void IPAddressContainsIPAddress() @@ -47,7 +68,7 @@ public void IPAddressContainsIPAddress() NetTestEntity[] _ = context.NetTestEntities - .Where(x => x.InetMappedToIPAddress.Contains(address)) + .Where(x => EF.Functions.Contains(x.InetMappedToIPAddress, address)) .ToArray(); AssertContainsSql("WHERE x.\"InetMappedToIPAddress\" >> @__address_0"); @@ -55,7 +76,7 @@ public void IPAddressContainsIPAddress() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void NpgsqlInetContainsNpgsqlInet() @@ -66,7 +87,7 @@ public void NpgsqlInetContainsNpgsqlInet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => x.CidrMappedToNpgsqlInet.Contains(npgsqlInet)) + .Where(x => EF.Functions.Contains(x.CidrMappedToNpgsqlInet, npgsqlInet)) .ToArray(); AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >> @__npgsqlInet_0"); @@ -74,7 +95,7 @@ public void NpgsqlInetContainsNpgsqlInet() } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] public void IPAddressDoesNotContainsIPAddress() @@ -85,7 +106,7 @@ public void IPAddressDoesNotContainsIPAddress() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !x.InetMappedToIPAddress.Contains(address)) + .Where(x => !EF.Functions.Contains(x.InetMappedToIPAddress, address)) .ToArray(); AssertContainsSql("WHERE NOT (x.\"InetMappedToIPAddress\" >> @__address_0 = TRUE)"); @@ -93,7 +114,7 @@ public void IPAddressDoesNotContainsIPAddress() } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] public void NpgsqlInetDoesNotContainNpgsqlInet() @@ -104,7 +125,7 @@ public void NpgsqlInetDoesNotContainNpgsqlInet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !x.CidrMappedToNpgsqlInet.Contains(npgsqlInet)) + .Where(x => !EF.Functions.Contains(x.CidrMappedToNpgsqlInet, npgsqlInet)) .ToArray(); AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >> @__npgsqlInet_0 = TRUE)"); @@ -112,7 +133,7 @@ public void NpgsqlInetDoesNotContainNpgsqlInet() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddressContainOrEqualIPAddress() @@ -123,7 +144,7 @@ public void IPAddressContainOrEqualIPAddress() NetTestEntity[] _ = context.NetTestEntities - .Where(x => x.InetMappedToIPAddress.ContainsOrEquals(address)) + .Where(x => EF.Functions.ContainsOrEquals(x.InetMappedToIPAddress, address)) .ToArray(); AssertContainsSql("WHERE x.\"InetMappedToIPAddress\" >>= @__address_0"); @@ -131,7 +152,7 @@ public void IPAddressContainOrEqualIPAddress() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void NpgsqlInetContainsOrEqualsNpgsqlInet() @@ -142,7 +163,7 @@ public void NpgsqlInetContainsOrEqualsNpgsqlInet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => x.CidrMappedToNpgsqlInet.ContainsOrEquals(npgsqlInet)) + .Where(x => EF.Functions.ContainsOrEquals(x.CidrMappedToNpgsqlInet, npgsqlInet)) .ToArray(); AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); @@ -150,7 +171,7 @@ public void NpgsqlInetContainsOrEqualsNpgsqlInet() } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] public void IPAddressDoesNotContainOrEqualIPAddress() @@ -161,7 +182,7 @@ public void IPAddressDoesNotContainOrEqualIPAddress() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !x.InetMappedToIPAddress.ContainsOrEquals(address)) + .Where(x => !EF.Functions.ContainsOrEquals(x.InetMappedToIPAddress, address)) .ToArray(); AssertContainsSql("WHERE NOT (x.\"InetMappedToIPAddress\" >>= @__address_0 = TRUE)"); @@ -169,7 +190,7 @@ public void IPAddressDoesNotContainOrEqualIPAddress() } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] public void NpgsqlInetDoesNotContainOrEqualNpgsqlInet() @@ -180,34 +201,13 @@ public void NpgsqlInetDoesNotContainOrEqualNpgsqlInet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !x.CidrMappedToNpgsqlInet.ContainsOrEquals(npgsqlInet)) + .Where(x => !EF.Functions.ContainsOrEquals(x.CidrMappedToNpgsqlInet, npgsqlInet)) .ToArray(); AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0 = TRUE)"); } } - /// - /// Tests inverse translation for . - /// - [Fact] - public void Demonstrate_ValueTypeParametersAreDuplicated() - { - using (NetContext context = Fixture.CreateContext()) - { - NpgsqlInet npgsqlInet = new IPAddress(0); - - bool[] _ = - context.NetTestEntities - .Where(x => x.CidrMappedToNpgsqlInet.ContainsOrEquals(npgsqlInet)) - .Select(x => x.CidrMappedToNpgsqlInet.Equals(npgsqlInet)) - .ToArray(); - - AssertContainsSql("SELECT x.\"CidrMappedToNpgsqlInet\" = @__npgsqlInet_0"); - AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); - } - } - #endregion #region Fixtures From ac00e7ead48c2e1c1a9b5a6fac43e3c38a61a25e Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Thu, 24 May 2018 13:36:37 -0400 Subject: [PATCH 05/13] Retarget cidr from NpgsqlInet to ValueTuple - Updates: - Completed NpgsqlNetworkAddressTranslator switch. - Completed NpgsqlNetworkAddressExtensions for inet-inet and cidr-cidr. - Added ClientEvaluationNotSupportedException to throw from provider-specific extension methods. - TODO: - Add non-operators for inet and cidr (i.e. functions). - Problems: - Adding entities that have a tuple throws an exception related to a binary equality operator? --- .../NpgsqlNetworkAddressExtensions.cs | 485 ++++++++++++++++++ .../Extensions/NpgsqlRangeExtensions.cs | 70 +-- .../NpgsqlNetworkAddressExtensions.cs | 95 ---- .../NpgsqlNetworkAddressTranslator.cs | 62 ++- .../Mapping/NpgsqlNetworkTypeMappings.cs | 14 +- .../ClientEvaluationNotSupportedException.cs | 48 ++ .../Query/NetworkAddressQueryNpgsqlTest.cs | 114 ++-- 7 files changed, 677 insertions(+), 211 deletions(-) create mode 100644 src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs delete mode 100644 src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs create mode 100644 src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs new file mode 100644 index 000000000..5560a9af6 --- /dev/null +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs @@ -0,0 +1,485 @@ +#region License + +// The PostgreSQL License +// +// Copyright (C) 2016 The Npgsql Development Team +// +// Permission to use, copy, modify, and distribute this software and its +// documentation for any purpose, without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph and the following two paragraphs appear in all copies. +// +// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY +// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, +// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. +// +// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS +// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +#endregion + +using System.Net; +using JetBrains.Annotations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities; + +// ReSharper disable once CheckNamespace +namespace Microsoft.EntityFrameworkCore +{ + /// + /// Provides extension methods supporting PostgreSQL network address operator translation. + /// + [PublicAPI] + public static class NpgsqlNetworkAddressExtensions + { + /// + /// Determines whether an contains another . + /// + /// The instance. + /// The IP address to search. + /// The IP address to locate. + /// + /// True if the contains the other ; otherwise, false. + /// + /// + /// 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 ipAddress, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to search. + /// The cidr to locate. + /// + /// True if the (IPAddress Address, int Subnet) contains the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an contains or is equal to another . + /// + /// The instance. + /// The IP address to search. + /// The IP address to locate. + /// + /// True if the contains or is equal to the other ; otherwise, false. + /// + /// + /// 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 ipAddress, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to search. + /// The cidr to locate. + /// + /// True if the (IPAddress Address, int Subnet) contains or is equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is less than another . + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// True if the is less than the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is less than another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// True if the (IPAddress Address, int Subnet) is less than the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is less than or equal to another . + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// True if the is less than or equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is less than or equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// True if the (IPAddress Address, int Subnet) is less than or equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is equal to another . + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// True if the is equal to the other ; otherwise, false. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool Equal([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// True if the (IPAddress Address, int Subnet) is equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is greater than or equal to another . + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// True if the is greater than or equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is greater than or equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// True if the (IPAddress Address, int Subnet) is greater than or equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is greater than another . + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// True if the is greater than the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is greater than another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// True if the (IPAddress Address, int Subnet) is greater than the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is not equal to another . + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// True if the is not equal to the other ; otherwise, false. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool NotEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is not equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// True if the IPAddress Address, int Subnet) is not equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is contained within another . + /// + /// The instance. + /// The inet to locate. + /// The inet to search. + /// + /// True if the is contained within the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is contained within another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to locate. + /// The cidr to search. + /// + /// True if the (IPAddress Address, int Subnet) is contained within the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is contained within or equal to another . + /// + /// The instance. + /// The inet to locate. + /// The inet to search. + /// + /// True if the is contained within or equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) is contained within or equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to locate. + /// The cidr to search. + /// + /// True if the (IPAddress Address, int Subnet) is contained within or equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Computes the bitwise NOT operation on an . + /// + /// The instance. + /// The inet to negate. + /// + /// The result of the bitwise NOT operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static IPAddress Not([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Computes the bitwise NOT operation on an (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to negate. + /// + /// The result of the bitwise NOT operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static (IPAddress Address, int Subnet) Not([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Computes the bitwise AND of two instances. + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// The result of the bitwise AND operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static IPAddress And([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Computes the bitwise AND of two (IPAddress Address, int Subnet) instances. + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// The result of the bitwise AND operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static (IPAddress Address, int Subnet) And([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Computes the bitwise OR of two instances. + /// + /// The instance. + /// The left-hand inet. + /// The right-hand inet. + /// + /// The result of the bitwise OR operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static IPAddress Or([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Computes the bitwise OR of two (IPAddress Address, int Subnet) instances. + /// + /// The instance. + /// The left-hand cidr. + /// The right-hand cidr. + /// + /// The result of the bitwise OR operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static (IPAddress Address, int Subnet) Or([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Adds the to the . + /// + /// The instance. + /// The inet. + /// The value to add. + /// + /// The augmented by the . + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Adds the to the (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr. + /// The value to add. + /// + /// The (IPAddress Address, int Subnet) augmented by the . + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Subtracts the from the . + /// + /// The instance. + /// The inet. + /// The value to subtract. + /// + /// The augmented by the . + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Subtracts the from the (IPAddress Address, int Subnet). + /// + /// The instance. + /// The inet. + /// The value to subtract. + /// + /// The (IPAddress Address, int Subnet) augmented by the . + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Subtracts one from another . + /// + /// The instance. + /// The inet from which to subtract. + /// The inet to subtract. + /// + /// The augmented by the . + /// + /// + /// 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, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Subtracts one (IPAddress Address, int Subnet) from another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr from which to subtract. + /// The cidr to subtract. + /// + /// The (IPAddress Address, int Subnet) augmented by the . + /// + /// + /// 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, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + } +} diff --git a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs index 3bdf2688a..5dab8880e 100644 --- a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs @@ -23,7 +23,8 @@ #endregion -using System; +using JetBrains.Annotations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities; using NpgsqlTypes; // ReSharper disable once CheckNamespace @@ -32,6 +33,7 @@ namespace Microsoft.EntityFrameworkCore /// /// Provides extension methods for supporting PostgreSQL translation. /// + [PublicAPI] public static class NpgsqlRangeExtensions { /// @@ -41,12 +43,12 @@ public static class NpgsqlRangeExtensions /// The value to locate in the range. /// The type of the elements of . /// - /// true if the range contains the specified value; otherwise, false. + /// True if the range contains the specified value; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool Contains(this NpgsqlRange range, T value) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range contains a specified range. @@ -55,12 +57,12 @@ public static class NpgsqlRangeExtensions /// The specified range to locate in the range. /// The type of the elements of . /// - /// true if the range contains the specified range; otherwise, false. + /// True if the range contains the specified range; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool Contains(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range is contained by a specified range. @@ -69,12 +71,12 @@ public static class NpgsqlRangeExtensions /// The range in which to locate the specified range. /// The type of the elements of . /// - /// true if the range contains the specified range; otherwise, false. + /// True if the range contains the specified range; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => b.Contains(a); + public static bool ContainedBy(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range overlaps another range. @@ -83,12 +85,12 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// true if the ranges overlap (share points in common); otherwise, false. + /// True if the ranges overlap (share points in common); otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool Overlaps(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range is strictly to the left of another range. @@ -97,12 +99,12 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// true if the first range is strictly to the left of the second; otherwise, false. + /// True if the first range is strictly to the left of the second; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool IsStrictlyLeftOf(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range is strictly to the right of another range. @@ -111,12 +113,12 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// true if the first range is strictly to the right of the second; otherwise, false. + /// True if the first range is strictly to the right of the second; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool IsStrictlyRightOf(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range does not extend to the left of another range. @@ -125,12 +127,12 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// true if the first range does not extend to the left of the second; otherwise, false. + /// True if the first range does not extend to the left of the second; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool DoesNotExtendLeftOf(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range does not extend to the right of another range. @@ -139,12 +141,12 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// true if the first range does not extend to the right of the second; otherwise, false. + /// True if the first range does not extend to the right of the second; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool DoesNotExtendRightOf(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether a range is adjacent to another range. @@ -153,12 +155,12 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// true if the ranges are adjacent; otherwise, false. + /// True if the ranges are adjacent; otherwise, false. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static bool IsAdjacentTo(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Returns the set union, which means unique elements that appear in either of two ranges. @@ -169,10 +171,10 @@ public static class NpgsqlRangeExtensions /// /// The unique elements that appear in either range. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static NpgsqlRange Union(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Returns the set intersection, which means elements that appear in each of two ranges. @@ -183,10 +185,10 @@ public static class NpgsqlRangeExtensions /// /// The elements that appear in both ranges. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static NpgsqlRange Intersect(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); /// /// Returns the set difference, which means the elements of one range that do not appear in a second range. @@ -197,9 +199,9 @@ public static class NpgsqlRangeExtensions /// /// The elements that appear in the first range, but not the second range. /// - /// + /// /// This 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) where T : IComparable => throw new NotSupportedException(); + public static NpgsqlRange Except(this NpgsqlRange a, NpgsqlRange b) => throw new ClientEvaluationNotSupportedException(); } } diff --git a/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs deleted file mode 100644 index 12ae0cef2..000000000 --- a/src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs +++ /dev/null @@ -1,95 +0,0 @@ -#region License - -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - -#endregion - -using System; -using System.Net; -using JetBrains.Annotations; -using NpgsqlTypes; - -// ReSharper disable once CheckNamespace -namespace Microsoft.EntityFrameworkCore -{ - /// - /// Provides extension methods supporting PostgreSQL network address operator translation. - /// - public static class NpgsqlNetworkAddressExtensions - { - /// - /// Determines whether an contains another . - /// - /// The DbFunctions instance. - /// The IP address to search. - /// The IP address to locate. - /// - /// true if the contains the other ; otherwise, false. - /// - /// - /// 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 _, [CanBeNull] IPAddress ipAddress, [CanBeNull] IPAddress other) => throw new NotSupportedException(); - - /// - /// Determines whether an contains another . - /// - /// The DbFunctions instance. - /// The inet to search. - /// The inet to locate. - /// - /// true if the contains the other ; otherwise, false. - /// - /// - /// 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 _, NpgsqlInet inet, NpgsqlInet other) => throw new NotSupportedException(); - - /// - /// Determines whether an contains or is equal to another . - /// - /// The DbFunctions instance. - /// The IP address to search. - /// The IP address to locate. - /// - /// true if the contains or is equal to the other ; otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool ContainsOrEquals([CanBeNull] this DbFunctions _, [CanBeNull] IPAddress ipAddress, [CanBeNull] IPAddress other) => throw new NotSupportedException(); - - /// - /// Determines whether an contains or is equal to another . - /// - /// The DbFunctions instance. - /// The inet to search. - /// The inet to locate. - /// - /// true if the contains or is equal to the other ; otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool ContainsOrEquals([CanBeNull] this DbFunctions _, NpgsqlInet inet, NpgsqlInet other) => throw new NotSupportedException(); - } -} diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs index 9fea7fbbb..234853976 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -25,6 +25,7 @@ using System.Linq.Expressions; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; @@ -42,30 +43,59 @@ public class NpgsqlNetworkAddressTranslator : IMethodCallTranslator [CanBeNull] public Expression Translate(MethodCallExpression expression) { + if (expression.Method.DeclaringType != typeof(NpgsqlNetworkAddressExtensions)) + return null; + switch (expression.Method.Name) { case nameof(NpgsqlNetworkAddressExtensions.Contains): - return new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], ">>", typeof(bool)); + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEqual): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>=", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.LessThan): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.LessThanOrEqual): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<=", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.Equal): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "=", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.GreaterThanOrEqual): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">=", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.GreaterThan): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.NotEqual): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<>", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.ContainedBy): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<<", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.ContainedByOrEqual): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<<=", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.Not): + return new CustomUnaryExpression(expression.Arguments[1], "~", expression.Arguments[1].Type); + + case nameof(NpgsqlNetworkAddressExtensions.And): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "&", expression.Arguments[1].Type); + + case nameof(NpgsqlNetworkAddressExtensions.Or): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "|", expression.Arguments[1].Type); + + case nameof(NpgsqlNetworkAddressExtensions.Add): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "+", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEquals): - return new CustomBinaryExpression(expression.Arguments[0], expression.Arguments[1], ">>=", typeof(bool)); + case nameof(NpgsqlNetworkAddressExtensions.Subtract): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "-", expression.Arguments[1].Type); default: return null; } } -// [NpgsqlBinaryOperator(Symbol = "<", ReturnType = typeof(bool))] LessThan, -// [NpgsqlBinaryOperator(Symbol = "<=", ReturnType = typeof(bool))] LessThanOrEqual, -// [NpgsqlBinaryOperator(Symbol = "=", ReturnType = typeof(bool))] Equal, -// [NpgsqlBinaryOperator(Symbol = ">=", ReturnType = typeof(bool))] GreaterThanOrEqual, -// [NpgsqlBinaryOperator(Symbol = ">", ReturnType = typeof(bool))] GreaterThan, -// [NpgsqlBinaryOperator(Symbol = "<>", ReturnType = typeof(bool))] NotEqual, -// [NpgsqlBinaryOperator(Symbol = "<<", ReturnType = typeof(bool))] ContainedWithin, -// [NpgsqlBinaryOperator(Symbol = "<<=", ReturnType = typeof(bool))] ContainedWithinOrEquals, -// [NpgsqlBinaryOperator(Symbol = "~", ReturnType = typeof(bool))] Not, -// [NpgsqlBinaryOperator(Symbol = "&", ReturnType = typeof(bool))] And, -// [NpgsqlBinaryOperator(Symbol = "|", ReturnType = typeof(bool))] Or, -// [NpgsqlBinaryOperator(Symbol = "+", ReturnType = typeof(bool))] Addition, -// [NpgsqlBinaryOperator(Symbol = "-", ReturnType = typeof(bool))] Subtraction, } } diff --git a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs index d57417936..e2c769314 100644 --- a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs +++ b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs @@ -33,10 +33,10 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping { public class NpgsqlMacaddrTypeMapping : NpgsqlTypeMapping { - public NpgsqlMacaddrTypeMapping() : base("macaddr", typeof(PhysicalAddress), NpgsqlDbType.MacAddr) {} + public NpgsqlMacaddrTypeMapping() : base("macaddr", typeof(PhysicalAddress), NpgsqlDbType.MacAddr) { } protected NpgsqlMacaddrTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) {} + : base(parameters, npgsqlDbType) { } public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlMacaddrTypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); @@ -53,7 +53,7 @@ public class NpgsqlMacaddr8TypeMapping : NpgsqlTypeMapping public NpgsqlMacaddr8TypeMapping() : base("macaddr8", typeof(PhysicalAddress), NpgsqlDbType.MacAddr8) {} protected NpgsqlMacaddr8TypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) {} + : base(parameters, npgsqlDbType) { } public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlMacaddr8TypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); @@ -67,10 +67,10 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlInetTypeMapping : NpgsqlTypeMapping { - public NpgsqlInetTypeMapping() : base("inet", typeof(IPAddress), NpgsqlDbType.Inet) {} + public NpgsqlInetTypeMapping() : base("inet", typeof(IPAddress), NpgsqlDbType.Inet) { } protected NpgsqlInetTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) {} + : base(parameters, npgsqlDbType) { } public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlInetTypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); @@ -84,10 +84,10 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlCidrTypeMapping : NpgsqlTypeMapping { - public NpgsqlCidrTypeMapping() : base("cidr", typeof((IPAddress, int)), NpgsqlDbType.Cidr) {} + public NpgsqlCidrTypeMapping() : base("cidr", typeof((IPAddress, int)), NpgsqlDbType.Cidr) { } protected NpgsqlCidrTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) {} + : base(parameters, npgsqlDbType) { } public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlCidrTypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); diff --git a/src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs b/src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs new file mode 100644 index 000000000..8fce1fdbb --- /dev/null +++ b/src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs @@ -0,0 +1,48 @@ +#region License + +// The PostgreSQL License +// +// Copyright (C) 2016 The Npgsql Development Team +// +// Permission to use, copy, modify, and distribute this software and its +// documentation for any purpose, without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph and the following two paragraphs appear in all copies. +// +// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY +// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, +// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF +// THE POSSIBILITY OF SUCH DAMAGE. +// +// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS +// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +#endregion + +using System; +using System.Runtime.CompilerServices; + +namespace Npgsql.EntityFrameworkCore.PostgreSQL.Utilities +{ + /// + /// The exception that is thrown when a method intended for SQL translation is evaluated by the client. + /// + public class ClientEvaluationNotSupportedException : NotSupportedException + { + readonly string _callerMemberName; + + /// + public override string Message + => $"{_callerMemberName} is only intended for use via SQL translation as part of an EF Core LINQ query."; + + /// + public ClientEvaluationNotSupportedException([CallerMemberName] string method = default) + { + _callerMemberName = method; + } + } +} diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index 71543694e..822aad62f 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Net; using Microsoft.EntityFrameworkCore; @@ -8,7 +7,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Npgsql.EntityFrameworkCore.PostgreSQL.TestUtilities; -using NpgsqlTypes; using Xunit; namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query @@ -43,16 +41,16 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() { using (NetContext context = Fixture.CreateContext()) { - NpgsqlInet npgsqlInet = new IPAddress(0); + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); bool[] _ = context.NetTestEntities - .Where(x => EF.Functions.ContainsOrEquals(x.CidrMappedToNpgsqlInet, npgsqlInet)) - .Select(x => x.CidrMappedToNpgsqlInet.Equals(npgsqlInet)) + .Where(x => EF.Functions.ContainsOrEqual(x.Cidr, cidr)) + .Select(x => x.Cidr.Equals(cidr)) .ToArray(); - AssertContainsSql("SELECT x.\"CidrMappedToNpgsqlInet\" = @__npgsqlInet_0"); - AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); + AssertContainsSql("SELECT x.\"Cidr\" = @__cidr_1 = TRUE"); + AssertContainsSql("WHERE x.\"Cidr\" >>= @__cidr_1 = TRUE"); } } @@ -60,37 +58,37 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() /// Tests translation for . /// [Fact] - public void IPAddressContainsIPAddress() + public void IPAddress_inet_Contains_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress address = new IPAddress(0); + IPAddress inet = new IPAddress(0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.Contains(x.InetMappedToIPAddress, address)) + .Where(x => EF.Functions.Contains(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"InetMappedToIPAddress\" >> @__address_0"); + AssertContainsSql("WHERE x.\"Inet\" >> @__inet_1 = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void NpgsqlInetContainsNpgsqlInet() + public void ValueTuple_cidr_Contains_cidr() { using (NetContext context = Fixture.CreateContext()) { - NpgsqlInet npgsqlInet = new IPAddress(0); + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.Contains(x.CidrMappedToNpgsqlInet, npgsqlInet)) + .Where(x => EF.Functions.Contains(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >> @__npgsqlInet_0"); + AssertContainsSql("WHERE x.\"Cidr\" >> @__cidr_1 = TRUE"); } } @@ -98,37 +96,37 @@ public void NpgsqlInetContainsNpgsqlInet() /// Tests inverse translation for . /// [Fact] - public void IPAddressDoesNotContainsIPAddress() + public void IPAddress_inet_DoesNotContain_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress address = new IPAddress(0); + IPAddress inet = new IPAddress(0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.Contains(x.InetMappedToIPAddress, address)) + .Where(x => !EF.Functions.Contains(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"InetMappedToIPAddress\" >> @__address_0 = TRUE)"); + AssertContainsSql("WHERE NOT (x.\"Inet\" >> @__inet_1 = TRUE)"); } } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] - public void NpgsqlInetDoesNotContainNpgsqlInet() + public void ValueTuple_cidr_DoesNotContain_cidr() { using (NetContext context = Fixture.CreateContext()) { - NpgsqlInet npgsqlInet = new IPAddress(0); + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.Contains(x.CidrMappedToNpgsqlInet, npgsqlInet)) + .Where(x => !EF.Functions.Contains(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >> @__npgsqlInet_0 = TRUE)"); + AssertContainsSql("WHERE NOT (x.\"Cidr\" >> @__cidr_1 = TRUE)"); } } @@ -136,37 +134,37 @@ public void NpgsqlInetDoesNotContainNpgsqlInet() /// Tests translation for . /// [Fact] - public void IPAddressContainOrEqualIPAddress() + public void IPAddress_inet_ContainsOrEquals_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress address = new IPAddress(0); + IPAddress inet = new IPAddress(0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.ContainsOrEquals(x.InetMappedToIPAddress, address)) + .Where(x => EF.Functions.ContainsOrEqual(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"InetMappedToIPAddress\" >>= @__address_0"); + AssertContainsSql("WHERE x.\"Inet\" >>= @__inet_1 = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void NpgsqlInetContainsOrEqualsNpgsqlInet() + public void ValueTuple_cidr_ContainsOrEquals_cidr() { using (NetContext context = Fixture.CreateContext()) { - NpgsqlInet npgsqlInet = new IPAddress(0); + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.ContainsOrEquals(x.CidrMappedToNpgsqlInet, npgsqlInet)) + .Where(x => EF.Functions.ContainsOrEqual(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0"); + AssertContainsSql("WHERE x.\"Cidr\" >>= @__cidr_1 = TRUE"); } } @@ -174,37 +172,37 @@ public void NpgsqlInetContainsOrEqualsNpgsqlInet() /// Tests inverse translation for . /// [Fact] - public void IPAddressDoesNotContainOrEqualIPAddress() + public void IPAddress_inet_DoesNotContainOrEqual_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress address = new IPAddress(0); + IPAddress inet = new IPAddress(0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.ContainsOrEquals(x.InetMappedToIPAddress, address)) + .Where(x => !EF.Functions.ContainsOrEqual(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"InetMappedToIPAddress\" >>= @__address_0 = TRUE)"); + AssertContainsSql("WHERE NOT (x.\"Inet\" >>= @__inet_1 = TRUE)"); } } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] - public void NpgsqlInetDoesNotContainOrEqualNpgsqlInet() + public void ValueTuple_cidr_DoesNotContainOrEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { - NpgsqlInet npgsqlInet = new IPAddress(0); + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.ContainsOrEquals(x.CidrMappedToNpgsqlInet, npgsqlInet)) + .Where(x => !EF.Functions.ContainsOrEqual(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"CidrMappedToNpgsqlInet\" >>= @__npgsqlInet_0 = TRUE)"); + AssertContainsSql("WHERE NOT (x.\"Cidr\" >>= @__cidr_1 = TRUE)"); } } @@ -256,18 +254,18 @@ public NetworkAddressQueryNpgsqlFixture() { context.Database.EnsureCreated(); - context.NetTestEntities - .AddRange( - new NetTestEntity { Id = 1, InetMappedToIPAddress = new IPAddress(1), CidrMappedToNpgsqlInet = new IPAddress(1) }, - new NetTestEntity { Id = 2, InetMappedToIPAddress = new IPAddress(2), CidrMappedToNpgsqlInet = new IPAddress(2) }, - new NetTestEntity { Id = 3, InetMappedToIPAddress = new IPAddress(3), CidrMappedToNpgsqlInet = new IPAddress(3) }, - new NetTestEntity { Id = 4, InetMappedToIPAddress = new IPAddress(4), CidrMappedToNpgsqlInet = new IPAddress(4) }, - new NetTestEntity { Id = 5, InetMappedToIPAddress = new IPAddress(5), CidrMappedToNpgsqlInet = new IPAddress(5) }, - new NetTestEntity { Id = 6, InetMappedToIPAddress = new IPAddress(6), CidrMappedToNpgsqlInet = new IPAddress(6) }, - new NetTestEntity { Id = 7, InetMappedToIPAddress = new IPAddress(7), CidrMappedToNpgsqlInet = new IPAddress(7) }, - new NetTestEntity { Id = 8, InetMappedToIPAddress = new IPAddress(8), CidrMappedToNpgsqlInet = new IPAddress(8) }, - new NetTestEntity { Id = 9, InetMappedToIPAddress = new IPAddress(9), CidrMappedToNpgsqlInet = new IPAddress(9) }, - new NetTestEntity { Id = 10, InetMappedToIPAddress = new IPAddress(10), CidrMappedToNpgsqlInet = new IPAddress(10) }); +// BUG: This throws for some reason +// for (int i = 0; i < 10; i++) +// { +// context.NetTestEntities +// .Add( +// new NetTestEntity +// { +// Id = i, +// Inet = new IPAddress(i), +// Cidr = (IPAddress: new IPAddress(i), Subnet: i) +// }); +// } context.SaveChanges(); } @@ -305,14 +303,12 @@ public class NetTestEntity /// /// The network address. /// - [Column(TypeName = "inet")] - public IPAddress InetMappedToIPAddress { get; set; } + public IPAddress Inet { get; set; } /// /// The network address. /// - [Column(TypeName = "cidr")] - public NpgsqlInet CidrMappedToNpgsqlInet { get; set; } + public (IPAddress IPAddress, int Subnet) Cidr { get; set; } } /// From 0f072299c354a9e60635494863aa07e4ff2c143e Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Fri, 25 May 2018 10:06:16 -0400 Subject: [PATCH 06/13] Add network address function translations - Maps cidr and inet functions to CLR extension methods. - See: https://www.postgresql.org/docs/current/static/functions-net.html#CIDR-INET-FUNCTIONS-TABLE - Includes functional tests covering translation. - Includes the bug fix in #425. - This can be removed once #425 is merged. --- .../NpgsqlNetworkAddressExtensions.cs | 326 ++++++++++++- .../NpgsqlNetworkAddressTranslator.cs | 37 ++ .../Query/NetworkAddressQueryNpgsqlTest.cs | 428 +++++++++++++++++- 3 files changed, 785 insertions(+), 6 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs index 5560a9af6..f74d6e01b 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs @@ -40,7 +40,7 @@ public static class NpgsqlNetworkAddressExtensions /// Determines whether an contains another . /// /// The instance. - /// The IP address to search. + /// The IP address to search. /// The IP address to locate. /// /// True if the contains the other ; otherwise, false. @@ -48,7 +48,7 @@ public static class NpgsqlNetworkAddressExtensions /// /// 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 ipAddress, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool Contains([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). @@ -68,7 +68,7 @@ public static class NpgsqlNetworkAddressExtensions /// Determines whether an contains or is equal to another . /// /// The instance. - /// The IP address to search. + /// The IP address to search. /// The IP address to locate. /// /// True if the contains or is equal to the other ; otherwise, false. @@ -76,7 +76,7 @@ public static class NpgsqlNetworkAddressExtensions /// /// 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 ipAddress, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). @@ -481,5 +481,323 @@ public static class NpgsqlNetworkAddressExtensions /// 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, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Returns the abbreviated display format as text. + /// + /// The instance. + /// The inet to abbreviate. + /// + /// The abbreviated display format as text. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Returns the abbreviated display format as text. + /// + /// The instance. + /// The cidr to abbreviate. + /// + /// The abbreviated display format as text. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Returns the broadcast address for a network. + /// + /// The instance. + /// The inet used to derive the broadcast address. + /// + /// The broadcast address for a network. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Returns the broadcast address for a network. + /// + /// The instance. + /// The cidr used to derive the broadcast address. + /// + /// The broadcast address for a network. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. + /// + /// The instance. + /// The inet used to derive the family. + /// + /// The family of an address; 4 for IPv4, 6 for IPv6. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. + /// + /// The instance. + /// The cidr used to derive the family. + /// + /// The family of an address; 4 for IPv4, 6 for IPv6. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the host (i.e. the IP address) as text. + /// + /// The instance. + /// The inet from which to extract the host. + /// + /// The host (i.e. the IP address) as text. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the host (i.e. the IP address) as text. + /// + /// The instance. + /// The cidr from which to extract the host. + /// + /// The host (i.e. the IP address) as text. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Constructs the host mask for the network. + /// + /// The instance. + /// The inet used to construct the host mask. + /// + /// The constructed host mask. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Constructs the host mask for the network. + /// + /// The instance. + /// The cidr used to construct the host mask. + /// + /// The constructed host mask. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the length of the subnet mask. + /// + /// The instance. + /// The inet used to extract the subnet length. + /// + /// The length of the subnet mask. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static int SubnetLength([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the length of the subnet mask. + /// + /// The instance. + /// The cidr used to extract the subnet length. + /// + /// The length of the subnet mask. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static int SubnetLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Constructs the subnet mask for the network. + /// + /// The instance. + /// The inet used to construct the subnet mask. + /// + /// The subnet mask for the network. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static IPAddress SubnetMask([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Constructs the subnet mask for the network. + /// + /// The instance. + /// The cidr used to construct the subnet mask. + /// + /// The subnet mask for the network. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static IPAddress SubnetMask([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the network part of the address. + /// + /// The instance. + /// The inet used to extract the network. + /// + /// The network part of the 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) Network([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the network part of the address. + /// + /// The instance. + /// The cidr used to extract the network. + /// + /// The network part of the 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) Network([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Sets the length of the subnet mask. + /// + /// The instance. + /// The inet to modify. + /// The subnet mask length to set. + /// + /// The network with a subnet mask of the specified length. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static IPAddress SetSubnetLength([CanBeNull] this DbFunctions _, IPAddress inet, int length) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Sets the length of the subnet mask. + /// + /// The instance. + /// The cidr to modify. + /// The subnet mask length to set. + /// + /// The network with a subnet mask of the specified length. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static (IPAddress Address, int Subnet) SetSubnetLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int length) => throw new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the IP address and subnet mask as text. + /// + /// The instance. + /// The inet to extract as text. + /// + /// The IP address and subnet mask as text. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Extracts the IP address and subnet mask as text. + /// + /// The instance. + /// The cidr to extract as text. + /// + /// The IP address and subnet mask as text. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Tests if the addresses are in the same family. + /// + /// The instance. + /// The primary inet. + /// The other inet. + /// + /// True if the addresses are in the same family; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Tests if the addresses are in the same family. + /// + /// The instance. + /// The primary cidr. + /// The other cidr. + /// + /// True if the addresses are in the same family; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Constructs the smallest network which includes both of the given networks. + /// + /// The instance. + /// The first inet. + /// The second inet. + /// + /// The smallest network which includes both of the given networks. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Constructs the smallest network which includes both of the given networks. + /// + /// The instance. + /// The first cidr. + /// The second cidr. + /// + /// The smallest network which includes both of the given networks. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); } } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs index 234853976..c5feae723 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -24,6 +24,7 @@ #endregion using System.Linq.Expressions; +using System.Net; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; @@ -93,6 +94,42 @@ public Expression Translate(MethodCallExpression expression) case nameof(NpgsqlNetworkAddressExtensions.Subtract): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "-", expression.Arguments[1].Type); + case nameof(NpgsqlNetworkAddressExtensions.Abbreviate): + return new PgFunctionExpression("abbrev", typeof(string), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.Broadcast): + return new PgFunctionExpression("broadcast", typeof(IPAddress), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.Family): + return new PgFunctionExpression("family", typeof(int), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.Host): + return new PgFunctionExpression("host", typeof(string), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.HostMask): + return new PgFunctionExpression("hostmask", typeof(IPAddress), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.SubnetLength): + return new PgFunctionExpression("masklen", typeof(int), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.SubnetMask): + return new PgFunctionExpression("netmask", typeof(IPAddress), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.Network): + return new PgFunctionExpression("network", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.SetSubnetLength): + return new PgFunctionExpression("set_masklen", expression.Arguments[1].Type, new[] { expression.Arguments[1], expression.Arguments[2] }); + + case nameof(NpgsqlNetworkAddressExtensions.Text): + return new PgFunctionExpression("text", typeof(string), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.SameFamily): + return new PgFunctionExpression("inet_same_family", typeof(bool), new[] { expression.Arguments[1], expression.Arguments[2] }); + + case nameof(NpgsqlNetworkAddressExtensions.Merge): + return new PgFunctionExpression("inet_merge", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1], expression.Arguments[2] }); + default: return null; } diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index 822aad62f..10afef24e 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -31,7 +31,7 @@ public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) Fixture.TestSqlLoggerFactory.Clear(); } - #region Tests + #region BugTests /// /// Demonstrates parameter duplication. @@ -54,6 +54,10 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() } } + #endregion + + #region OperatorTests + /// /// Tests translation for . /// @@ -208,6 +212,426 @@ public void ValueTuple_cidr_DoesNotContainOrEqual_cidr() #endregion + #region FunctionTests + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Abbreviate() + { + using (NetContext context = Fixture.CreateContext()) + { + string[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Abbreviate(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT abbrev(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Abbrebiate() + { + using (NetContext context = Fixture.CreateContext()) + { + string[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Abbreviate(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT abbrev(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Broadcast() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Broadcast(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT broadcast(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Broadcast() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Broadcast(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT broadcast(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Family() + { + using (NetContext context = Fixture.CreateContext()) + { + int[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Family(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT family(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Family() + { + using (NetContext context = Fixture.CreateContext()) + { + int[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Family(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT family(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Host() + { + using (NetContext context = Fixture.CreateContext()) + { + string[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Host(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT host(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Host() + { + using (NetContext context = Fixture.CreateContext()) + { + string[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Host(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT host(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_HostMask() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.HostMask(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT hostmask(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_HostMask() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.HostMask(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT hostmask(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_SubnetLength() + { + using (NetContext context = Fixture.CreateContext()) + { + int[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SubnetLength(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT masklen(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_SubnetLength() + { + using (NetContext context = Fixture.CreateContext()) + { + int[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SubnetLength(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT masklen(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_SubnetMask() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SubnetMask(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT netmask(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_SubnetMask() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SubnetMask(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT netmask(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Network() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Network(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT network(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Network() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Network(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT network(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_SetSubnetLength() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SetSubnetLength(x.Inet, 0)) + .ToArray(); + + AssertContainsSql("SELECT set_masklen(x.\"Inet\", 0)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_SetSubnetLength() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SetSubnetLength(x.Cidr, 0)) + .ToArray(); + + AssertContainsSql("SELECT set_masklen(x.\"Cidr\", 0)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Text() + { + using (NetContext context = Fixture.CreateContext()) + { + string[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Text(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT text(x.\"Inet\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Text() + { + using (NetContext context = Fixture.CreateContext()) + { + string[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Text(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT text(x.\"Cidr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_SameFamily() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + bool[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SameFamily(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("SELECT inet_same_family(x.\"Inet\", @__inet_1)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_SameFamily() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + bool[] _ = + context.NetTestEntities + .Select(x => EF.Functions.SameFamily(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("SELECT inet_same_family(x.\"Cidr\", @__cidr_1)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Merge() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Merge(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("SELECT inet_merge(x.\"Inet\", @__inet_1)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Merge() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Merge(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("SELECT inet_merge(x.\"Cidr\", @__cidr_1)"); + } + } + + #endregion + #region Fixtures /// @@ -308,7 +732,7 @@ public class NetTestEntity /// /// The network address. /// - public (IPAddress IPAddress, int Subnet) Cidr { get; set; } + public (IPAddress Address, int Subnet) Cidr { get; set; } } /// From 8d72b9763fd624103df15f93b290df5864e8f5eb Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Fri, 25 May 2018 17:32:11 -0400 Subject: [PATCH 07/13] Add MAC address functions for translation - Maps macaddr and macaddr8 functions to CLR extension methods. - macaddr: https://www.postgresql.org/docs/current/static/functions-net.html#MACADDR-FUNCTIONS-TABLE - macaddr8: https://www.postgresql.org/docs/current/static/functions-net.html#MACADDR8-FUNCTIONS-TABLE - Includes functional tests covering translation. - TODO: - Map the standard relational operators and bitwise arithmetic operators. --- .../NpgsqlNetworkAddressExtensions.cs | 27 ++++++++++ .../NpgsqlNetworkAddressTranslator.cs | 7 +++ .../Mapping/NpgsqlNetworkTypeMappings.cs | 2 +- .../Query/NetworkAddressQueryNpgsqlTest.cs | 52 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs index f74d6e01b..c4043f07b 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs @@ -24,6 +24,7 @@ #endregion using System.Net; +using System.Net.NetworkInformation; using JetBrains.Annotations; using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities; @@ -799,5 +800,31 @@ public static class NpgsqlNetworkAddressExtensions /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Sets the last 3 bytes of the MAC address to zero. For macaddr8, the last 5 bytes are set to zero. + /// + /// The instance. + /// The MAC address to truncate. + /// + /// The MAC address with the last 3 bytes set to zero. For macaddr8, the last 5 bytes are set to zero. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Sets the 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 address. + /// + /// The instance. + /// The MAC address to modify. + /// + /// The MAC address with the 7th bit set to one. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); } } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs index c5feae723..d63bd77da 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -25,6 +25,7 @@ using System.Linq.Expressions; using System.Net; +using System.Net.NetworkInformation; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; @@ -130,6 +131,12 @@ public Expression Translate(MethodCallExpression expression) case nameof(NpgsqlNetworkAddressExtensions.Merge): return new PgFunctionExpression("inet_merge", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1], expression.Arguments[2] }); + case nameof(NpgsqlNetworkAddressExtensions.Truncate): + return new PgFunctionExpression("trunc", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); + + case nameof(NpgsqlNetworkAddressExtensions.Set7BitMac8): + return new PgFunctionExpression("macaddr8_set7bit", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); + default: return null; } diff --git a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs index e2c769314..cfdc8ff5b 100644 --- a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs +++ b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs @@ -50,7 +50,7 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlMacaddr8TypeMapping : NpgsqlTypeMapping { - public NpgsqlMacaddr8TypeMapping() : base("macaddr8", typeof(PhysicalAddress), NpgsqlDbType.MacAddr8) {} + public NpgsqlMacaddr8TypeMapping() : base("macaddr8", typeof(PhysicalAddress), NpgsqlDbType.MacAddr8) { } protected NpgsqlMacaddr8TypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) : base(parameters, npgsqlDbType) { } diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index 10afef24e..14f6f4538 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -1,7 +1,9 @@ using System; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Net; +using System.Net.NetworkInformation; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.TestUtilities; using Microsoft.Extensions.DependencyInjection; @@ -630,6 +632,45 @@ public void ValueTuple_cidr_Merge() } } + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_Truncate() + { + using (NetContext context = Fixture.CreateContext()) + { + var _ = + context.NetTestEntities + .Select( + x => new + { + macaddr = EF.Functions.Truncate(x.Macaddr), + macaddr8 = EF.Functions.Truncate(x.Macaddr8) + }) + .ToArray(); + + AssertContainsSql("SELECT trunc(x.\"Macaddr\") AS macaddr, trunc(x.\"Macaddr8\") AS macaddr8"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_Set7BitMac8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Set7BitMac8(x.Macaddr8)) + .ToArray(); + + AssertContainsSql("SELECT macaddr8_set7bit(x.\"Macaddr8\")"); + } + } + #endregion #region Fixtures @@ -733,6 +774,17 @@ public class NetTestEntity /// The network address. /// public (IPAddress Address, int Subnet) Cidr { get; set; } + + /// + /// The MAC address. + /// + public PhysicalAddress Macaddr { get; set; } + + /// + /// The MAC address. + /// + [Column(TypeName = "macaddr8")] + public PhysicalAddress Macaddr8 { get; set; } } /// From 448da55c8399ea22a93737843a8cc9bd806c2a1a Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Fri, 25 May 2018 18:25:28 -0400 Subject: [PATCH 08/13] Add tests for network address operators - Includes functional tests convering network address operators. - Includes the network function `ContainsOrContainedBy(...)`. - Includes patch for https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/pull/426 - Reordering functions/operators to reflect the docs for version 10. - TODO: - Add operators for `macaddr` and `macaddr8`. - Add some basic info to the docs. --- .../NpgsqlNetworkAddressExtensions.cs | 140 +++-- .../NpgsqlNetworkAddressTranslator.cs | 15 +- .../Query/NetworkAddressQueryNpgsqlTest.cs | 538 +++++++++++++++++- 3 files changed, 605 insertions(+), 88 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs index c4043f07b..1bb6b1da8 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs @@ -37,62 +37,6 @@ namespace Microsoft.EntityFrameworkCore [PublicAPI] public static class NpgsqlNetworkAddressExtensions { - /// - /// Determines whether an contains another . - /// - /// The instance. - /// The IP address to search. - /// The IP address to locate. - /// - /// True if the contains the other ; otherwise, false. - /// - /// - /// 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 new ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). - /// - /// The instance. - /// The cidr to search. - /// The cidr to locate. - /// - /// True if the (IPAddress Address, int Subnet) contains the other (IPAddress Address, int Subnet); otherwise, false. - /// - /// - /// 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 new ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an contains or is equal to another . - /// - /// The instance. - /// The IP address to search. - /// The IP address to locate. - /// - /// True if the contains or is equal to the other ; otherwise, false. - /// - /// - /// 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 new ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). - /// - /// The instance. - /// The cidr to search. - /// The cidr to locate. - /// - /// True if the (IPAddress Address, int Subnet) contains or is equal to the other (IPAddress Address, int Subnet); otherwise, false. - /// - /// - /// 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 new ClientEvaluationNotSupportedException(); - /// /// Determines whether an is less than another . /// @@ -317,6 +261,90 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an contains another . + /// + /// The instance. + /// The IP address to search. + /// The IP address to locate. + /// + /// True if the contains the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to search. + /// The cidr to locate. + /// + /// True if the (IPAddress Address, int Subnet) contains the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an contains or is equal to another . + /// + /// The instance. + /// The IP address to search. + /// The IP address to locate. + /// + /// True if the contains or is equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to search. + /// The cidr to locate. + /// + /// True if the (IPAddress Address, int Subnet) contains or is equal to the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an contains or is contained by another . + /// + /// The instance. + /// The IP address to search. + /// The IP address to locate. + /// + /// True if the contains or is contained by the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an (IPAddress Address, int Subnet) contains or is contained by another (IPAddress Address, int Subnet). + /// + /// The instance. + /// The cidr to search. + /// The cidr to locate. + /// + /// True if the (IPAddress Address, int Subnet) contains or is contained by the other (IPAddress Address, int Subnet); otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + /// /// Computes the bitwise NOT operation on an . /// diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs index d63bd77da..7291ccded 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -50,12 +50,6 @@ public Expression Translate(MethodCallExpression expression) switch (expression.Method.Name) { - case nameof(NpgsqlNetworkAddressExtensions.Contains): - return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>", typeof(bool)); - - case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEqual): - return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>=", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.LessThan): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<", typeof(bool)); @@ -80,6 +74,15 @@ public Expression Translate(MethodCallExpression expression) case nameof(NpgsqlNetworkAddressExtensions.ContainedByOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<<=", typeof(bool)); + case nameof(NpgsqlNetworkAddressExtensions.Contains): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEqual): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>=", typeof(bool)); + + case nameof(NpgsqlNetworkAddressExtensions.ContainsOrContainedBy): + return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "&&", typeof(bool)); + case nameof(NpgsqlNetworkAddressExtensions.Not): return new CustomUnaryExpression(expression.Arguments[1], "~", expression.Arguments[1].Type); diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index 14f6f4538..d70db0377 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -14,10 +14,12 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query { /// - /// Provides unit tests for network address operator translations. + /// Provides unit tests for network address operator and function translations. /// public class NetworkAddressQueryNpgsqlTest : IClassFixture { + #region Setup + /// /// Provides resources for unit tests. /// @@ -33,6 +35,8 @@ public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) Fixture.TestSqlLoggerFactory.Clear(); } + #endregion + #region BugTests /// @@ -61,10 +65,10 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() #region OperatorTests /// - /// Tests translation for . + /// Tests inverse translation for . /// [Fact] - public void IPAddress_inet_Contains_inet() + public void IPAddress_inet_LessThan_inet() { using (NetContext context = Fixture.CreateContext()) { @@ -72,18 +76,18 @@ public void IPAddress_inet_Contains_inet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.Contains(x.Inet, inet)) + .Where(x => EF.Functions.LessThan(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"Inet\" >> @__inet_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Inet\" < @__inet_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests inverse translation for . /// [Fact] - public void ValueTuple_cidr_Contains_cidr() + public void ValueTuple_cidr_LessThan_cidr() { using (NetContext context = Fixture.CreateContext()) { @@ -91,18 +95,94 @@ public void ValueTuple_cidr_Contains_cidr() NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.Contains(x.Cidr, cidr)) + .Where(x => EF.Functions.LessThan(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"Cidr\" >> @__cidr_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Cidr\" < @__cidr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_LessThanOrEqual_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.LessThanOrEqual(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Inet\" <= @__inet_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void ValueTuple_cidr_LessThanOrEqual_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.LessThanOrEqual(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" <= @__cidr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_Equal_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Equal(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Inet\" = @__inet_1) = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] - public void IPAddress_inet_DoesNotContain_inet() + public void ValueTuple_cidr_Equal_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Equal(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" = @__cidr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_GreaterThanOrEqual_inet() { using (NetContext context = Fixture.CreateContext()) { @@ -110,18 +190,18 @@ public void IPAddress_inet_DoesNotContain_inet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.Contains(x.Inet, inet)) + .Where(x => EF.Functions.GreaterThanOrEqual(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"Inet\" >> @__inet_1 = TRUE)"); + AssertContainsSql("WHERE (x.\"Inet\" >= @__inet_1) = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests inverse translation for . /// [Fact] - public void ValueTuple_cidr_DoesNotContain_cidr() + public void ValueTuple_cidr_GreaterThanOrEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { @@ -129,10 +209,162 @@ public void ValueTuple_cidr_DoesNotContain_cidr() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.Contains(x.Cidr, cidr)) + .Where(x => EF.Functions.GreaterThanOrEqual(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" >= @__cidr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_GreaterThan_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.GreaterThan(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"Cidr\" >> @__cidr_1 = TRUE)"); + AssertContainsSql("WHERE (x.\"Inet\" > @__inet_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void ValueTuple_cidr_GreaterThan_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.GreaterThan(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" > @__cidr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_NotEqual_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.NotEqual(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Inet\" <> @__inet_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void ValueTuple_cidr_NotEqual_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.NotEqual(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" <> @__cidr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_ContainedBy_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainedBy(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Inet\" << @__inet_1 = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void ValueTuple_cidr_ContainedBy_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainedBy(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Cidr\" << @__cidr_1 = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_ContainedByOrEqual_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainedByOrEqual(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Inet\" <<= @__inet_1 = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void ValueTuple_cidr_ContainedByOrEqual_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainedByOrEqual(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Cidr\" <<= @__cidr_1 = TRUE"); } } @@ -140,6 +372,44 @@ public void ValueTuple_cidr_DoesNotContain_cidr() /// Tests translation for . /// [Fact] + public void IPAddress_inet_Contains_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Contains(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Inet\" >> @__inet_1 = TRUE"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Contains_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Contains(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Cidr\" >> @__cidr_1 = TRUE"); + } + } + + /// + /// Tests translation for . + /// + [Fact] public void IPAddress_inet_ContainsOrEquals_inet() { using (NetContext context = Fixture.CreateContext()) @@ -156,7 +426,7 @@ public void IPAddress_inet_ContainsOrEquals_inet() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_ContainsOrEquals_cidr() @@ -175,10 +445,10 @@ public void ValueTuple_cidr_ContainsOrEquals_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] - public void IPAddress_inet_DoesNotContainOrEqual_inet() + public void IPAddress_inet_ContainsOrContainedBy_inet() { using (NetContext context = Fixture.CreateContext()) { @@ -186,18 +456,18 @@ public void IPAddress_inet_DoesNotContainOrEqual_inet() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.ContainsOrEqual(x.Inet, inet)) + .Where(x => EF.Functions.ContainsOrContainedBy(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"Inet\" >>= @__inet_1 = TRUE)"); + AssertContainsSql("WHERE x.\"Inet\" && @__inet_1 = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_DoesNotContainOrEqual_cidr() + public void ValueTuple_cidr_ContainsOrContainedBy_cidr() { using (NetContext context = Fixture.CreateContext()) { @@ -205,10 +475,226 @@ public void ValueTuple_cidr_DoesNotContainOrEqual_cidr() NetTestEntity[] _ = context.NetTestEntities - .Where(x => !EF.Functions.ContainsOrEqual(x.Cidr, cidr)) + .Where(x => EF.Functions.ContainsOrContainedBy(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("WHERE x.\"Cidr\" && @__cidr_1 = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void IPAddress_inet_Not() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Not(x.Inet)) + .ToArray(); + + AssertContainsSql("SELECT ~x.\"Inet\""); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void ValueTuple_cidr_Not() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Not(x.Cidr)) + .ToArray(); + + AssertContainsSql("SELECT ~x.\"Cidr\""); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_And_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.And(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Inet\" & @__inet_1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_And_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.And(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Cidr\" & @__cidr_1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Or_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Or(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Inet\" | @__inet_1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Or_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Or(x.Cidr, cidr)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Cidr\" | @__cidr_1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Add_int() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Add(x.Inet, 1)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Inet\" + 1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Add_int() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Add(x.Cidr, 1)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Cidr\" + 1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Subtract_int() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Subtract(x.Inet, 1)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Inet\" - 1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Subtract_int() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Subtract(x.Cidr, 1)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Cidr\" - 1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_Subtract_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = new IPAddress(0); + + IPAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Subtract(x.Inet, inet)) + .ToArray(); + + AssertContainsSql("SELECT x.\"Inet\" - @__inet_1"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Subtract_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + + (IPAddress Address, int Subnet)[] _ = + context.NetTestEntities + .Select(x => EF.Functions.Subtract(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE NOT (x.\"Cidr\" >>= @__cidr_1 = TRUE)"); + AssertContainsSql("SELECT x.\"Cidr\" - @__cidr_1"); } } From 7ece32ca3d04d4ec8b09a0f744e62dd0f74f1123 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Fri, 25 May 2018 21:12:47 -0400 Subject: [PATCH 09/13] Add MAC address operators - Includes relational and bitwise operators for `macaddr` and `macaddr8`. - Mapped to `PhysicalAddress`. - Includes functional tests covering new operators. - TODO: - Add some basic info to the docs. - BUG: - Tests failing for `macaddr8`: ``` System.FormatException : MAC addresses must have length 6 in PostgreSQL at Npgsql.TypeHandlers .NetworkHandlers .MacaddrHandler .ValidateAndGetLength( PhysicalAddress value, NpgsqlParameter parameter) ``` --- .../NpgsqlNetworkAddressExtensions.cs | 148 ++++++++ .../NpgsqlNetworkAddressTranslator.cs | 2 +- .../EFCore.PG.FunctionalTests.csproj | 1 + .../Query/NetworkAddressQueryNpgsqlTest.cs | 315 ++++++++++++++++-- 4 files changed, 429 insertions(+), 37 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs index 1bb6b1da8..40fd6507a 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs @@ -34,9 +34,14 @@ namespace Microsoft.EntityFrameworkCore /// /// Provides extension methods supporting PostgreSQL network address operator translation. /// + /// + /// See: https://www.postgresql.org/docs/current/static/functions-net.html + /// [PublicAPI] public static class NpgsqlNetworkAddressExtensions { + #region RelationalOperators + /// /// Determines whether an is less than another . /// @@ -65,6 +70,20 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool LessThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an is less than another . + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// True if the is less than the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + /// /// Determines whether an is less than or equal to another . /// @@ -93,6 +112,20 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an is less than or equal to another . + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// True if the is less than or equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + /// /// Determines whether an is equal to another . /// @@ -121,6 +154,20 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an is equal to another . + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// True if the is equal to the other ; otherwise, false. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool Equal([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + /// /// Determines whether an is greater than or equal to another . /// @@ -149,6 +196,20 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an is greater than or equal to another . + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// True if the is greater than or equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + /// /// Determines whether an is greater than another . /// @@ -177,6 +238,20 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an is greater than another . + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// True if the is greater than the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + /// /// Determines whether an is not equal to another . /// @@ -205,6 +280,24 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Determines whether an is not equal to another . + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// True if the is not equal to the other ; otherwise, false. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static bool NotEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + + #endregion + + #region ContainmentOperators + /// /// Determines whether an is contained within another . /// @@ -345,6 +438,10 @@ public static class NpgsqlNetworkAddressExtensions /// public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + #endregion + + #region BitwiseOperators + /// /// Computes the bitwise NOT operation on an . /// @@ -371,6 +468,19 @@ public static class NpgsqlNetworkAddressExtensions /// public static (IPAddress Address, int Subnet) Not([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + /// + /// Computes the bitwise NOT operation on an . + /// + /// The instance. + /// The macaddr to negate. + /// + /// The result of the bitwise NOT operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static PhysicalAddress Not([CanBeNull] this DbFunctions _, PhysicalAddress macaddr) => throw new ClientEvaluationNotSupportedException(); + /// /// Computes the bitwise AND of two instances. /// @@ -399,6 +509,20 @@ public static class NpgsqlNetworkAddressExtensions /// public static (IPAddress Address, int Subnet) And([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Computes the bitwise AND of two instances. + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// The result of the bitwise AND operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static PhysicalAddress And([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + /// /// Computes the bitwise OR of two instances. /// @@ -427,6 +551,24 @@ public static class NpgsqlNetworkAddressExtensions /// public static (IPAddress Address, int Subnet) Or([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + /// + /// Computes the bitwise OR of two instances. + /// + /// The instance. + /// The left-hand macaddr. + /// The right-hand macaddr. + /// + /// The result of the bitwise OR operation. + /// + /// + /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. + /// + public static PhysicalAddress Or([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + + #endregion + + #region ArithmeticOperators + /// /// Adds the to the . /// @@ -511,6 +653,10 @@ public static class NpgsqlNetworkAddressExtensions /// public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + #endregion + + #region Functions + /// /// Returns the abbreviated display format as text. /// @@ -854,5 +1000,7 @@ public static class NpgsqlNetworkAddressExtensions /// 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 new ClientEvaluationNotSupportedException(); + + #endregion } } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs index 7291ccded..22ba8c3dd 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs @@ -34,7 +34,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal { /// - /// Provides translation services for PostgreSQL network address (inet, cidr) operators. + /// Provides translation services for PostgreSQL network address (cidr, inet, macaddr, macaddr8) operators and functions. /// /// /// See: https://www.postgresql.org/docs/current/static/functions-net.html diff --git a/test/EFCore.PG.FunctionalTests/EFCore.PG.FunctionalTests.csproj b/test/EFCore.PG.FunctionalTests/EFCore.PG.FunctionalTests.csproj index 995cdaa61..31000562e 100644 --- a/test/EFCore.PG.FunctionalTests/EFCore.PG.FunctionalTests.csproj +++ b/test/EFCore.PG.FunctionalTests/EFCore.PG.FunctionalTests.csproj @@ -7,6 +7,7 @@ ../../Npgsql.snk true true + latest diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs index d70db0377..c9bf85692 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs @@ -16,6 +16,9 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query /// /// Provides unit tests for network address operator and function translations. /// + /// + /// See: https://www.postgresql.org/docs/current/static/functions-net.html + /// public class NetworkAddressQueryNpgsqlTest : IClassFixture { #region Setup @@ -47,7 +50,7 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); bool[] _ = context.NetTestEntities @@ -62,7 +65,7 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() #endregion - #region OperatorTests + #region RelationalOperatorTests /// /// Tests inverse translation for . @@ -72,7 +75,7 @@ public void IPAddress_inet_LessThan_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -91,7 +94,7 @@ public void ValueTuple_cidr_LessThan_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -102,6 +105,44 @@ public void ValueTuple_cidr_LessThan_cidr() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_LessThan_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.LessThan(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr\" < @__macaddr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_LessThan_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.LessThan(x.Macaddr8, macaddr8)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr8\" < @__macaddr8_1) = TRUE"); + } + } + /// /// Tests inverse translation for . /// @@ -110,7 +151,7 @@ public void IPAddress_inet_LessThanOrEqual_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -129,7 +170,7 @@ public void ValueTuple_cidr_LessThanOrEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -140,6 +181,44 @@ public void ValueTuple_cidr_LessThanOrEqual_cidr() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_LessThanOrEqual_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.LessThanOrEqual(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr\" <= @__macaddr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_LessThanOrEqual_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.LessThanOrEqual(x.Macaddr8, macaddr8)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr8\" <= @__macaddr8_1) = TRUE"); + } + } + /// /// Tests inverse translation for . /// @@ -148,7 +227,7 @@ public void IPAddress_inet_Equal_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -167,7 +246,7 @@ public void ValueTuple_cidr_Equal_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -178,6 +257,44 @@ public void ValueTuple_cidr_Equal_cidr() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_Equal_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Equal(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr\" = @__macaddr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_Equal_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Equal(x.Macaddr8, macaddr8)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr8\" = @__macaddr8_1) = TRUE"); + } + } + /// /// Tests inverse translation for . /// @@ -186,7 +303,7 @@ public void IPAddress_inet_GreaterThanOrEqual_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -205,7 +322,7 @@ public void ValueTuple_cidr_GreaterThanOrEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -216,6 +333,44 @@ public void ValueTuple_cidr_GreaterThanOrEqual_cidr() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_GreaterThanOrEqual_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.GreaterThanOrEqual(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr\" >= @__macaddr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_GreaterThanOrEqual_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.GreaterThanOrEqual(x.Macaddr8, macaddr8)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr8\" >= @__macaddr8_1) = TRUE"); + } + } + /// /// Tests inverse translation for . /// @@ -224,7 +379,7 @@ public void IPAddress_inet_GreaterThan_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -243,7 +398,7 @@ public void ValueTuple_cidr_GreaterThan_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -254,6 +409,44 @@ public void ValueTuple_cidr_GreaterThan_cidr() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_GreaterThan_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.GreaterThan(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr\" > @__macaddr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_GreaterThan_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.GreaterThan(x.Macaddr8, macaddr8)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr8\" > @__macaddr8_1) = TRUE"); + } + } + /// /// Tests inverse translation for . /// @@ -262,7 +455,7 @@ public void IPAddress_inet_NotEqual_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -281,7 +474,7 @@ public void ValueTuple_cidr_NotEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -292,6 +485,48 @@ public void ValueTuple_cidr_NotEqual_cidr() } } + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_NotEqual_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.NotEqual(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr\" <> @__macaddr_1) = TRUE"); + } + } + + /// + /// Tests inverse translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_NotEqual_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.NotEqual(x.Macaddr8, macaddr8)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Macaddr8\" <> @__macaddr8_1) = TRUE"); + } + } + + #endregion + + #region ContainmentOperatorTests + /// /// Tests inverse translation for . /// @@ -300,7 +535,7 @@ public void IPAddress_inet_ContainedBy_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -319,7 +554,7 @@ public void ValueTuple_cidr_ContainedBy_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -338,7 +573,7 @@ public void IPAddress_inet_ContainedByOrEqual_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -357,7 +592,7 @@ public void ValueTuple_cidr_ContainedByOrEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -376,7 +611,7 @@ public void IPAddress_inet_Contains_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -395,7 +630,7 @@ public void ValueTuple_cidr_Contains_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -414,7 +649,7 @@ public void IPAddress_inet_ContainsOrEquals_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -433,7 +668,7 @@ public void ValueTuple_cidr_ContainsOrEquals_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -452,7 +687,7 @@ public void IPAddress_inet_ContainsOrContainedBy_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; NetTestEntity[] _ = context.NetTestEntities @@ -471,7 +706,7 @@ public void ValueTuple_cidr_ContainsOrContainedBy_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); NetTestEntity[] _ = context.NetTestEntities @@ -482,6 +717,10 @@ public void ValueTuple_cidr_ContainsOrContainedBy_cidr() } } + #endregion + + #region BitwiseOperatorTests + /// /// Tests inverse translation for . /// @@ -524,7 +763,7 @@ public void IPAddress_inet_And_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; IPAddress[] _ = context.NetTestEntities @@ -543,7 +782,7 @@ public void ValueTuple_cidr_And_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); (IPAddress Address, int Subnet)[] _ = context.NetTestEntities @@ -562,7 +801,7 @@ public void IPAddress_inet_Or_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; IPAddress[] _ = context.NetTestEntities @@ -581,7 +820,7 @@ public void ValueTuple_cidr_Or_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); (IPAddress Address, int Subnet)[] _ = context.NetTestEntities @@ -592,6 +831,10 @@ public void ValueTuple_cidr_Or_cidr() } } + #endregion + + #region ArithmeticOperatorTests + /// /// Tests translation for . /// @@ -668,7 +911,7 @@ public void IPAddress_inet_Subtract_inet() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; IPAddress[] _ = context.NetTestEntities @@ -687,7 +930,7 @@ public void ValueTuple_cidr_Subtract_cidr() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); (IPAddress Address, int Subnet)[] _ = context.NetTestEntities @@ -984,7 +1227,7 @@ public void IPAddress_inet_SetSubnetLength() { IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.SetSubnetLength(x.Inet, 0)) + .Select(x => EF.Functions.SetSubnetLength(x.Inet, default)) .ToArray(); AssertContainsSql("SELECT set_masklen(x.\"Inet\", 0)"); @@ -1001,7 +1244,7 @@ public void ValueTuple_cidr_SetSubnetLength() { (IPAddress Address, int Subnet)[] _ = context.NetTestEntities - .Select(x => EF.Functions.SetSubnetLength(x.Cidr, 0)) + .Select(x => EF.Functions.SetSubnetLength(x.Cidr, default)) .ToArray(); AssertContainsSql("SELECT set_masklen(x.\"Cidr\", 0)"); @@ -1050,7 +1293,7 @@ public void IPAddress_inet_SameFamily() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; bool[] _ = context.NetTestEntities @@ -1069,7 +1312,7 @@ public void ValueTuple_cidr_SameFamily() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); bool[] _ = context.NetTestEntities @@ -1088,7 +1331,7 @@ public void IPAddress_inet_Merge() { using (NetContext context = Fixture.CreateContext()) { - IPAddress inet = new IPAddress(0); + IPAddress inet = IPAddress.Any; (IPAddress Address, int Subnet)[] _ = context.NetTestEntities @@ -1107,7 +1350,7 @@ public void ValueTuple_cidr_Merge() { using (NetContext context = Fixture.CreateContext()) { - (IPAddress Address, int Subnet) cidr = (new IPAddress(0), 0); + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); (IPAddress Address, int Subnet)[] _ = context.NetTestEntities From 9b6f1b45f380805768f363e90ecc80e14ad5f9b4 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Sat, 26 May 2018 12:20:27 -0400 Subject: [PATCH 10/13] Update tests for the patch in PR 426 - Updates tests for new parentheses in custom binary operators. - Renames `NetworkAddress*` to `Network*` to reflect the feature scope. - Issues: - Tests for `macaddr8` are tricky. - Entity properties with column type `macaddr8` work fine. - But parameters of type `PhysicalAddress` are treated as a `macaddr`. - `System.FormatException : MAC addresses must have length 6 in PostgreSQL` - Perhaps Npgsql could detect and upgrade `PhysicalAddress` values to `macaddr8`? - But only when they have 8 bytes? - Opened issue 428 to discuss possible solutions. --- ...tensions.cs => NpgsqlNetworkExtensions.cs} | 4 +- .../NpgsqlCompositeMethodCallTranslator.cs | 2 +- ...anslator.cs => NpgsqlNetworkTranslator.cs} | 66 ++--- ...pgsqlTest.cs => NetworkQueryNpgsqlTest.cs} | 226 +++++++++--------- 4 files changed, 143 insertions(+), 155 deletions(-) rename src/EFCore.PG/Extensions/{NpgsqlNetworkAddressExtensions.cs => NpgsqlNetworkExtensions.cs} (99%) rename src/EFCore.PG/Query/ExpressionTranslators/Internal/{NpgsqlNetworkAddressTranslator.cs => NpgsqlNetworkTranslator.cs} (72%) rename test/EFCore.PG.FunctionalTests/Query/{NetworkAddressQueryNpgsqlTest.cs => NetworkQueryNpgsqlTest.cs} (78%) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs similarity index 99% rename from src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs rename to src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs index 40fd6507a..c0448914c 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs @@ -32,13 +32,13 @@ namespace Microsoft.EntityFrameworkCore { /// - /// Provides extension methods supporting PostgreSQL network address operator translation. + /// Provides extension methods supporting operator translation for PostgreSQL network types. /// /// /// See: https://www.postgresql.org/docs/current/static/functions-net.html /// [PublicAPI] - public static class NpgsqlNetworkAddressExtensions + public static class NpgsqlNetworkExtensions { #region RelationalOperators diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs index d68830d9a..131ac6988 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlCompositeMethodCallTranslator.cs @@ -60,7 +60,7 @@ public class NpgsqlCompositeMethodCallTranslator : RelationalCompositeMethodCall new NpgsqlRegexIsMatchTranslator(), new NpgsqlFullTextSearchMethodTranslator(), new NpgsqlRangeTranslator(), - new NpgsqlNetworkAddressTranslator() + new NpgsqlNetworkTranslator() }; /// diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs similarity index 72% rename from src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs rename to src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs index 22ba8c3dd..2eae914b9 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkAddressTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs @@ -34,110 +34,110 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal { /// - /// Provides translation services for PostgreSQL network address (cidr, inet, macaddr, macaddr8) operators and functions. + /// Provides translation services for operators and functions of PostgreSQL network typess (cidr, inet, macaddr, macaddr8). /// /// /// See: https://www.postgresql.org/docs/current/static/functions-net.html /// - public class NpgsqlNetworkAddressTranslator : IMethodCallTranslator + public class NpgsqlNetworkTranslator : IMethodCallTranslator { /// [CanBeNull] public Expression Translate(MethodCallExpression expression) { - if (expression.Method.DeclaringType != typeof(NpgsqlNetworkAddressExtensions)) + if (expression.Method.DeclaringType != typeof(NpgsqlNetworkExtensions)) return null; switch (expression.Method.Name) { - case nameof(NpgsqlNetworkAddressExtensions.LessThan): + case nameof(NpgsqlNetworkExtensions.LessThan): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.LessThanOrEqual): + case nameof(NpgsqlNetworkExtensions.LessThanOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<=", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.Equal): + case nameof(NpgsqlNetworkExtensions.Equal): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "=", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.GreaterThanOrEqual): + case nameof(NpgsqlNetworkExtensions.GreaterThanOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">=", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.GreaterThan): + case nameof(NpgsqlNetworkExtensions.GreaterThan): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.NotEqual): + case nameof(NpgsqlNetworkExtensions.NotEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<>", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.ContainedBy): + case nameof(NpgsqlNetworkExtensions.ContainedBy): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<<", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.ContainedByOrEqual): + case nameof(NpgsqlNetworkExtensions.ContainedByOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<<=", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.Contains): + case nameof(NpgsqlNetworkExtensions.Contains): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.ContainsOrEqual): + case nameof(NpgsqlNetworkExtensions.ContainsOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">>=", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.ContainsOrContainedBy): + case nameof(NpgsqlNetworkExtensions.ContainsOrContainedBy): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "&&", typeof(bool)); - case nameof(NpgsqlNetworkAddressExtensions.Not): + case nameof(NpgsqlNetworkExtensions.Not): return new CustomUnaryExpression(expression.Arguments[1], "~", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkAddressExtensions.And): + case nameof(NpgsqlNetworkExtensions.And): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "&", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkAddressExtensions.Or): + case nameof(NpgsqlNetworkExtensions.Or): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "|", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkAddressExtensions.Add): + case nameof(NpgsqlNetworkExtensions.Add): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "+", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkAddressExtensions.Subtract): + case nameof(NpgsqlNetworkExtensions.Subtract): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "-", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkAddressExtensions.Abbreviate): + case nameof(NpgsqlNetworkExtensions.Abbreviate): return new PgFunctionExpression("abbrev", typeof(string), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.Broadcast): + case nameof(NpgsqlNetworkExtensions.Broadcast): return new PgFunctionExpression("broadcast", typeof(IPAddress), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.Family): + case nameof(NpgsqlNetworkExtensions.Family): return new PgFunctionExpression("family", typeof(int), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.Host): + case nameof(NpgsqlNetworkExtensions.Host): return new PgFunctionExpression("host", typeof(string), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.HostMask): + case nameof(NpgsqlNetworkExtensions.HostMask): return new PgFunctionExpression("hostmask", typeof(IPAddress), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.SubnetLength): + case nameof(NpgsqlNetworkExtensions.SubnetLength): return new PgFunctionExpression("masklen", typeof(int), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.SubnetMask): + case nameof(NpgsqlNetworkExtensions.SubnetMask): return new PgFunctionExpression("netmask", typeof(IPAddress), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.Network): + case nameof(NpgsqlNetworkExtensions.Network): return new PgFunctionExpression("network", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.SetSubnetLength): + case nameof(NpgsqlNetworkExtensions.SetSubnetLength): return new PgFunctionExpression("set_masklen", expression.Arguments[1].Type, new[] { expression.Arguments[1], expression.Arguments[2] }); - case nameof(NpgsqlNetworkAddressExtensions.Text): + case nameof(NpgsqlNetworkExtensions.Text): return new PgFunctionExpression("text", typeof(string), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.SameFamily): + case nameof(NpgsqlNetworkExtensions.SameFamily): return new PgFunctionExpression("inet_same_family", typeof(bool), new[] { expression.Arguments[1], expression.Arguments[2] }); - case nameof(NpgsqlNetworkAddressExtensions.Merge): + case nameof(NpgsqlNetworkExtensions.Merge): return new PgFunctionExpression("inet_merge", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1], expression.Arguments[2] }); - case nameof(NpgsqlNetworkAddressExtensions.Truncate): + case nameof(NpgsqlNetworkExtensions.Truncate): return new PgFunctionExpression("trunc", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkAddressExtensions.Set7BitMac8): + case nameof(NpgsqlNetworkExtensions.Set7BitMac8): return new PgFunctionExpression("macaddr8_set7bit", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); default: diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs similarity index 78% rename from test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs rename to test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs index c9bf85692..5aee6fb2f 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkAddressQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs @@ -19,7 +19,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query /// /// See: https://www.postgresql.org/docs/current/static/functions-net.html /// - public class NetworkAddressQueryNpgsqlTest : IClassFixture + public class NetworkQueryNpgsqlTest : IClassFixture { #region Setup @@ -32,7 +32,7 @@ public class NetworkAddressQueryNpgsqlTest : IClassFixture /// The fixture of resources for testing. - public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) + public NetworkQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) { Fixture = fixture; Fixture.TestSqlLoggerFactory.Clear(); @@ -45,7 +45,7 @@ public NetworkAddressQueryNpgsqlTest(NetworkAddressQueryNpgsqlFixture fixture) /// /// Demonstrates parameter duplication. /// - [Fact(Skip = nameof(NetworkAddressQueryNpgsqlTest))] + [Fact(Skip = nameof(NetworkQueryNpgsqlTest))] public void Demonstrate_ValueTypeParametersAreDuplicated() { using (NetContext context = Fixture.CreateContext()) @@ -68,7 +68,7 @@ public void Demonstrate_ValueTypeParametersAreDuplicated() #region RelationalOperatorTests /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_LessThan_inet() @@ -87,7 +87,7 @@ public void IPAddress_inet_LessThan_inet() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_LessThan_cidr() @@ -106,7 +106,7 @@ public void ValueTuple_cidr_LessThan_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_LessThan_macaddr() @@ -125,26 +125,24 @@ public void PhysicalAddress_macaddr_LessThan_macaddr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr8_LessThan_macaddr8() { using (NetContext context = Fixture.CreateContext()) { - PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); - NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.LessThan(x.Macaddr8, macaddr8)) + .Where(x => EF.Functions.LessThan(x.Macaddr8, x.Macaddr8)) .ToArray(); - AssertContainsSql("WHERE (x.\"Macaddr8\" < @__macaddr8_1) = TRUE"); + AssertContainsSql("WHERE (x.\"Macaddr8\" < x.\"Macaddr8\") = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_LessThanOrEqual_inet() @@ -163,7 +161,7 @@ public void IPAddress_inet_LessThanOrEqual_inet() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_LessThanOrEqual_cidr() @@ -182,7 +180,7 @@ public void ValueTuple_cidr_LessThanOrEqual_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_LessThanOrEqual_macaddr() @@ -201,26 +199,24 @@ public void PhysicalAddress_macaddr_LessThanOrEqual_macaddr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr8_LessThanOrEqual_macaddr8() { using (NetContext context = Fixture.CreateContext()) { - PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); - NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.LessThanOrEqual(x.Macaddr8, macaddr8)) + .Where(x => EF.Functions.LessThanOrEqual(x.Macaddr8, x.Macaddr8)) .ToArray(); - AssertContainsSql("WHERE (x.\"Macaddr8\" <= @__macaddr8_1) = TRUE"); + AssertContainsSql("WHERE (x.\"Macaddr8\" <= x.\"Macaddr8\") = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Equal_inet() @@ -239,7 +235,7 @@ public void IPAddress_inet_Equal_inet() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Equal_cidr() @@ -258,7 +254,7 @@ public void ValueTuple_cidr_Equal_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_Equal_macaddr() @@ -277,26 +273,24 @@ public void PhysicalAddress_macaddr_Equal_macaddr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr8_Equal_macaddr8() { using (NetContext context = Fixture.CreateContext()) { - PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); - NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.Equal(x.Macaddr8, macaddr8)) + .Where(x => EF.Functions.Equal(x.Macaddr8, x.Macaddr8)) .ToArray(); - AssertContainsSql("WHERE (x.\"Macaddr8\" = @__macaddr8_1) = TRUE"); + AssertContainsSql("WHERE (x.\"Macaddr8\" = x.\"Macaddr8\") = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_GreaterThanOrEqual_inet() @@ -315,7 +309,7 @@ public void IPAddress_inet_GreaterThanOrEqual_inet() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_GreaterThanOrEqual_cidr() @@ -334,7 +328,7 @@ public void ValueTuple_cidr_GreaterThanOrEqual_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_GreaterThanOrEqual_macaddr() @@ -353,26 +347,24 @@ public void PhysicalAddress_macaddr_GreaterThanOrEqual_macaddr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr8_GreaterThanOrEqual_macaddr8() { using (NetContext context = Fixture.CreateContext()) { - PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); - NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.GreaterThanOrEqual(x.Macaddr8, macaddr8)) + .Where(x => EF.Functions.GreaterThanOrEqual(x.Macaddr8, x.Macaddr8)) .ToArray(); - AssertContainsSql("WHERE (x.\"Macaddr8\" >= @__macaddr8_1) = TRUE"); + AssertContainsSql("WHERE (x.\"Macaddr8\" >= x.\"Macaddr8\") = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_GreaterThan_inet() @@ -391,7 +383,7 @@ public void IPAddress_inet_GreaterThan_inet() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_GreaterThan_cidr() @@ -410,7 +402,7 @@ public void ValueTuple_cidr_GreaterThan_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_GreaterThan_macaddr() @@ -429,26 +421,24 @@ public void PhysicalAddress_macaddr_GreaterThan_macaddr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr8_GreaterThan_macaddr8() { using (NetContext context = Fixture.CreateContext()) { - PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); - NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.GreaterThan(x.Macaddr8, macaddr8)) + .Where(x => EF.Functions.GreaterThan(x.Macaddr8, x.Macaddr8)) .ToArray(); - AssertContainsSql("WHERE (x.\"Macaddr8\" > @__macaddr8_1) = TRUE"); + AssertContainsSql("WHERE (x.\"Macaddr8\" > x.\"Macaddr8\") = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_NotEqual_inet() @@ -467,7 +457,7 @@ public void IPAddress_inet_NotEqual_inet() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_NotEqual_cidr() @@ -486,7 +476,7 @@ public void ValueTuple_cidr_NotEqual_cidr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_NotEqual_macaddr() @@ -505,21 +495,19 @@ public void PhysicalAddress_macaddr_NotEqual_macaddr() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr8_NotEqual_macaddr8() { using (NetContext context = Fixture.CreateContext()) { - PhysicalAddress macaddr8 = new PhysicalAddress(new byte[8]); - NetTestEntity[] _ = context.NetTestEntities - .Where(x => EF.Functions.NotEqual(x.Macaddr8, macaddr8)) + .Where(x => EF.Functions.NotEqual(x.Macaddr8, x.Macaddr8)) .ToArray(); - AssertContainsSql("WHERE (x.\"Macaddr8\" <> @__macaddr8_1) = TRUE"); + AssertContainsSql("WHERE (x.\"Macaddr8\" <> x.\"Macaddr8\") = TRUE"); } } @@ -528,7 +516,7 @@ public void PhysicalAddress_macaddr8_NotEqual_macaddr8() #region ContainmentOperatorTests /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_ContainedBy_inet() @@ -542,12 +530,12 @@ public void IPAddress_inet_ContainedBy_inet() .Where(x => EF.Functions.ContainedBy(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"Inet\" << @__inet_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Inet\" << @__inet_1) = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_ContainedBy_cidr() @@ -561,12 +549,12 @@ public void ValueTuple_cidr_ContainedBy_cidr() .Where(x => EF.Functions.ContainedBy(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"Cidr\" << @__cidr_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Cidr\" << @__cidr_1) = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_ContainedByOrEqual_inet() @@ -580,12 +568,12 @@ public void IPAddress_inet_ContainedByOrEqual_inet() .Where(x => EF.Functions.ContainedByOrEqual(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"Inet\" <<= @__inet_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Inet\" <<= @__inet_1) = TRUE"); } } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_ContainedByOrEqual_cidr() @@ -599,12 +587,12 @@ public void ValueTuple_cidr_ContainedByOrEqual_cidr() .Where(x => EF.Functions.ContainedByOrEqual(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"Cidr\" <<= @__cidr_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Cidr\" <<= @__cidr_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Contains_inet() @@ -618,12 +606,12 @@ public void IPAddress_inet_Contains_inet() .Where(x => EF.Functions.Contains(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"Inet\" >> @__inet_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Inet\" >> @__inet_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Contains_cidr() @@ -637,12 +625,12 @@ public void ValueTuple_cidr_Contains_cidr() .Where(x => EF.Functions.Contains(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"Cidr\" >> @__cidr_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Cidr\" >> @__cidr_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_ContainsOrEquals_inet() @@ -656,12 +644,12 @@ public void IPAddress_inet_ContainsOrEquals_inet() .Where(x => EF.Functions.ContainsOrEqual(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"Inet\" >>= @__inet_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Inet\" >>= @__inet_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_ContainsOrEquals_cidr() @@ -675,12 +663,12 @@ public void ValueTuple_cidr_ContainsOrEquals_cidr() .Where(x => EF.Functions.ContainsOrEqual(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"Cidr\" >>= @__cidr_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Cidr\" >>= @__cidr_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_ContainsOrContainedBy_inet() @@ -694,12 +682,12 @@ public void IPAddress_inet_ContainsOrContainedBy_inet() .Where(x => EF.Functions.ContainsOrContainedBy(x.Inet, inet)) .ToArray(); - AssertContainsSql("WHERE x.\"Inet\" && @__inet_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Inet\" && @__inet_1) = TRUE"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_ContainsOrContainedBy_cidr() @@ -713,7 +701,7 @@ public void ValueTuple_cidr_ContainsOrContainedBy_cidr() .Where(x => EF.Functions.ContainsOrContainedBy(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("WHERE x.\"Cidr\" && @__cidr_1 = TRUE"); + AssertContainsSql("WHERE (x.\"Cidr\" && @__cidr_1) = TRUE"); } } @@ -722,7 +710,7 @@ public void ValueTuple_cidr_ContainsOrContainedBy_cidr() #region BitwiseOperatorTests /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Not() @@ -739,7 +727,7 @@ public void IPAddress_inet_Not() } /// - /// Tests inverse translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Not() @@ -756,7 +744,7 @@ public void ValueTuple_cidr_Not() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_And_inet() @@ -770,12 +758,12 @@ public void IPAddress_inet_And_inet() .Select(x => EF.Functions.And(x.Inet, inet)) .ToArray(); - AssertContainsSql("SELECT x.\"Inet\" & @__inet_1"); + AssertContainsSql("SELECT (x.\"Inet\" & @__inet_1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_And_cidr() @@ -789,12 +777,12 @@ public void ValueTuple_cidr_And_cidr() .Select(x => EF.Functions.And(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("SELECT x.\"Cidr\" & @__cidr_1"); + AssertContainsSql("SELECT (x.\"Cidr\" & @__cidr_1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Or_inet() @@ -808,12 +796,12 @@ public void IPAddress_inet_Or_inet() .Select(x => EF.Functions.Or(x.Inet, inet)) .ToArray(); - AssertContainsSql("SELECT x.\"Inet\" | @__inet_1"); + AssertContainsSql("SELECT (x.\"Inet\" | @__inet_1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Or_cidr() @@ -827,7 +815,7 @@ public void ValueTuple_cidr_Or_cidr() .Select(x => EF.Functions.Or(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("SELECT x.\"Cidr\" | @__cidr_1"); + AssertContainsSql("SELECT (x.\"Cidr\" | @__cidr_1)"); } } @@ -836,7 +824,7 @@ public void ValueTuple_cidr_Or_cidr() #region ArithmeticOperatorTests /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Add_int() @@ -848,12 +836,12 @@ public void IPAddress_inet_Add_int() .Select(x => EF.Functions.Add(x.Inet, 1)) .ToArray(); - AssertContainsSql("SELECT x.\"Inet\" + 1"); + AssertContainsSql("SELECT (x.\"Inet\" + 1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Add_int() @@ -865,12 +853,12 @@ public void ValueTuple_cidr_Add_int() .Select(x => EF.Functions.Add(x.Cidr, 1)) .ToArray(); - AssertContainsSql("SELECT x.\"Cidr\" + 1"); + AssertContainsSql("SELECT (x.\"Cidr\" + 1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Subtract_int() @@ -882,12 +870,12 @@ public void IPAddress_inet_Subtract_int() .Select(x => EF.Functions.Subtract(x.Inet, 1)) .ToArray(); - AssertContainsSql("SELECT x.\"Inet\" - 1"); + AssertContainsSql("SELECT (x.\"Inet\" - 1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Subtract_int() @@ -899,12 +887,12 @@ public void ValueTuple_cidr_Subtract_int() .Select(x => EF.Functions.Subtract(x.Cidr, 1)) .ToArray(); - AssertContainsSql("SELECT x.\"Cidr\" - 1"); + AssertContainsSql("SELECT (x.\"Cidr\" - 1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Subtract_inet() @@ -918,12 +906,12 @@ public void IPAddress_inet_Subtract_inet() .Select(x => EF.Functions.Subtract(x.Inet, inet)) .ToArray(); - AssertContainsSql("SELECT x.\"Inet\" - @__inet_1"); + AssertContainsSql("SELECT (x.\"Inet\" - @__inet_1)"); } } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Subtract_cidr() @@ -937,7 +925,7 @@ public void ValueTuple_cidr_Subtract_cidr() .Select(x => EF.Functions.Subtract(x.Cidr, cidr)) .ToArray(); - AssertContainsSql("SELECT x.\"Cidr\" - @__cidr_1"); + AssertContainsSql("SELECT (x.\"Cidr\" - @__cidr_1)"); } } @@ -946,7 +934,7 @@ public void ValueTuple_cidr_Subtract_cidr() #region FunctionTests /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Abbreviate() @@ -963,7 +951,7 @@ public void IPAddress_inet_Abbreviate() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Abbrebiate() @@ -980,7 +968,7 @@ public void ValueTuple_cidr_Abbrebiate() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Broadcast() @@ -997,7 +985,7 @@ public void IPAddress_inet_Broadcast() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Broadcast() @@ -1014,7 +1002,7 @@ public void ValueTuple_cidr_Broadcast() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Family() @@ -1031,7 +1019,7 @@ public void IPAddress_inet_Family() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Family() @@ -1048,7 +1036,7 @@ public void ValueTuple_cidr_Family() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Host() @@ -1065,7 +1053,7 @@ public void IPAddress_inet_Host() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Host() @@ -1082,7 +1070,7 @@ public void ValueTuple_cidr_Host() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_HostMask() @@ -1099,7 +1087,7 @@ public void IPAddress_inet_HostMask() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_HostMask() @@ -1116,7 +1104,7 @@ public void ValueTuple_cidr_HostMask() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_SubnetLength() @@ -1133,7 +1121,7 @@ public void IPAddress_inet_SubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_SubnetLength() @@ -1150,7 +1138,7 @@ public void ValueTuple_cidr_SubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_SubnetMask() @@ -1167,7 +1155,7 @@ public void IPAddress_inet_SubnetMask() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_SubnetMask() @@ -1184,7 +1172,7 @@ public void ValueTuple_cidr_SubnetMask() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Network() @@ -1201,7 +1189,7 @@ public void IPAddress_inet_Network() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Network() @@ -1218,7 +1206,7 @@ public void ValueTuple_cidr_Network() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_SetSubnetLength() @@ -1235,7 +1223,7 @@ public void IPAddress_inet_SetSubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_SetSubnetLength() @@ -1252,7 +1240,7 @@ public void ValueTuple_cidr_SetSubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Text() @@ -1269,7 +1257,7 @@ public void IPAddress_inet_Text() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Text() @@ -1286,7 +1274,7 @@ public void ValueTuple_cidr_Text() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_SameFamily() @@ -1305,7 +1293,7 @@ public void IPAddress_inet_SameFamily() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_SameFamily() @@ -1324,7 +1312,7 @@ public void ValueTuple_cidr_SameFamily() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void IPAddress_inet_Merge() @@ -1343,7 +1331,7 @@ public void IPAddress_inet_Merge() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void ValueTuple_cidr_Merge() @@ -1362,7 +1350,7 @@ public void ValueTuple_cidr_Merge() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_Truncate() @@ -1384,7 +1372,7 @@ public void PhysicalAddress_macaddr_Truncate() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] public void PhysicalAddress_macaddr_Set7BitMac8() From a665a1101cf8ded4119163bdcc4ccbcc844d914c Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Sun, 27 May 2018 11:03:46 -0400 Subject: [PATCH 11/13] Update naming and overloads - Adds missing tests for bitwise operators on `PhysicalAddress`. - For `macaddr` and `macaddr8`. - Adds overloads mixing `inet` and `cidr` and related tests. --- .../Extensions/NpgsqlNetworkExtensions.cs | 298 ++++++++++++---- .../Extensions/NpgsqlRangeExtensions.cs | 1 - .../Internal/NpgsqlNetworkTranslator.cs | 41 +-- .../Mapping/NpgsqlNetworkTypeMappings.cs | 16 +- .../Query/NetworkQueryNpgsqlTest.cs | 324 +++++++++++++++--- 5 files changed, 535 insertions(+), 145 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs index c0448914c..24d3be8a2 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs @@ -37,7 +37,6 @@ namespace Microsoft.EntityFrameworkCore /// /// See: https://www.postgresql.org/docs/current/static/functions-net.html /// - [PublicAPI] public static class NpgsqlNetworkExtensions { #region RelationalOperators @@ -54,7 +53,8 @@ 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 new ClientEvaluationNotSupportedException(); + public static bool LessThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is less than another (IPAddress Address, int Subnet). @@ -68,7 +68,8 @@ 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 Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool LessThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is less than another . @@ -82,7 +83,8 @@ 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 _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool LessThan([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is less than or equal to another . @@ -96,7 +98,8 @@ 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 LessThanOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is less than or equal to another (IPAddress Address, int Subnet). @@ -110,7 +113,8 @@ 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 LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is less than or equal to another . @@ -124,7 +128,8 @@ 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 LessThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is equal to another . @@ -138,7 +143,8 @@ 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 Equal([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool Equal([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is equal to another (IPAddress Address, int Subnet). @@ -152,7 +158,8 @@ 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 Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is equal to another . @@ -166,7 +173,8 @@ 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 Equal([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool Equal([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than or equal to another . @@ -180,7 +188,8 @@ 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 GreaterThanOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is greater than or equal to another (IPAddress Address, int Subnet). @@ -194,7 +203,8 @@ 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 GreaterThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than or equal to another . @@ -208,7 +218,8 @@ 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 GreaterThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than another . @@ -222,7 +233,8 @@ 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 GreaterThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool GreaterThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is greater than another (IPAddress Address, int Subnet). @@ -236,7 +248,8 @@ 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 GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than another . @@ -250,7 +263,8 @@ 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 GreaterThan([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool GreaterThan([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is not equal to another . @@ -264,7 +278,8 @@ 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 NotEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool NotEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is not equal to another (IPAddress Address, int Subnet). @@ -278,7 +293,8 @@ 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 NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is not equal to another . @@ -292,7 +308,8 @@ 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 NotEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool NotEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); #endregion @@ -310,7 +327,23 @@ 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 ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is contained within a network. + /// + /// The instance. + /// The inet to locate. + /// The cidr to search. + /// + /// True if the is contained within the network; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is contained within another (IPAddress Address, int Subnet). @@ -324,7 +357,8 @@ 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 ContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an is contained within or equal to another . @@ -338,7 +372,23 @@ 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 ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an is contained within or equal to a network. + /// + /// The instance. + /// The inet to locate. + /// The cidr to search. + /// + /// True if the is contained within or equal to the network; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is contained within or equal to another (IPAddress Address, int Subnet). @@ -352,7 +402,8 @@ 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 ContainedByOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an contains another . @@ -366,7 +417,23 @@ 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 Contains([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool Contains([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether a network contains another . + /// + /// The instance. + /// The network to search. + /// The IP address to locate. + /// + /// True if the network contains the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). @@ -380,7 +447,8 @@ 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 Contains([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an contains or is equal to another . @@ -394,7 +462,23 @@ 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 ContainsOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether a network contains or is equal to another . + /// + /// The instance. + /// The network to search. + /// The IP address to locate. + /// + /// True if the network contains or is equal to the other ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). @@ -408,7 +492,8 @@ 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 ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Determines whether an contains or is contained by another . @@ -422,7 +507,38 @@ 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 ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether a network contains or is contained by an . + /// + /// The instance. + /// The network to search. + /// The IP address to locate. + /// + /// True if the network contains or is contained by the ; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); + + /// + /// Determines whether an contains or is contained by a network. + /// + /// The instance. + /// The IP address to search. + /// The network to locate. + /// + /// True if the contains or is contained by the network; otherwise, false. + /// + /// + /// 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 new ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is contained by another (IPAddress Address, int Subnet). @@ -436,7 +552,8 @@ 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 ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); #endregion @@ -453,7 +570,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static IPAddress Not([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress BitwiseNot([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise NOT operation on an (IPAddress Address, int Subnet). @@ -466,7 +584,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static (IPAddress Address, int Subnet) Not([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) BitwiseNot([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise NOT operation on an . @@ -479,7 +598,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static PhysicalAddress Not([CanBeNull] this DbFunctions _, PhysicalAddress macaddr) => throw new ClientEvaluationNotSupportedException(); + public static PhysicalAddress BitwiseNot([CanBeNull] this DbFunctions _, PhysicalAddress macaddr) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise AND of two instances. @@ -493,7 +613,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static IPAddress And([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress BitwiseAnd([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise AND of two (IPAddress Address, int Subnet) instances. @@ -507,7 +628,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static (IPAddress Address, int Subnet) And([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) BitwiseAnd([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise AND of two instances. @@ -521,7 +643,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static PhysicalAddress And([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static PhysicalAddress BitwiseAnd([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise OR of two instances. @@ -535,7 +658,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static IPAddress Or([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress BitwiseOr([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise OR of two (IPAddress Address, int Subnet) instances. @@ -549,7 +673,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static (IPAddress Address, int Subnet) Or([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) BitwiseOr([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Computes the bitwise OR of two instances. @@ -563,7 +688,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static PhysicalAddress Or([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw new ClientEvaluationNotSupportedException(); + public static PhysicalAddress BitwiseOr([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) + => throw new ClientEvaluationNotSupportedException(); #endregion @@ -581,7 +707,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static IPAddress Add([CanBeNull] this DbFunctions _, IPAddress inet, int value) + => throw new ClientEvaluationNotSupportedException(); /// /// Adds the to the (IPAddress Address, int Subnet). @@ -595,7 +722,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Add([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int value) + => throw new ClientEvaluationNotSupportedException(); /// /// Subtracts the from the . @@ -609,7 +737,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static IPAddress Subtract([CanBeNull] this DbFunctions _, IPAddress inet, int value) + => throw new ClientEvaluationNotSupportedException(); /// /// Subtracts the from the (IPAddress Address, int Subnet). @@ -623,7 +752,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int value) + => throw new ClientEvaluationNotSupportedException(); /// /// Subtracts one from another . @@ -637,7 +767,8 @@ public static class NpgsqlNetworkExtensions /// /// 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, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress Subtract([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Subtracts one (IPAddress Address, int Subnet) from another (IPAddress Address, int Subnet). @@ -651,7 +782,8 @@ public static class NpgsqlNetworkExtensions /// /// 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, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); #endregion @@ -668,7 +800,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static string Abbreviate([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Returns the abbreviated display format as text. @@ -681,7 +814,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static string Abbreviate([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Returns the broadcast address for a network. @@ -694,7 +828,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static IPAddress Broadcast([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Returns the broadcast address for a network. @@ -707,7 +842,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static IPAddress Broadcast([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. @@ -720,7 +856,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static int Family([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. @@ -733,7 +870,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static int Family([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the host (i.e. the IP address) as text. @@ -746,7 +884,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static string Host([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the host (i.e. the IP address) as text. @@ -759,7 +898,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static string Host([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Constructs the host mask for the network. @@ -772,7 +912,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static IPAddress HostMask([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Constructs the host mask for the network. @@ -785,7 +926,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static IPAddress HostMask([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the length of the subnet mask. @@ -798,7 +940,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static int SubnetLength([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + public static int MaskLength([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the length of the subnet mask. @@ -811,7 +954,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static int SubnetLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + public static int MaskLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Constructs the subnet mask for the network. @@ -824,7 +968,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static IPAddress SubnetMask([CanBeNull] this DbFunctions _, IPAddress inet) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress Netmask([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Constructs the subnet mask for the network. @@ -837,7 +982,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static IPAddress SubnetMask([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress Netmask([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the network part of the address. @@ -850,7 +996,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the network part of the address. @@ -863,7 +1010,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Sets the length of the subnet mask. @@ -877,7 +1025,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static IPAddress SetSubnetLength([CanBeNull] this DbFunctions _, IPAddress inet, int length) => throw new ClientEvaluationNotSupportedException(); + public static IPAddress SetMaskLength([CanBeNull] this DbFunctions _, IPAddress inet, int length) + => throw new ClientEvaluationNotSupportedException(); /// /// Sets the length of the subnet mask. @@ -891,7 +1040,8 @@ public static class NpgsqlNetworkExtensions /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// - public static (IPAddress Address, int Subnet) SetSubnetLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int length) => throw new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) SetMaskLength([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, int length) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the IP address and subnet mask as text. @@ -904,7 +1054,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static string Text([CanBeNull] this DbFunctions _, IPAddress inet) + => throw new ClientEvaluationNotSupportedException(); /// /// Extracts the IP address and subnet mask as text. @@ -917,7 +1068,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static string Text([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) + => throw new ClientEvaluationNotSupportedException(); /// /// Tests if the addresses are in the same family. @@ -931,7 +1083,8 @@ 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 SameFamily([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) => throw new ClientEvaluationNotSupportedException(); + public static bool SameFamily([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Tests if the addresses are in the same family. @@ -945,7 +1098,8 @@ 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 SameFamily([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) => throw new ClientEvaluationNotSupportedException(); + public static bool SameFamily([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Constructs the smallest network which includes both of the given networks. @@ -959,7 +1113,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) + => throw new ClientEvaluationNotSupportedException(); /// /// Constructs the smallest network which includes both of the given networks. @@ -973,7 +1128,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) + => throw new ClientEvaluationNotSupportedException(); /// /// Sets the last 3 bytes of the MAC address to zero. For macaddr8, the last 5 bytes are set to zero. @@ -986,7 +1142,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static PhysicalAddress Truncate([CanBeNull] this DbFunctions _, PhysicalAddress macAddress) + => throw new ClientEvaluationNotSupportedException(); /// /// Sets the 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 address. @@ -999,7 +1156,8 @@ public static class NpgsqlNetworkExtensions /// /// 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 new ClientEvaluationNotSupportedException(); + public static PhysicalAddress Set7BitMac8([CanBeNull] this DbFunctions _, PhysicalAddress macAddress) + => throw new ClientEvaluationNotSupportedException(); #endregion } diff --git a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs index 5dab8880e..132f5eaf0 100644 --- a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs @@ -33,7 +33,6 @@ namespace Microsoft.EntityFrameworkCore /// /// Provides extension methods for supporting PostgreSQL translation. /// - [PublicAPI] public static class NpgsqlRangeExtensions { /// diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs index 2eae914b9..fbb82b400 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs @@ -28,6 +28,7 @@ using System.Net.NetworkInformation; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Query.Expressions; using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators; using Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal; @@ -83,13 +84,13 @@ public Expression Translate(MethodCallExpression expression) case nameof(NpgsqlNetworkExtensions.ContainsOrContainedBy): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "&&", typeof(bool)); - case nameof(NpgsqlNetworkExtensions.Not): + case nameof(NpgsqlNetworkExtensions.BitwiseNot): return new CustomUnaryExpression(expression.Arguments[1], "~", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkExtensions.And): + case nameof(NpgsqlNetworkExtensions.BitwiseAnd): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "&", expression.Arguments[1].Type); - case nameof(NpgsqlNetworkExtensions.Or): + case nameof(NpgsqlNetworkExtensions.BitwiseOr): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "|", expression.Arguments[1].Type); case nameof(NpgsqlNetworkExtensions.Add): @@ -99,46 +100,46 @@ public Expression Translate(MethodCallExpression expression) return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "-", expression.Arguments[1].Type); case nameof(NpgsqlNetworkExtensions.Abbreviate): - return new PgFunctionExpression("abbrev", typeof(string), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("abbrev", typeof(string), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.Broadcast): - return new PgFunctionExpression("broadcast", typeof(IPAddress), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("broadcast", typeof(IPAddress), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.Family): - return new PgFunctionExpression("family", typeof(int), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("family", typeof(int), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.Host): - return new PgFunctionExpression("host", typeof(string), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("host", typeof(string), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.HostMask): - return new PgFunctionExpression("hostmask", typeof(IPAddress), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("hostmask", typeof(IPAddress), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkExtensions.SubnetLength): - return new PgFunctionExpression("masklen", typeof(int), new[] { expression.Arguments[1] }); + case nameof(NpgsqlNetworkExtensions.MaskLength): + return new SqlFunctionExpression("masklen", typeof(int), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkExtensions.SubnetMask): - return new PgFunctionExpression("netmask", typeof(IPAddress), new[] { expression.Arguments[1] }); + case nameof(NpgsqlNetworkExtensions.Netmask): + return new SqlFunctionExpression("netmask", typeof(IPAddress), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.Network): - return new PgFunctionExpression("network", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("network", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1] }); - case nameof(NpgsqlNetworkExtensions.SetSubnetLength): - return new PgFunctionExpression("set_masklen", expression.Arguments[1].Type, new[] { expression.Arguments[1], expression.Arguments[2] }); + case nameof(NpgsqlNetworkExtensions.SetMaskLength): + return new SqlFunctionExpression("set_masklen", expression.Arguments[1].Type, new[] { expression.Arguments[1], expression.Arguments[2] }); case nameof(NpgsqlNetworkExtensions.Text): - return new PgFunctionExpression("text", typeof(string), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("text", typeof(string), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.SameFamily): - return new PgFunctionExpression("inet_same_family", typeof(bool), new[] { expression.Arguments[1], expression.Arguments[2] }); + return new SqlFunctionExpression("inet_same_family", typeof(bool), new[] { expression.Arguments[1], expression.Arguments[2] }); case nameof(NpgsqlNetworkExtensions.Merge): - return new PgFunctionExpression("inet_merge", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1], expression.Arguments[2] }); + return new SqlFunctionExpression("inet_merge", typeof((IPAddress Address, int Subnet)), new[] { expression.Arguments[1], expression.Arguments[2] }); case nameof(NpgsqlNetworkExtensions.Truncate): - return new PgFunctionExpression("trunc", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("trunc", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); case nameof(NpgsqlNetworkExtensions.Set7BitMac8): - return new PgFunctionExpression("macaddr8_set7bit", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); + return new SqlFunctionExpression("macaddr8_set7bit", typeof(PhysicalAddress), new[] { expression.Arguments[1] }); default: return null; diff --git a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs index cfdc8ff5b..d57417936 100644 --- a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs +++ b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs @@ -33,10 +33,10 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping { public class NpgsqlMacaddrTypeMapping : NpgsqlTypeMapping { - public NpgsqlMacaddrTypeMapping() : base("macaddr", typeof(PhysicalAddress), NpgsqlDbType.MacAddr) { } + public NpgsqlMacaddrTypeMapping() : base("macaddr", typeof(PhysicalAddress), NpgsqlDbType.MacAddr) {} protected NpgsqlMacaddrTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) { } + : base(parameters, npgsqlDbType) {} public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlMacaddrTypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); @@ -50,10 +50,10 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlMacaddr8TypeMapping : NpgsqlTypeMapping { - public NpgsqlMacaddr8TypeMapping() : base("macaddr8", typeof(PhysicalAddress), NpgsqlDbType.MacAddr8) { } + public NpgsqlMacaddr8TypeMapping() : base("macaddr8", typeof(PhysicalAddress), NpgsqlDbType.MacAddr8) {} protected NpgsqlMacaddr8TypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) { } + : base(parameters, npgsqlDbType) {} public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlMacaddr8TypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); @@ -67,10 +67,10 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlInetTypeMapping : NpgsqlTypeMapping { - public NpgsqlInetTypeMapping() : base("inet", typeof(IPAddress), NpgsqlDbType.Inet) { } + public NpgsqlInetTypeMapping() : base("inet", typeof(IPAddress), NpgsqlDbType.Inet) {} protected NpgsqlInetTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) { } + : base(parameters, npgsqlDbType) {} public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlInetTypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); @@ -84,10 +84,10 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlCidrTypeMapping : NpgsqlTypeMapping { - public NpgsqlCidrTypeMapping() : base("cidr", typeof((IPAddress, int)), NpgsqlDbType.Cidr) { } + public NpgsqlCidrTypeMapping() : base("cidr", typeof((IPAddress, int)), NpgsqlDbType.Cidr) {} protected NpgsqlCidrTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType) - : base(parameters, npgsqlDbType) { } + : base(parameters, npgsqlDbType) {} public override RelationalTypeMapping Clone(string storeType, int? size) => new NpgsqlCidrTypeMapping(Parameters.WithStoreTypeAndSize(storeType, size), NpgsqlDbType); diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs index 5aee6fb2f..d6e258feb 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs @@ -534,6 +534,25 @@ public void IPAddress_inet_ContainedBy_inet() } } + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_ContainedBy_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainedBy(x.Inet, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Inet\" << @__cidr_1) = TRUE"); + } + } + /// /// Tests translation for . /// @@ -572,6 +591,25 @@ public void IPAddress_inet_ContainedByOrEqual_inet() } } + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_ContainedByOrEqual_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainedByOrEqual(x.Inet, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Inet\" <<= @__cidr_1) = TRUE"); + } + } + /// /// Tests translation for . /// @@ -610,6 +648,25 @@ public void IPAddress_inet_Contains_inet() } } + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_Contains_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = IPAddress.Any; + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.Contains(x.Cidr, inet)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" >> @__inet_1) = TRUE"); + } + } + /// /// Tests translation for . /// @@ -633,7 +690,7 @@ public void ValueTuple_cidr_Contains_cidr() /// Tests translation for . /// [Fact] - public void IPAddress_inet_ContainsOrEquals_inet() + public void IPAddress_inet_ContainsOrEqual_inet() { using (NetContext context = Fixture.CreateContext()) { @@ -648,11 +705,30 @@ public void IPAddress_inet_ContainsOrEquals_inet() } } + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_ContainsOrEqual_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = IPAddress.Any; + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainsOrEqual(x.Cidr, inet)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" >>= @__inet_1) = TRUE"); + } + } + /// /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_ContainsOrEquals_cidr() + public void ValueTuple_cidr_ContainsOrEqual_cidr() { using (NetContext context = Fixture.CreateContext()) { @@ -686,6 +762,44 @@ public void IPAddress_inet_ContainsOrContainedBy_inet() } } + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_ContainsOrContainedBy_cidr() + { + using (NetContext context = Fixture.CreateContext()) + { + (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainsOrContainedBy(x.Inet, cidr)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Inet\" && @__cidr_1) = TRUE"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void ValueTuple_cidr_ContainsOrContainedBy_inet() + { + using (NetContext context = Fixture.CreateContext()) + { + IPAddress inet = IPAddress.Any; + + NetTestEntity[] _ = + context.NetTestEntities + .Where(x => EF.Functions.ContainsOrContainedBy(x.Cidr, inet)) + .ToArray(); + + AssertContainsSql("WHERE (x.\"Cidr\" && @__inet_1) = TRUE"); + } + } + /// /// Tests translation for . /// @@ -710,16 +824,16 @@ public void ValueTuple_cidr_ContainsOrContainedBy_cidr() #region BitwiseOperatorTests /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void IPAddress_inet_Not() + public void IPAddress_inet_BitwiseNot() { using (NetContext context = Fixture.CreateContext()) { IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.Not(x.Inet)) + .Select(x => EF.Functions.BitwiseNot(x.Inet)) .ToArray(); AssertContainsSql("SELECT ~x.\"Inet\""); @@ -727,16 +841,16 @@ public void IPAddress_inet_Not() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_Not() + public void ValueTuple_cidr_BitwiseNot() { using (NetContext context = Fixture.CreateContext()) { (IPAddress Address, int Subnet)[] _ = context.NetTestEntities - .Select(x => EF.Functions.Not(x.Cidr)) + .Select(x => EF.Functions.BitwiseNot(x.Cidr)) .ToArray(); AssertContainsSql("SELECT ~x.\"Cidr\""); @@ -744,10 +858,44 @@ public void ValueTuple_cidr_Not() } /// - /// Tests translation for . + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_BitwiseNot() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.BitwiseNot(x.Macaddr)) + .ToArray(); + + AssertContainsSql("SELECT ~x.\"Macaddr\""); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_BitwiseNot() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.BitwiseNot(x.Macaddr8)) + .ToArray(); + + AssertContainsSql("SELECT ~x.\"Macaddr8\""); + } + } + + /// + /// Tests translation for . /// [Fact] - public void IPAddress_inet_And_inet() + public void IPAddress_inet_BitwiseAnd_inet() { using (NetContext context = Fixture.CreateContext()) { @@ -755,7 +903,7 @@ public void IPAddress_inet_And_inet() IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.And(x.Inet, inet)) + .Select(x => EF.Functions.BitwiseAnd(x.Inet, inet)) .ToArray(); AssertContainsSql("SELECT (x.\"Inet\" & @__inet_1)"); @@ -763,10 +911,10 @@ public void IPAddress_inet_And_inet() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_And_cidr() + public void ValueTuple_cidr_BitwiseAnd_cidr() { using (NetContext context = Fixture.CreateContext()) { @@ -774,7 +922,7 @@ public void ValueTuple_cidr_And_cidr() (IPAddress Address, int Subnet)[] _ = context.NetTestEntities - .Select(x => EF.Functions.And(x.Cidr, cidr)) + .Select(x => EF.Functions.BitwiseAnd(x.Cidr, cidr)) .ToArray(); AssertContainsSql("SELECT (x.\"Cidr\" & @__cidr_1)"); @@ -782,10 +930,46 @@ public void ValueTuple_cidr_And_cidr() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void IPAddress_inet_Or_inet() + public void PhysicalAddress_macaddr_BitwiseAnd_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.BitwiseAnd(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("SELECT (x.\"Macaddr\" & @__macaddr_1)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_BitwiseAnd_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.BitwiseAnd(x.Macaddr8, x.Macaddr8)) + .ToArray(); + + AssertContainsSql("SELECT (x.\"Macaddr8\" & x.\"Macaddr8\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void IPAddress_inet_BitwiseOr_inet() { using (NetContext context = Fixture.CreateContext()) { @@ -793,7 +977,7 @@ public void IPAddress_inet_Or_inet() IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.Or(x.Inet, inet)) + .Select(x => EF.Functions.BitwiseOr(x.Inet, inet)) .ToArray(); AssertContainsSql("SELECT (x.\"Inet\" | @__inet_1)"); @@ -801,10 +985,10 @@ public void IPAddress_inet_Or_inet() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_Or_cidr() + public void ValueTuple_cidr_BitwiseOr_cidr() { using (NetContext context = Fixture.CreateContext()) { @@ -812,13 +996,49 @@ public void ValueTuple_cidr_Or_cidr() (IPAddress Address, int Subnet)[] _ = context.NetTestEntities - .Select(x => EF.Functions.Or(x.Cidr, cidr)) + .Select(x => EF.Functions.BitwiseOr(x.Cidr, cidr)) .ToArray(); AssertContainsSql("SELECT (x.\"Cidr\" | @__cidr_1)"); } } + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr_BitwiseOr_macaddr() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); + + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.BitwiseOr(x.Macaddr, macaddr)) + .ToArray(); + + AssertContainsSql("SELECT (x.\"Macaddr\" | @__macaddr_1)"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_BitwiseOr_macaddr8() + { + using (NetContext context = Fixture.CreateContext()) + { + PhysicalAddress[] _ = + context.NetTestEntities + .Select(x => EF.Functions.BitwiseOr(x.Macaddr8, x.Macaddr8)) + .ToArray(); + + AssertContainsSql("SELECT (x.\"Macaddr8\" | x.\"Macaddr8\")"); + } + } + #endregion #region ArithmeticOperatorTests @@ -1104,16 +1324,16 @@ public void ValueTuple_cidr_HostMask() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void IPAddress_inet_SubnetLength() + public void IPAddress_inet_MaskLength() { using (NetContext context = Fixture.CreateContext()) { int[] _ = context.NetTestEntities - .Select(x => EF.Functions.SubnetLength(x.Inet)) + .Select(x => EF.Functions.MaskLength(x.Inet)) .ToArray(); AssertContainsSql("SELECT masklen(x.\"Inet\")"); @@ -1121,16 +1341,16 @@ public void IPAddress_inet_SubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_SubnetLength() + public void ValueTuple_cidr_MaskLength() { using (NetContext context = Fixture.CreateContext()) { int[] _ = context.NetTestEntities - .Select(x => EF.Functions.SubnetLength(x.Cidr)) + .Select(x => EF.Functions.MaskLength(x.Cidr)) .ToArray(); AssertContainsSql("SELECT masklen(x.\"Cidr\")"); @@ -1138,16 +1358,16 @@ public void ValueTuple_cidr_SubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void IPAddress_inet_SubnetMask() + public void IPAddress_inet_Netmask() { using (NetContext context = Fixture.CreateContext()) { IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.SubnetMask(x.Inet)) + .Select(x => EF.Functions.Netmask(x.Inet)) .ToArray(); AssertContainsSql("SELECT netmask(x.\"Inet\")"); @@ -1155,16 +1375,16 @@ public void IPAddress_inet_SubnetMask() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_SubnetMask() + public void ValueTuple_cidr_Netmask() { using (NetContext context = Fixture.CreateContext()) { IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.SubnetMask(x.Cidr)) + .Select(x => EF.Functions.Netmask(x.Cidr)) .ToArray(); AssertContainsSql("SELECT netmask(x.\"Cidr\")"); @@ -1206,16 +1426,16 @@ public void ValueTuple_cidr_Network() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void IPAddress_inet_SetSubnetLength() + public void IPAddress_inet_SetMaskLength() { using (NetContext context = Fixture.CreateContext()) { IPAddress[] _ = context.NetTestEntities - .Select(x => EF.Functions.SetSubnetLength(x.Inet, default)) + .Select(x => EF.Functions.SetMaskLength(x.Inet, default)) .ToArray(); AssertContainsSql("SELECT set_masklen(x.\"Inet\", 0)"); @@ -1223,16 +1443,16 @@ public void IPAddress_inet_SetSubnetLength() } /// - /// Tests translation for . + /// Tests translation for . /// [Fact] - public void ValueTuple_cidr_SetSubnetLength() + public void ValueTuple_cidr_SetMaskLength() { using (NetContext context = Fixture.CreateContext()) { (IPAddress Address, int Subnet)[] _ = context.NetTestEntities - .Select(x => EF.Functions.SetSubnetLength(x.Cidr, default)) + .Select(x => EF.Functions.SetMaskLength(x.Cidr, default)) .ToArray(); AssertContainsSql("SELECT set_masklen(x.\"Cidr\", 0)"); @@ -1359,15 +1579,27 @@ public void PhysicalAddress_macaddr_Truncate() { var _ = context.NetTestEntities - .Select( - x => new - { - macaddr = EF.Functions.Truncate(x.Macaddr), - macaddr8 = EF.Functions.Truncate(x.Macaddr8) - }) + .Select(x => EF.Functions.Truncate(x.Macaddr)) + .ToArray(); + + AssertContainsSql("SELECT trunc(x.\"Macaddr\")"); + } + } + + /// + /// Tests translation for . + /// + [Fact] + public void PhysicalAddress_macaddr8_Truncate() + { + using (NetContext context = Fixture.CreateContext()) + { + var _ = + context.NetTestEntities + .Select(x => EF.Functions.Truncate(x.Macaddr8)) .ToArray(); - AssertContainsSql("SELECT trunc(x.\"Macaddr\") AS macaddr, trunc(x.\"Macaddr8\") AS macaddr8"); + AssertContainsSql("SELECT trunc(x.\"Macaddr8\")"); } } @@ -1375,7 +1607,7 @@ public void PhysicalAddress_macaddr_Truncate() /// Tests translation for . /// [Fact] - public void PhysicalAddress_macaddr_Set7BitMac8() + public void PhysicalAddress_macaddr8_Set7BitMac8() { using (NetContext context = Fixture.CreateContext()) { From 3ca6977533dfd7b8475e678ed1d681d8f3044992 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Sun, 15 Jul 2018 16:30:47 -0400 Subject: [PATCH 12/13] Split off unrelated changes and rollback - ClientEvaluationNotSupportedException.cs - NpgsqlRangeExtensions.cs --- .../Extensions/NpgsqlNetworkExtensions.cs | 318 +++++++++--------- .../Extensions/NpgsqlRangeExtensions.cs | 81 ++--- .../ClientEvaluationNotSupportedException.cs | 48 --- 3 files changed, 189 insertions(+), 258 deletions(-) delete mode 100644 src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs index 24d3be8a2..c4b9635d7 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs @@ -23,10 +23,11 @@ #endregion +using System; using System.Net; using System.Net.NetworkInformation; +using System.Runtime.CompilerServices; using JetBrains.Annotations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore @@ -50,11 +51,11 @@ public static class NpgsqlNetworkExtensions /// /// True if the is less than the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is less than another (IPAddress Address, int Subnet). @@ -65,11 +66,11 @@ public static bool LessThan([CanBeNull] this DbFunctions _, IPAddress inet, IPAd /// /// True if the (IPAddress Address, int Subnet) is less than the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is less than another . @@ -80,11 +81,11 @@ public static bool LessThan([CanBeNull] this DbFunctions _, (IPAddress Address, /// /// True if the is less than the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is less than or equal to another . @@ -95,11 +96,11 @@ public static bool LessThan([CanBeNull] this DbFunctions _, PhysicalAddress maca /// /// True if the is less than or equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is less than or equal to another (IPAddress Address, int Subnet). @@ -110,11 +111,11 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, IPAddress ine /// /// True if the (IPAddress Address, int Subnet) is less than or equal to the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is less than or equal to another . @@ -125,11 +126,11 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad /// /// True if the is less than or equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is equal to another . @@ -140,11 +141,11 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddre /// /// True if the is equal to the other ; otherwise, false. /// - /// + /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool Equal([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is equal to another (IPAddress Address, int Subnet). @@ -155,11 +156,11 @@ public static bool Equal([CanBeNull] this DbFunctions _, IPAddress inet, IPAddre /// /// True if the (IPAddress Address, int Subnet) is equal to the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is equal to another . @@ -170,11 +171,11 @@ public static bool Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int /// /// True if the is equal to the other ; otherwise, false. /// - /// + /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool Equal([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than or equal to another . @@ -185,11 +186,11 @@ public static bool Equal([CanBeNull] this DbFunctions _, PhysicalAddress macaddr /// /// True if the is greater than or equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is greater than or equal to another (IPAddress Address, int Subnet). @@ -200,11 +201,11 @@ public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, IPAddress /// /// True if the (IPAddress Address, int Subnet) is greater than or equal to the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than or equal to another . @@ -215,11 +216,11 @@ public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress /// /// True if the is greater than or equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than another . @@ -230,11 +231,11 @@ public static bool GreaterThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAd /// /// True if the is greater than the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is greater than another (IPAddress Address, int Subnet). @@ -245,11 +246,11 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, IPAddress inet, I /// /// True if the (IPAddress Address, int Subnet) is greater than the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is greater than another . @@ -260,11 +261,11 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Addres /// /// True if the is greater than the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is not equal to another . @@ -275,11 +276,11 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, PhysicalAddress m /// /// True if the is not equal to the other ; otherwise, false. /// - /// + /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool NotEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is not equal to another (IPAddress Address, int Subnet). @@ -290,11 +291,11 @@ public static bool NotEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAd /// /// True if the IPAddress Address, int Subnet) is not equal to the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is not equal to another . @@ -305,11 +306,11 @@ public static bool NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, /// /// True if the is not equal to the other ; otherwise, false. /// - /// + /// /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. /// public static bool NotEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); #endregion @@ -324,11 +325,11 @@ public static bool NotEqual([CanBeNull] this DbFunctions _, PhysicalAddress maca /// /// True if the is contained within the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is contained within a network. @@ -339,11 +340,11 @@ public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, I /// /// True if the is contained within the network; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is contained within another (IPAddress Address, int Subnet). @@ -354,11 +355,11 @@ public static bool ContainedBy([CanBeNull] this DbFunctions _, IPAddress inet, ( /// /// True if the (IPAddress Address, int Subnet) is contained within the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is contained within or equal to another . @@ -369,11 +370,11 @@ public static bool ContainedBy([CanBeNull] this DbFunctions _, (IPAddress Addres /// /// True if the is contained within or equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an is contained within or equal to a network. @@ -384,11 +385,11 @@ public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress /// /// True if the is contained within or equal to the network; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) is contained within or equal to another (IPAddress Address, int Subnet). @@ -399,11 +400,11 @@ public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, IPAddress /// /// True if the (IPAddress Address, int Subnet) is contained within or equal to the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an contains another . @@ -414,11 +415,11 @@ public static bool ContainedByOrEqual([CanBeNull] this DbFunctions _, (IPAddress /// /// True if the contains the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether a network contains another . @@ -429,11 +430,11 @@ public static bool Contains([CanBeNull] this DbFunctions _, IPAddress inet, IPAd /// /// True if the network contains the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains another (IPAddress Address, int Subnet). @@ -444,11 +445,11 @@ public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, /// /// True if the (IPAddress Address, int Subnet) contains the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an contains or is equal to another . @@ -459,11 +460,11 @@ public static bool Contains([CanBeNull] this DbFunctions _, (IPAddress Address, /// /// True if the contains or is equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether a network contains or is equal to another . @@ -474,11 +475,11 @@ public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, IPAddress ine /// /// True if the network contains or is equal to the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is equal to another (IPAddress Address, int Subnet). @@ -489,11 +490,11 @@ public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad /// /// True if the (IPAddress Address, int Subnet) contains or is equal to the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an contains or is contained by another . @@ -504,11 +505,11 @@ public static bool ContainsOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad /// /// True if the contains or is contained by the other ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether a network contains or is contained by an . @@ -519,11 +520,11 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddre /// /// True if the network contains or is contained by the ; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an contains or is contained by a network. @@ -534,11 +535,11 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddr /// /// True if the contains or is contained by the network; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Determines whether an (IPAddress Address, int Subnet) contains or is contained by another (IPAddress Address, int Subnet). @@ -549,11 +550,11 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, IPAddre /// /// True if the (IPAddress Address, int Subnet) contains or is contained by the other (IPAddress Address, int Subnet); otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); #endregion @@ -567,11 +568,11 @@ public static bool ContainsOrContainedBy([CanBeNull] this DbFunctions _, (IPAddr /// /// The result of the bitwise NOT operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise NOT operation on an (IPAddress Address, int Subnet). @@ -581,11 +582,11 @@ public static IPAddress BitwiseNot([CanBeNull] this DbFunctions _, IPAddress ine /// /// The result of the bitwise NOT operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise NOT operation on an . @@ -595,11 +596,11 @@ public static (IPAddress Address, int Subnet) BitwiseNot([CanBeNull] this DbFunc /// /// The result of the bitwise NOT operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise AND of two instances. @@ -610,11 +611,11 @@ public static PhysicalAddress BitwiseNot([CanBeNull] this DbFunctions _, Physica /// /// The result of the bitwise AND operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise AND of two (IPAddress Address, int Subnet) instances. @@ -625,11 +626,11 @@ public static IPAddress BitwiseAnd([CanBeNull] this DbFunctions _, IPAddress ine /// /// The result of the bitwise AND operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise AND of two instances. @@ -640,11 +641,11 @@ public static (IPAddress Address, int Subnet) BitwiseAnd([CanBeNull] this DbFunc /// /// The result of the bitwise AND operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise OR of two instances. @@ -655,11 +656,11 @@ public static PhysicalAddress BitwiseAnd([CanBeNull] this DbFunctions _, Physica /// /// The result of the bitwise OR operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise OR of two (IPAddress Address, int Subnet) instances. @@ -670,11 +671,11 @@ public static IPAddress BitwiseOr([CanBeNull] this DbFunctions _, IPAddress inet /// /// The result of the bitwise OR operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Computes the bitwise OR of two instances. @@ -685,11 +686,11 @@ public static (IPAddress Address, int Subnet) BitwiseOr([CanBeNull] this DbFunct /// /// The result of the bitwise OR operation. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); #endregion @@ -704,11 +705,11 @@ public static PhysicalAddress BitwiseOr([CanBeNull] this DbFunctions _, Physical /// /// The augmented by the . /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Adds the to the (IPAddress Address, int Subnet). @@ -719,11 +720,11 @@ public static IPAddress Add([CanBeNull] this DbFunctions _, IPAddress inet, int /// /// The (IPAddress Address, int Subnet) augmented by the . /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Subtracts the from the . @@ -734,11 +735,11 @@ public static (IPAddress Address, int Subnet) Add([CanBeNull] this DbFunctions _ /// /// The augmented by the . /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Subtracts the from the (IPAddress Address, int Subnet). @@ -749,11 +750,11 @@ public static IPAddress Subtract([CanBeNull] this DbFunctions _, IPAddress inet, /// /// The (IPAddress Address, int Subnet) augmented by the . /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Subtracts one from another . @@ -764,11 +765,11 @@ public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFuncti /// /// The augmented by the . /// - /// + /// /// 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, IPAddress other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Subtracts one (IPAddress Address, int Subnet) from another (IPAddress Address, int Subnet). @@ -779,11 +780,11 @@ public static IPAddress Subtract([CanBeNull] this DbFunctions _, IPAddress inet, /// /// The (IPAddress Address, int Subnet) augmented by the . /// - /// + /// /// 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, (IPAddress Address, int Subnet) other) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); #endregion @@ -797,11 +798,11 @@ public static (IPAddress Address, int Subnet) Subtract([CanBeNull] this DbFuncti /// /// The abbreviated display format as text. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Returns the abbreviated display format as text. @@ -811,11 +812,11 @@ public static string Abbreviate([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The abbreviated display format as text. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Returns the broadcast address for a network. @@ -825,11 +826,11 @@ public static string Abbreviate([CanBeNull] this DbFunctions _, (IPAddress Addre /// /// The broadcast address for a network. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Returns the broadcast address for a network. @@ -839,11 +840,11 @@ public static IPAddress Broadcast([CanBeNull] this DbFunctions _, IPAddress inet /// /// The broadcast address for a network. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. @@ -853,11 +854,11 @@ public static IPAddress Broadcast([CanBeNull] this DbFunctions _, (IPAddress Add /// /// The family of an address; 4 for IPv4, 6 for IPv6. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the family of an address; 4 for IPv4, 6 for IPv6. @@ -867,11 +868,11 @@ public static int Family([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The family of an address; 4 for IPv4, 6 for IPv6. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the host (i.e. the IP address) as text. @@ -881,11 +882,11 @@ public static int Family([CanBeNull] this DbFunctions _, (IPAddress Address, int /// /// The host (i.e. the IP address) as text. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the host (i.e. the IP address) as text. @@ -895,11 +896,11 @@ public static string Host([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The host (i.e. the IP address) as text. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Constructs the host mask for the network. @@ -909,11 +910,11 @@ public static string Host([CanBeNull] this DbFunctions _, (IPAddress Address, in /// /// The constructed host mask. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Constructs the host mask for the network. @@ -923,11 +924,11 @@ public static IPAddress HostMask([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The constructed host mask. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the length of the subnet mask. @@ -937,11 +938,11 @@ public static IPAddress HostMask([CanBeNull] this DbFunctions _, (IPAddress Addr /// /// The length of the subnet mask. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the length of the subnet mask. @@ -951,11 +952,11 @@ public static int MaskLength([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The length of the subnet mask. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Constructs the subnet mask for the network. @@ -965,11 +966,11 @@ public static int MaskLength([CanBeNull] this DbFunctions _, (IPAddress Address, /// /// The subnet mask for the network. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Constructs the subnet mask for the network. @@ -979,11 +980,11 @@ public static IPAddress Netmask([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The subnet mask for the network. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the network part of the address. @@ -993,11 +994,11 @@ public static IPAddress Netmask([CanBeNull] this DbFunctions _, (IPAddress Addre /// /// The network part of the 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) Network([CanBeNull] this DbFunctions _, IPAddress inet) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the network part of the address. @@ -1007,11 +1008,11 @@ public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctio /// /// The network part of the 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) Network([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr) - => throw new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Sets the length of the subnet mask. @@ -1022,11 +1023,11 @@ public static (IPAddress Address, int Subnet) Network([CanBeNull] this DbFunctio /// /// The network with a subnet mask of the specified length. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Sets the length of the subnet mask. @@ -1037,11 +1038,11 @@ public static IPAddress SetMaskLength([CanBeNull] this DbFunctions _, IPAddress /// /// The network with a subnet mask of the specified length. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the IP address and subnet mask as text. @@ -1051,11 +1052,11 @@ public static (IPAddress Address, int Subnet) SetMaskLength([CanBeNull] this DbF /// /// The IP address and subnet mask as text. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Extracts the IP address and subnet mask as text. @@ -1065,11 +1066,11 @@ public static string Text([CanBeNull] this DbFunctions _, IPAddress inet) /// /// The IP address and subnet mask as text. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Tests if the addresses are in the same family. @@ -1080,11 +1081,11 @@ public static string Text([CanBeNull] this DbFunctions _, (IPAddress Address, in /// /// True if the addresses are in the same family; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Tests if the addresses are in the same family. @@ -1095,11 +1096,11 @@ public static bool SameFamily([CanBeNull] this DbFunctions _, IPAddress inet, IP /// /// True if the addresses are in the same family; otherwise, false. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Constructs the smallest network which includes both of the given networks. @@ -1110,11 +1111,11 @@ public static bool SameFamily([CanBeNull] this DbFunctions _, (IPAddress Address /// /// The smallest network which includes both of the given networks. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Constructs the smallest network which includes both of the given networks. @@ -1125,11 +1126,11 @@ public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions /// /// The smallest network which includes both of the given networks. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Sets the last 3 bytes of the MAC address to zero. For macaddr8, the last 5 bytes are set to zero. @@ -1139,11 +1140,11 @@ public static (IPAddress Address, int Subnet) Merge([CanBeNull] this DbFunctions /// /// The MAC address with the last 3 bytes set to zero. For macaddr8, the last 5 bytes are set to zero. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); /// /// Sets the 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 address. @@ -1153,11 +1154,26 @@ public static PhysicalAddress Truncate([CanBeNull] this DbFunctions _, PhysicalA /// /// The MAC address with the 7th bit set to one. /// - /// + /// /// 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 new ClientEvaluationNotSupportedException(); + => throw ClientEvaluationNotSupportedException(); + + #endregion + + #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 } diff --git a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs index 132f5eaf0..8f3821c90 100644 --- a/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs @@ -23,8 +23,7 @@ #endregion -using JetBrains.Annotations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities; +using System; using NpgsqlTypes; // ReSharper disable once CheckNamespace @@ -42,12 +41,9 @@ public static class NpgsqlRangeExtensions /// The value to locate in the range. /// The type of the elements of . /// - /// True if the range contains the specified value; otherwise, false. + /// true if the range contains the specified value; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool Contains(this NpgsqlRange range, T value) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range contains a specified range. @@ -56,12 +52,9 @@ public static class NpgsqlRangeExtensions /// The specified range to locate in the range. /// The type of the elements of . /// - /// True if the range contains the specified range; otherwise, false. + /// true if the range contains the specified range; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool Contains(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range is contained by a specified range. @@ -70,12 +63,9 @@ public static class NpgsqlRangeExtensions /// The range in which to locate the specified range. /// The type of the elements of . /// - /// True if the range contains the specified range; otherwise, false. + /// true if the range contains the specified range; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool ContainedBy(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => b.Contains(a); /// /// Determines whether a range overlaps another range. @@ -84,12 +74,9 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// True if the ranges overlap (share points in common); otherwise, false. + /// true if the ranges overlap (share points in common); otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool Overlaps(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range is strictly to the left of another range. @@ -98,12 +85,9 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// True if the first range is strictly to the left of the second; otherwise, false. + /// true if the first range is strictly to the left of the second; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool IsStrictlyLeftOf(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range is strictly to the right of another range. @@ -112,12 +96,9 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// True if the first range is strictly to the right of the second; otherwise, false. + /// true if the first range is strictly to the right of the second; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool IsStrictlyRightOf(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range does not extend to the left of another range. @@ -126,12 +107,9 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// True if the first range does not extend to the left of the second; otherwise, false. + /// true if the first range does not extend to the left of the second; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool DoesNotExtendLeftOf(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range does not extend to the right of another range. @@ -140,12 +118,9 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// True if the first range does not extend to the right of the second; otherwise, false. + /// true if the first range does not extend to the right of the second; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool DoesNotExtendRightOf(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Determines whether a range is adjacent to another range. @@ -154,12 +129,9 @@ public static class NpgsqlRangeExtensions /// The second range. /// The type of the elements of . /// - /// True if the ranges are adjacent; otherwise, false. + /// true if the ranges are adjacent; otherwise, false. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static bool IsAdjacentTo(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Returns the set union, which means unique elements that appear in either of two ranges. @@ -170,10 +142,7 @@ public static class NpgsqlRangeExtensions /// /// The unique elements that appear in either range. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static NpgsqlRange Union(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Returns the set intersection, which means elements that appear in each of two ranges. @@ -184,10 +153,7 @@ public static class NpgsqlRangeExtensions /// /// The elements that appear in both ranges. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static NpgsqlRange Intersect(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); /// /// Returns the set difference, which means the elements of one range that do not appear in a second range. @@ -198,9 +164,6 @@ public static class NpgsqlRangeExtensions /// /// The elements that appear in the first range, but not the second range. /// - /// - /// This 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 new ClientEvaluationNotSupportedException(); + public static NpgsqlRange Except(this NpgsqlRange a, NpgsqlRange b) where T : IComparable => throw new NotSupportedException(); } } diff --git a/src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs b/src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs deleted file mode 100644 index 8fce1fdbb..000000000 --- a/src/EFCore.PG/Utilities/ClientEvaluationNotSupportedException.cs +++ /dev/null @@ -1,48 +0,0 @@ -#region License - -// The PostgreSQL License -// -// Copyright (C) 2016 The Npgsql Development Team -// -// Permission to use, copy, modify, and distribute this software and its -// documentation for any purpose, without fee, and without a written -// agreement is hereby granted, provided that the above copyright notice -// and this paragraph and the following two paragraphs appear in all copies. -// -// IN NO EVENT SHALL THE NPGSQL DEVELOPMENT TEAM BE LIABLE TO ANY PARTY -// FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, -// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -// DOCUMENTATION, EVEN IF THE NPGSQL DEVELOPMENT TEAM HAS BEEN ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -// -// THE NPGSQL DEVELOPMENT TEAM SPECIFICALLY DISCLAIMS ANY WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS -// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - -#endregion - -using System; -using System.Runtime.CompilerServices; - -namespace Npgsql.EntityFrameworkCore.PostgreSQL.Utilities -{ - /// - /// The exception that is thrown when a method intended for SQL translation is evaluated by the client. - /// - public class ClientEvaluationNotSupportedException : NotSupportedException - { - readonly string _callerMemberName; - - /// - public override string Message - => $"{_callerMemberName} is only intended for use via SQL translation as part of an EF Core LINQ query."; - - /// - public ClientEvaluationNotSupportedException([CallerMemberName] string method = default) - { - _callerMemberName = method; - } - } -} From d4d851fd2e1293217340d78868cb7956fd048429 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Sun, 22 Jul 2018 13:58:35 -0400 Subject: [PATCH 13/13] Remove Equal/NotEqual in favor of built-ins --- .../Extensions/NpgsqlNetworkExtensions.cs | 90 ---------- .../Internal/NpgsqlNetworkTranslator.cs | 6 - .../Query/NetworkQueryNpgsqlTest.cs | 163 +----------------- 3 files changed, 3 insertions(+), 256 deletions(-) diff --git a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs index c4b9635d7..4f28c218a 100644 --- a/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs +++ b/src/EFCore.PG/Extensions/NpgsqlNetworkExtensions.cs @@ -132,51 +132,6 @@ public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, (IPAddress Ad public static bool LessThanOrEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw ClientEvaluationNotSupportedException(); - /// - /// Determines whether an is equal to another . - /// - /// The instance. - /// The left-hand inet. - /// The right-hand inet. - /// - /// True if the is equal to the other ; otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool Equal([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an (IPAddress Address, int Subnet) is equal to another (IPAddress Address, int Subnet). - /// - /// The instance. - /// The left-hand cidr. - /// The right-hand cidr. - /// - /// True if the (IPAddress Address, int Subnet) is equal to the other (IPAddress Address, int Subnet); otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool Equal([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an is equal to another . - /// - /// The instance. - /// The left-hand macaddr. - /// The right-hand macaddr. - /// - /// True if the is equal to the other ; otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool Equal([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); - /// /// Determines whether an is greater than or equal to another . /// @@ -267,51 +222,6 @@ public static bool GreaterThan([CanBeNull] this DbFunctions _, (IPAddress Addres public static bool GreaterThan([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) => throw ClientEvaluationNotSupportedException(); - /// - /// Determines whether an is not equal to another . - /// - /// The instance. - /// The left-hand inet. - /// The right-hand inet. - /// - /// True if the is not equal to the other ; otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool NotEqual([CanBeNull] this DbFunctions _, IPAddress inet, IPAddress other) - => throw ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an (IPAddress Address, int Subnet) is not equal to another (IPAddress Address, int Subnet). - /// - /// The instance. - /// The left-hand cidr. - /// The right-hand cidr. - /// - /// True if the IPAddress Address, int Subnet) is not equal to the other (IPAddress Address, int Subnet); otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool NotEqual([CanBeNull] this DbFunctions _, (IPAddress Address, int Subnet) cidr, (IPAddress Address, int Subnet) other) - => throw ClientEvaluationNotSupportedException(); - - /// - /// Determines whether an is not equal to another . - /// - /// The instance. - /// The left-hand macaddr. - /// The right-hand macaddr. - /// - /// True if the is not equal to the other ; otherwise, false. - /// - /// - /// This method is only intended for use via SQL translation as part of an EF Core LINQ query. - /// - public static bool NotEqual([CanBeNull] this DbFunctions _, PhysicalAddress macaddr, PhysicalAddress other) - => throw ClientEvaluationNotSupportedException(); - #endregion #region ContainmentOperators diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs index fbb82b400..a9fd81a0e 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlNetworkTranslator.cs @@ -57,18 +57,12 @@ public Expression Translate(MethodCallExpression expression) case nameof(NpgsqlNetworkExtensions.LessThanOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<=", typeof(bool)); - case nameof(NpgsqlNetworkExtensions.Equal): - return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "=", typeof(bool)); - case nameof(NpgsqlNetworkExtensions.GreaterThanOrEqual): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">=", typeof(bool)); case nameof(NpgsqlNetworkExtensions.GreaterThan): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], ">", typeof(bool)); - case nameof(NpgsqlNetworkExtensions.NotEqual): - return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<>", typeof(bool)); - case nameof(NpgsqlNetworkExtensions.ContainedBy): return new CustomBinaryExpression(expression.Arguments[1], expression.Arguments[2], "<<", typeof(bool)); diff --git a/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs index d6e258feb..51468ca9c 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NetworkQueryNpgsqlTest.cs @@ -215,80 +215,6 @@ public void PhysicalAddress_macaddr8_LessThanOrEqual_macaddr8() } } - /// - /// Tests translation for . - /// - [Fact] - public void IPAddress_inet_Equal_inet() - { - using (NetContext context = Fixture.CreateContext()) - { - IPAddress inet = IPAddress.Any; - - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.Equal(x.Inet, inet)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Inet\" = @__inet_1) = TRUE"); - } - } - - /// - /// Tests translation for . - /// - [Fact] - public void ValueTuple_cidr_Equal_cidr() - { - using (NetContext context = Fixture.CreateContext()) - { - (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); - - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.Equal(x.Cidr, cidr)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Cidr\" = @__cidr_1) = TRUE"); - } - } - - /// - /// Tests translation for . - /// - [Fact] - public void PhysicalAddress_macaddr_Equal_macaddr() - { - using (NetContext context = Fixture.CreateContext()) - { - PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); - - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.Equal(x.Macaddr, macaddr)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Macaddr\" = @__macaddr_1) = TRUE"); - } - } - - /// - /// Tests translation for . - /// - [Fact] - public void PhysicalAddress_macaddr8_Equal_macaddr8() - { - using (NetContext context = Fixture.CreateContext()) - { - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.Equal(x.Macaddr8, x.Macaddr8)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Macaddr8\" = x.\"Macaddr8\") = TRUE"); - } - } - /// /// Tests translation for . /// @@ -437,80 +363,6 @@ public void PhysicalAddress_macaddr8_GreaterThan_macaddr8() } } - /// - /// Tests translation for . - /// - [Fact] - public void IPAddress_inet_NotEqual_inet() - { - using (NetContext context = Fixture.CreateContext()) - { - IPAddress inet = IPAddress.Any; - - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.NotEqual(x.Inet, inet)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Inet\" <> @__inet_1) = TRUE"); - } - } - - /// - /// Tests translation for . - /// - [Fact] - public void ValueTuple_cidr_NotEqual_cidr() - { - using (NetContext context = Fixture.CreateContext()) - { - (IPAddress Address, int Subnet) cidr = (IPAddress.Any, default); - - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.NotEqual(x.Cidr, cidr)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Cidr\" <> @__cidr_1) = TRUE"); - } - } - - /// - /// Tests translation for . - /// - [Fact] - public void PhysicalAddress_macaddr_NotEqual_macaddr() - { - using (NetContext context = Fixture.CreateContext()) - { - PhysicalAddress macaddr = new PhysicalAddress(new byte[6]); - - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.NotEqual(x.Macaddr, macaddr)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Macaddr\" <> @__macaddr_1) = TRUE"); - } - } - - /// - /// Tests translation for . - /// - [Fact] - public void PhysicalAddress_macaddr8_NotEqual_macaddr8() - { - using (NetContext context = Fixture.CreateContext()) - { - NetTestEntity[] _ = - context.NetTestEntities - .Where(x => EF.Functions.NotEqual(x.Macaddr8, x.Macaddr8)) - .ToArray(); - - AssertContainsSql("WHERE (x.\"Macaddr8\" <> x.\"Macaddr8\") = TRUE"); - } - } - #endregion #region ContainmentOperatorTests @@ -1691,16 +1543,10 @@ public NetworkAddressQueryNpgsqlFixture() /// /// A for testing. /// - public NetContext CreateContext() - { - return new NetContext(_options); - } + public NetContext CreateContext() => new NetContext(_options); /// - public void Dispose() - { - _testStore.Dispose(); - } + public void Dispose() => _testStore.Dispose(); } /// @@ -1763,10 +1609,7 @@ public NetContext(DbContextOptions options) : base(options) { } /// Asserts that the SQL fragment appears in the logs. /// /// The SQL statement or fragment to search for in the logs. - public void AssertContainsSql(string sql) - { - Assert.Contains(sql, Fixture.TestSqlLoggerFactory.Sql); - } + public void AssertContainsSql(string sql) => Assert.Contains(sql, Fixture.TestSqlLoggerFactory.Sql); #endregion }