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?

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.


Need Your Help

why does this work fine the first time around but not the 2nd time around?

c# asp.net-mvc asp.net-mvc-3 static quartz-scheduler

I am using a scheduler that will send out reminders through a library called actionMailer. I however need the httpcontext to work as well actionMailer uses mvc.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.