Skip to content

Commit

Permalink
Retargeting cidr from NpgsqlInet to (IPAddress Address, int Subnet).
Browse files Browse the repository at this point in the history
- 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?
  • Loading branch information
austindrenski committed May 26, 2018
1 parent 169c2c5 commit b02bff3
Show file tree
Hide file tree
Showing 8 changed files with 741 additions and 258 deletions.
485 changes: 485 additions & 0 deletions src/EFCore.PG/Extensions/NpgsqlNetworkAddressExtensions.cs

Large diffs are not rendered by default.

70 changes: 36 additions & 34 deletions src/EFCore.PG/Extensions/NpgsqlRangeExtensions.cs
Expand Up @@ -23,7 +23,8 @@

#endregion

using System;
using JetBrains.Annotations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities;
using NpgsqlTypes;

// ReSharper disable once CheckNamespace
Expand All @@ -32,6 +33,7 @@ namespace Microsoft.EntityFrameworkCore
/// <summary>
/// Provides extension methods for <see cref="NpgsqlRange{T}"/> supporting PostgreSQL translation.
/// </summary>
[PublicAPI]
public static class NpgsqlRangeExtensions
{
/// <summary>
Expand All @@ -41,12 +43,12 @@ public static class NpgsqlRangeExtensions
/// <param name="value">The value to locate in the range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="range"/>.</typeparam>
/// <returns>
/// <value>true</value> if the range contains the specified value; otherwise, <value>false</value>.
/// True if the range contains the specified value; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool Contains<T>(this NpgsqlRange<T> range, T value) where T : IComparable<T> => throw new NotSupportedException();
public static bool Contains<T>(this NpgsqlRange<T> range, T value) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range contains a specified range.
Expand All @@ -55,12 +57,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The specified range to locate in the range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the range contains the specified range; otherwise, <value>false</value>.
/// True if the range contains the specified range; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool Contains<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool Contains<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range is contained by a specified range.
Expand All @@ -69,12 +71,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The range in which to locate the specified range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the range contains the specified range; otherwise, <value>false</value>.
/// True if the range contains the specified range; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool ContainedBy<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => b.Contains(a);
public static bool ContainedBy<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range overlaps another range.
Expand All @@ -83,12 +85,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The second range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the ranges overlap (share points in common); otherwise, <value>false</value>.
/// True if the ranges overlap (share points in common); otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool Overlaps<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool Overlaps<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range is strictly to the left of another range.
Expand All @@ -97,12 +99,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The second range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the first range is strictly to the left of the second; otherwise, <value>false</value>.
/// True if the first range is strictly to the left of the second; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool IsStrictlyLeftOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool IsStrictlyLeftOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range is strictly to the right of another range.
Expand All @@ -111,12 +113,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The second range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the first range is strictly to the right of the second; otherwise, <value>false</value>.
/// True if the first range is strictly to the right of the second; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool IsStrictlyRightOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool IsStrictlyRightOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range does not extend to the left of another range.
Expand All @@ -125,12 +127,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The second range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the first range does not extend to the left of the second; otherwise, <value>false</value>.
/// True if the first range does not extend to the left of the second; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool DoesNotExtendLeftOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool DoesNotExtendLeftOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range does not extend to the right of another range.
Expand All @@ -139,12 +141,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The second range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the first range does not extend to the right of the second; otherwise, <value>false</value>.
/// True if the first range does not extend to the right of the second; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool DoesNotExtendRightOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool DoesNotExtendRightOf<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Determines whether a range is adjacent to another range.
Expand All @@ -153,12 +155,12 @@ public static class NpgsqlRangeExtensions
/// <param name="b">The second range.</param>
/// <typeparam name="T">The type of the elements of <paramref name="a"/>.</typeparam>
/// <returns>
/// <value>true</value> if the ranges are adjacent; otherwise, <value>false</value>.
/// True if the ranges are adjacent; otherwise, false.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static bool IsAdjacentTo<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static bool IsAdjacentTo<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Returns the set union, which means unique elements that appear in either of two ranges.
Expand All @@ -169,10 +171,10 @@ public static class NpgsqlRangeExtensions
/// <returns>
/// The unique elements that appear in either range.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static NpgsqlRange<T> Union<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static NpgsqlRange<T> Union<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Returns the set intersection, which means elements that appear in each of two ranges.
Expand All @@ -183,10 +185,10 @@ public static class NpgsqlRangeExtensions
/// <returns>
/// The elements that appear in both ranges.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static NpgsqlRange<T> Intersect<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static NpgsqlRange<T> Intersect<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();

/// <summary>
/// Returns the set difference, which means the elements of one range that do not appear in a second range.
Expand All @@ -197,9 +199,9 @@ public static class NpgsqlRangeExtensions
/// <returns>
/// The elements that appear in the first range, but not the second range.
/// </returns>
/// <exception cref="NotSupportedException">
/// <exception cref="ClientEvaluationNotSupportedException">
/// This method is only intended for use via SQL translation as part of an EF Core LINQ query.
/// </exception>
public static NpgsqlRange<T> Except<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) where T : IComparable<T> => throw new NotSupportedException();
public static NpgsqlRange<T> Except<T>(this NpgsqlRange<T> a, NpgsqlRange<T> b) => throw new ClientEvaluationNotSupportedException();
}
}
95 changes: 0 additions & 95 deletions src/EFCore.PG/NpgsqlNetworkAddressExtensions.cs

This file was deleted.

0 comments on commit b02bff3

Please sign in to comment.