0

I have a little mapping problem for NHibernate. First of all my Database structure looks like this.

A Table Post(Id, Title, Text ...... ) with Articels A Table Tag(Tagname) with Tags (Tagcloud) A Table PostTag(PostId, TagName) for mapping Post and Tag.

So every post can have more Tags. Now I wanna map the Tags in a Post as a basic collection with strings, not as objects of Tag for example. So does anyone know how to do this? I'm new to this and I cant find a answer until now :)

So faithfully. Jan

  • Try look here: https://stackoverflow.com/q/4768788/735864 or here: https://stackoverflow.com/q/606607/735864 – danyolgiax Jun 13 '11 at 10:18

1 Answers1

0

when you dont need to update tag:

HasMany(x => x.Tags)
    .Table("PostTag")
    .KeyColumn("PostId")
    .Element("Tagname");

if you need to update then:

HasManyToMany(x => x.Tagnames)
    .Table("PostTag")
    .AsBag()  // or AsArray()
    .ParentKeyColumn("PostId")
    .ChildKeyColumn("TagName")
    .Element("TagName");

Or

class Post
{
    public virtual ISet<Tag> Tags { get; set; }

    public virtual string[] Tagnames
    { get { return Tags.Select(t => t.Name).ToArray(); } }
}
Firo
  • 30,626
  • 4
  • 55
  • 94