开发者

Intercepting property setting in Fluent NHibernate

I'm new to Fluent NHibernate, and have what I think should be a simple question. The problem is that I can't seem to find a simple answer anywhere.

I have a database column that is an nvarchar (SQL Server). It should map to a model property that is a System.Uri. The problem is that string doesn't implicitly convert to Uri. Is there a way to "intercept" the setting of the property to use custom logic?

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

// would like to find something lik开发者_如何转开发e what I have below
Map(x => x.WebAddress).Intercept<string, Uri>(y => new Uri(y));

What am I missing?


You should use an IUserType, this is an NHibernate feature rather than Fluent NHibernate. You'd then use CustomType<YourUserType>() on your property.

A google search reveals many different examples of implementing the IUserType interface, such as http://www.martinwilley.com/net/code/nhibernate/usertype.html.


I wish I could take credit, but I believe this example will do exactly what you are hoping to do. http://swik.net/tag4sree/Hibernate+-+Objects/Implementing+custom+types+in+nHibernate/b3s2p

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜