diff --git a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs index 7ea53b6a9..cfdc8ff5b 100644 --- a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs +++ b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs @@ -1,8 +1,30 @@ -using System; -using System.Collections.Generic; +#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 System.Net.NetworkInformation; -using System.Text; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using NpgsqlTypes; @@ -11,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); @@ -28,10 +50,10 @@ protected override string GenerateNonNullSqlLiteral(object value) public class NpgsqlMacaddr8TypeMapping : NpgsqlTypeMapping { - public NpgsqlMacaddr8TypeMapping() : base("macaddr8", typeof(PhysicalAddress), NpgsqlDbType.MacAddr) {} + 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); @@ -45,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); @@ -62,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); @@ -75,8 +97,8 @@ public override CoreTypeMapping Clone(ValueConverter converter) protected override string GenerateNonNullSqlLiteral(object value) { - var cidr = ((IPAddress, int))value; - return $"CIDR '{cidr.Item1}/{cidr.Item2}'"; + var cidr = ((IPAddress Address, int Subnet))value; + return $"CIDR '{cidr.Address}/{cidr.Subnet}'"; } } } diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs index 5f3cd01a5..3a41b1895 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs @@ -1,4 +1,5 @@ #region License + // The PostgreSQL License // // Copyright (C) 2016 The Npgsql Development Team @@ -19,6 +20,7 @@ // 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; @@ -30,11 +32,9 @@ using System.Linq; using System.Net; using System.Net.NetworkInformation; -using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; -using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; using Npgsql.TypeHandlers; @@ -199,40 +199,41 @@ public NpgsqlTypeMappingSource([NotNull] TypeMappingSourceDependencies dependenc var clrTypeMappings = new Dictionary { - { typeof(bool), _bool }, - { typeof(byte[]), _bytea }, - { typeof(float), _float4 }, - { typeof(double), _float8 }, - { typeof(decimal), _numeric }, - { typeof(Guid), _uuid }, - { typeof(byte), _int2Byte }, - { typeof(short), _int2 }, - { typeof(int), _int4 }, - { typeof(long), _int8 }, - { typeof(string), _text }, - { typeof(char), _singleChar }, - { typeof(DateTime), _timestamp }, - { typeof(TimeSpan), _interval }, - { typeof(DateTimeOffset), _timestamptzDto }, - { typeof(PhysicalAddress), _macaddr }, - { typeof(IPAddress), _inet }, - { typeof(BitArray), _varbit }, - { typeof(Dictionary), _hstore }, - { typeof(NpgsqlPoint), _point }, - { typeof(NpgsqlBox), _box }, - { typeof(NpgsqlLine), _line }, - { typeof(NpgsqlLSeg), _lseg }, - { typeof(NpgsqlPath), _path }, - { typeof(NpgsqlPolygon), _polygon }, - { typeof(NpgsqlCircle), _circle }, - - { typeof(NpgsqlRange), _int4range }, - { typeof(NpgsqlRange), _int8range }, - { typeof(NpgsqlRange), _numrange }, - { typeof(NpgsqlRange), _tsrange }, - - { typeof(NpgsqlTsQuery), _tsquery }, - { typeof(NpgsqlTsVector), _tsvector }, + { typeof(bool), _bool }, + { typeof(byte[]), _bytea }, + { typeof(float), _float4 }, + { typeof(double), _float8 }, + { typeof(decimal), _numeric }, + { typeof(Guid), _uuid }, + { typeof(byte), _int2Byte }, + { typeof(short), _int2 }, + { typeof(int), _int4 }, + { typeof(long), _int8 }, + { typeof(string), _text }, + { typeof(char), _singleChar }, + { typeof(DateTime), _timestamp }, + { typeof(TimeSpan), _interval }, + { typeof(DateTimeOffset), _timestamptzDto }, + { typeof(PhysicalAddress), _macaddr }, + { typeof(IPAddress), _inet }, + { typeof((IPAddress, int)), _cidr }, + { typeof(BitArray), _varbit }, + { typeof(Dictionary), _hstore }, + { typeof(NpgsqlPoint), _point }, + { typeof(NpgsqlBox), _box }, + { typeof(NpgsqlLine), _line }, + { typeof(NpgsqlLSeg), _lseg }, + { typeof(NpgsqlPath), _path }, + { typeof(NpgsqlPolygon), _polygon }, + { typeof(NpgsqlCircle), _circle }, + + { typeof(NpgsqlRange), _int4range }, + { typeof(NpgsqlRange), _int8range }, + { typeof(NpgsqlRange), _numrange }, + { typeof(NpgsqlRange), _tsrange }, + + { typeof(NpgsqlTsQuery), _tsquery }, + { typeof(NpgsqlTsVector), _tsvector }, { typeof(NpgsqlTsRankingNormalization), _rankingNormalization } }; @@ -286,10 +287,7 @@ protected override RelationalTypeMapping FindMapping(in RelationalTypeMappingInf // We couldn't find a base (simple) type mapping. Try to find an array. var arrayMapping = FindArrayMapping(mappingInfo); - if (arrayMapping != null) - return arrayMapping; - - return null; + return arrayMapping ?? null; } protected virtual RelationalTypeMapping FindBaseTypeMapping(in RelationalTypeMappingInfo mappingInfo)