views:

305

answers:

2

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?

+1  A: 

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.

Craig Stuntz
A: 

Thanks for the answer. Ok, i thought there might be a better way ...

Its a pity that i can't use this property using LinQ to Entities, thats exactly what i had planned to do :-) ... but i see the problem. To make this work one would need to mix LibQ to Entities and LinQ to Objects.

Georg Wächter