R – NHibernate Attributes Mapping List

attributesnhibernatenhibernate-mapping

I'm a new NHibernate developer. I'm using attributes and not map files and I have configured the application to create the tables automatically.

I Have two classes , Group and User.

Withing the Group class I have a list of users

public class Group
{
    [NHibernate.Mapping.Attributes.Id(Name = "GroupId")]
    [NHibernate.Mapping.Attributes.Generator(Class = "guid")]
    public virtual Guid GroupId { get; set; }
    // What Attributes do I place here
    public virtual List<User> Users { get; set; }
}

I can't find the right attributes so that there will be two tables that have one to many relation.

Can anyone help?

Thanks,
Ronny

Best Answer

[ManyToMany], [OneToMany] or [ManyToOne] (those linked docs are fairly useless though) depending on how you want it setup. Probably [OneToMany], and then the same on a User.

You could avoid the pain by using the Fluent NHibernate library instead, if you haven't already tried it.