Efcore: Value converter for Uri

Created on 27 May 2019  路  5Comments  路  Source: dotnet/efcore

This is a feature request. I would like to propose the addition of a value converter for the Uri type.

closed-fixed customer-reported type-enhancement

Most helpful comment

I'm liking the look of this. Taking a stab at raising a PR for it.

All 5 comments

I'm liking the look of this. Taking a stab at raising a PR for it.

Silly list of value converter candidates for possible consideration or more likely outright rejection.

A candidate could have a public constructor taking a single primitive type, or a have a static Parse method taking a single primitive type.

With your own value converter:

var uriConverter = new ValueConverter<Uri, string>(v => v.ToString(), v => new Uri(v));

Or with backing fields for those who want.

public class Server
{
    private string _iPAddress;

    public IPAddress IPAddress
    {
        get { return IPAddress.Parse(_iPAddress); }
        set { _iPAddress = value.ToString(); }
    }
}

The IPAddress is now in EF Core thanks to @ralmsdeveloper with pull request #20679.

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew#ipaddress-mapping

PhysicalAddress is now in EF Core thanks to @ralmsdeveloper.

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew#physicaladdress-mapping

Somle more possible candidates:

  • Half
  • JsonValue
  • JsonDocument
  • MediaTypeHeaderValue
  • TimeSpan
Was this page helpful?
0 / 5 - 0 ratings