diff --git a/src/EFCore/Storage/ValueConversion/IPAddressToStringConverter.cs b/src/EFCore/Storage/ValueConversion/IPAddressToStringConverter.cs index a1a905d1263..f9aee600334 100644 --- a/src/EFCore/Storage/ValueConversion/IPAddressToStringConverter.cs +++ b/src/EFCore/Storage/ValueConversion/IPAddressToStringConverter.cs @@ -13,6 +13,10 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion /// public class IPAddressToStringConverter : ValueConverter { + // IPv4-mapped IPv6 addresses can go up to 45 bytes, e.g. 0000:0000:0000:0000:0000:ffff:192.168.1.1 + private static readonly ConverterMappingHints _defaultHints + = new ConverterMappingHints(size: 45); + /// /// Creates a new instance of this converter. /// @@ -24,7 +28,7 @@ public IPAddressToStringConverter([CanBeNull] ConverterMappingHints mappingHints : base( ToString(), ToIPAddress(), - mappingHints) + _defaultHints.With(mappingHints)) { } @@ -32,7 +36,10 @@ public IPAddressToStringConverter([CanBeNull] ConverterMappingHints mappingHints /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(IPAddress), typeof(string), i => new IPAddressToStringConverter(i.MappingHints)); + = new ValueConverterInfo( + typeof(IPAddress), + typeof(string), i => new IPAddressToStringConverter(i.MappingHints), + _defaultHints); private static new Expression> ToString() => v => v == null ? default : v.ToString();