提交 6655bbbd 编写于 作者: A Austin Drenski 提交者: Shay Rojansky

Fix network type mappings

- Fix macaddr8 mapping
- Fix cidr mapping to (IPAddress, int)
- Split out from #407
上级 651839dd
using System; #region License
using System.Collections.Generic;
// 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;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Text;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NpgsqlTypes; using NpgsqlTypes;
...@@ -28,7 +50,7 @@ protected override string GenerateNonNullSqlLiteral(object value) ...@@ -28,7 +50,7 @@ protected override string GenerateNonNullSqlLiteral(object value)
public class NpgsqlMacaddr8TypeMapping : NpgsqlTypeMapping 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) protected NpgsqlMacaddr8TypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType)
: base(parameters, npgsqlDbType) {} : base(parameters, npgsqlDbType) {}
...@@ -75,8 +97,8 @@ public override CoreTypeMapping Clone(ValueConverter converter) ...@@ -75,8 +97,8 @@ public override CoreTypeMapping Clone(ValueConverter converter)
protected override string GenerateNonNullSqlLiteral(object value) protected override string GenerateNonNullSqlLiteral(object value)
{ {
var cidr = ((IPAddress, int))value; var cidr = ((IPAddress Address, int Subnet))value;
return $"CIDR '{cidr.Item1}/{cidr.Item2}'"; return $"CIDR '{cidr.Address}/{cidr.Subnet}'";
} }
} }
} }
#region License #region License
// The PostgreSQL License // The PostgreSQL License
// //
// Copyright (C) 2016 The Npgsql Development Team // Copyright (C) 2016 The Npgsql Development Team
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
// AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS // AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
// ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS // ON AN "AS IS" BASIS, AND THE NPGSQL DEVELOPMENT TEAM HAS NO OBLIGATIONS
// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. // TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#endregion #endregion
using System; using System;
...@@ -30,11 +32,9 @@ ...@@ -30,11 +32,9 @@
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Reflection;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
using Npgsql.TypeHandlers; using Npgsql.TypeHandlers;
...@@ -199,40 +199,41 @@ public class NpgsqlTypeMappingSource : RelationalTypeMappingSource ...@@ -199,40 +199,41 @@ public class NpgsqlTypeMappingSource : RelationalTypeMappingSource
var clrTypeMappings = new Dictionary<Type, RelationalTypeMapping> var clrTypeMappings = new Dictionary<Type, RelationalTypeMapping>
{ {
{ typeof(bool), _bool }, { typeof(bool), _bool },
{ typeof(byte[]), _bytea }, { typeof(byte[]), _bytea },
{ typeof(float), _float4 }, { typeof(float), _float4 },
{ typeof(double), _float8 }, { typeof(double), _float8 },
{ typeof(decimal), _numeric }, { typeof(decimal), _numeric },
{ typeof(Guid), _uuid }, { typeof(Guid), _uuid },
{ typeof(byte), _int2Byte }, { typeof(byte), _int2Byte },
{ typeof(short), _int2 }, { typeof(short), _int2 },
{ typeof(int), _int4 }, { typeof(int), _int4 },
{ typeof(long), _int8 }, { typeof(long), _int8 },
{ typeof(string), _text }, { typeof(string), _text },
{ typeof(char), _singleChar }, { typeof(char), _singleChar },
{ typeof(DateTime), _timestamp }, { typeof(DateTime), _timestamp },
{ typeof(TimeSpan), _interval }, { typeof(TimeSpan), _interval },
{ typeof(DateTimeOffset), _timestamptzDto }, { typeof(DateTimeOffset), _timestamptzDto },
{ typeof(PhysicalAddress), _macaddr }, { typeof(PhysicalAddress), _macaddr },
{ typeof(IPAddress), _inet }, { typeof(IPAddress), _inet },
{ typeof(BitArray), _varbit }, { typeof((IPAddress, int)), _cidr },
{ typeof(Dictionary<string, string>), _hstore }, { typeof(BitArray), _varbit },
{ typeof(NpgsqlPoint), _point }, { typeof(Dictionary<string, string>), _hstore },
{ typeof(NpgsqlBox), _box }, { typeof(NpgsqlPoint), _point },
{ typeof(NpgsqlLine), _line }, { typeof(NpgsqlBox), _box },
{ typeof(NpgsqlLSeg), _lseg }, { typeof(NpgsqlLine), _line },
{ typeof(NpgsqlPath), _path }, { typeof(NpgsqlLSeg), _lseg },
{ typeof(NpgsqlPolygon), _polygon }, { typeof(NpgsqlPath), _path },
{ typeof(NpgsqlCircle), _circle }, { typeof(NpgsqlPolygon), _polygon },
{ typeof(NpgsqlCircle), _circle },
{ typeof(NpgsqlRange<int>), _int4range },
{ typeof(NpgsqlRange<long>), _int8range }, { typeof(NpgsqlRange<int>), _int4range },
{ typeof(NpgsqlRange<decimal>), _numrange }, { typeof(NpgsqlRange<long>), _int8range },
{ typeof(NpgsqlRange<DateTime>), _tsrange }, { typeof(NpgsqlRange<decimal>), _numrange },
{ typeof(NpgsqlRange<DateTime>), _tsrange },
{ typeof(NpgsqlTsQuery), _tsquery },
{ typeof(NpgsqlTsVector), _tsvector }, { typeof(NpgsqlTsQuery), _tsquery },
{ typeof(NpgsqlTsVector), _tsvector },
{ typeof(NpgsqlTsRankingNormalization), _rankingNormalization } { typeof(NpgsqlTsRankingNormalization), _rankingNormalization }
}; };
...@@ -286,10 +287,7 @@ protected override RelationalTypeMapping FindMapping(in RelationalTypeMappingInf ...@@ -286,10 +287,7 @@ protected override RelationalTypeMapping FindMapping(in RelationalTypeMappingInf
// We couldn't find a base (simple) type mapping. Try to find an array. // We couldn't find a base (simple) type mapping. Try to find an array.
var arrayMapping = FindArrayMapping(mappingInfo); var arrayMapping = FindArrayMapping(mappingInfo);
if (arrayMapping != null) return arrayMapping ?? null;
return arrayMapping;
return null;
} }
protected virtual RelationalTypeMapping FindBaseTypeMapping(in RelationalTypeMappingInfo mappingInfo) protected virtual RelationalTypeMapping FindBaseTypeMapping(in RelationalTypeMappingInfo mappingInfo)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册