截取Fluent NHibernate中的属性设置

时间:2009-11-04 18:18:39

标签: c# fluent-nhibernate orm

我是Fluent NHibernate的新手,我觉得应该是一个简单的问题。问题是我似乎无法在任何地方找到简单的答案。

我有一个nvarchar(SQL Server)的数据库列。它应映射到System.Uri的模型属性。问题是string不会隐式转换为Uri。有没有办法“拦截”属性的设置以使用自定义逻辑?

Map(x => x.WebAddress); // WebAddress in the DB is nvarchar, and it's a System.Uri in the model

// would like to find something like what I have below
Map(x => x.WebAddress).Intercept<string, Uri>(y => new Uri(y));

我错过了什么?

2 个答案:

答案 0 :(得分:1)

你应该使用IUserType,这是一个NHibernate功能而不是Fluent NHibernate。然后,您可以在您的财产上使用CustomType<YourUserType>()

谷歌搜索揭示了许多实现IUserType界面的不同示例,例如http://www.martinwilley.com/net/code/nhibernate/usertype.html

答案 1 :(得分:0)

我希望我能得到赞誉,但我相信这个例子将完全符合您的希望。 http://swik.net/tag4sree/Hibernate+-+Objects/Implementing+custom+types+in+nHibernate/b3s2p

相关问题