Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map a string to Uri type using the Entity Framework?

My database contains a column of type string, that represents a URL. I'm now wondering how its possible to map this string to a Uri object using the Entity Framework.

Any ideas?

like image 777
Georg Wächter Avatar asked Mar 27 '26 21:03

Georg Wächter


1 Answers

Use a partial class, w/ 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 you can't use custom properties like this in LINQ to entities, though.

like image 194
Craig Stuntz Avatar answered Apr 02 '26 15:04

Craig Stuntz