开发者

NHibernate persist System.Uri

开发者 https://www.devze.com 2022-12-13 17:19 出处:网络
I have a domain object that has a couple of Uri properties that need to be persisted to a Urls table that has sev开发者_JS百科eral parts of the Uri from which the properties will need to be reassemble

I have a domain object that has a couple of Uri properties that need to be persisted to a Urls table that has sev开发者_JS百科eral parts of the Uri from which the properties will need to be reassembled after retrieval. I can store the properties well enough, but how do I tell NHibernate how to recreate the Uri property? You can't set most of the Uri object's properties directly. Rather, the url must be assembled and passed to a Uri constructor.


Personally I do not find the Uri type to be super useful but there are 2 options that I can think of:

  1. Create a new user type by implementing IUserType (see http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx - search for the Uri implementation it's about half way down)
  2. Create a protected string property that is mapped in NHibernate and wrap a public Uri around it.

UPDATE

I haven't played with this but given that you are looking to map the properties of the Uri I think you want to look at implementing the ICompositeUserType instead of IUserType. See this post for an idea (not based on Uri but could be good for pointers) http://www.lostechies.com/blogs/rhouston/archive/2008/03/23/mapping-timestamp-data-using-nhibernate-s-icompositeusertype.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消