views:

235

answers:

2

I'm building a blog using C# and nHibernate for my database persistence. I want to make the entries taggable so I have an IList for the tags property. But how do I map this to a comma separated list in a single column in my database?

I want to avoid using a separate table for the tags and just keep them in one column as a separated list. So I'm basically trying to map a comma separated list in the database to a IList property. Is this possible in nHibernate?

+4  A: 

Yes, this is possible:

http://www.nablasoft.com/alkampfer/index.php/2008/10/21/some-details-on-older-post-about-usertype/

Add that file to your assembly and then reference it in your mapping file:

<property name='ListAsStringProperty'
              type='namespace.StringListUserType, assembly' />

The property mapped should be a simple collection (List or IList), override the char separator to make it into a comma.

Watson
+1  A: 

Why not make it another table? That way you could do tag clouds, searches on tags, etc.

joegtp
I guess I could create a separate table, and your right it would benefit me more to break it out, but it would be cool to know how to do this without relying on changing my table schema.
Chris