Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions src/EFCore.PG/Storage/Internal/Mapping/NpgsqlNetworkTypeMappings.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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}'";
}
}
}
78 changes: 38 additions & 40 deletions src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#region License

// The PostgreSQL License
//
// Copyright (C) 2016 The Npgsql Development Team
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -199,40 +199,41 @@ public NpgsqlTypeMappingSource([NotNull] TypeMappingSourceDependencies dependenc

var clrTypeMappings = new Dictionary<Type, RelationalTypeMapping>
{
{ 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<string, string>), _hstore },
{ typeof(NpgsqlPoint), _point },
{ typeof(NpgsqlBox), _box },
{ typeof(NpgsqlLine), _line },
{ typeof(NpgsqlLSeg), _lseg },
{ typeof(NpgsqlPath), _path },
{ typeof(NpgsqlPolygon), _polygon },
{ typeof(NpgsqlCircle), _circle },

{ typeof(NpgsqlRange<int>), _int4range },
{ typeof(NpgsqlRange<long>), _int8range },
{ typeof(NpgsqlRange<decimal>), _numrange },
{ typeof(NpgsqlRange<DateTime>), _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<string, string>), _hstore },
{ typeof(NpgsqlPoint), _point },
{ typeof(NpgsqlBox), _box },
{ typeof(NpgsqlLine), _line },
{ typeof(NpgsqlLSeg), _lseg },
{ typeof(NpgsqlPath), _path },
{ typeof(NpgsqlPolygon), _polygon },
{ typeof(NpgsqlCircle), _circle },

{ typeof(NpgsqlRange<int>), _int4range },
{ typeof(NpgsqlRange<long>), _int8range },
{ typeof(NpgsqlRange<decimal>), _numrange },
{ typeof(NpgsqlRange<DateTime>), _tsrange },

{ typeof(NpgsqlTsQuery), _tsquery },
{ typeof(NpgsqlTsVector), _tsvector },
{ typeof(NpgsqlTsRankingNormalization), _rankingNormalization }
};

Expand Down Expand Up @@ -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)
Expand Down