How to map string to Uri type using Entity Framework?

My database contains a column of type string that represents a URL. I am now wondering how it can map this string to a Uri object using Entity Framework.

Any ideas?

+3
source share
1 answer

Use a partial class, with a custom property:

    public partial class MyClass
    {
        public Uri MyUri
        {
            get
                { return new Uri(StringUriPropertyFromDB); }
        }
    }

You can make the string property private in the EF designer if you want. Note that you cannot use custom properties like this in LINQ for objects.

+2
source