简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM