Sunday, March 20, 2011

Mapping a URI to string in Fluent NHibernate

(See this related question for LINQ-to-SQL)

I'd like to map a class that has a URI member to a string column using NHibernate. How exactly might I accomplish that?

I don't think the solution given to the related question works here - I can't declare a private field and map it, because the mapping needs to reference that field.

From stackoverflow
  • The same solution would work fine; You could define the string property as private so it is not exposed to anyone.

    Fluent NHibernate doesn't handle this as easily as standard HBM files, but it can be done a few ways. See the Fluent NHibernate Wiki for instructions.

    Alternatively, I think you'd have to define an IUserType class that can load/save the value as a string. Example of doing this with Fluent NHibernate can be found at the end of this blog post.

    ripper234 : Updated the question - I'm using Fluent NHibernate. How would such a mapping work? (Code sample if possible).
    Chris Shaffer : Added links to examples for both options.
    ripper234 : Looks interesting, thanks.

0 comments:

Post a Comment