[英]How to map a string to Uri type using the Entity Framework?
My database contains a column of type string, that represents a URL. 我的数据库包含一个string类型的列,表示一个URL。 I'm now wondering how its possible to map this string to a Uri object using the Entity Framework.
我现在想知道如何使用Entity Framework将此字符串映射到Uri对象。
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. 如果需要,可以在EF设计器中将字符串属性设为私有。 Note you can't use custom properties like this in LINQ to entities, though.
请注意,不能在LINQ实体中使用这样的自定义属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.