If you check out the source for NH, there is a project called
NHibernate.Mapping.Attributes.Test that contains a sample file (Domain.cs) that probably uses every available attribute.
Here's one sample.
It isn't pretty, but this is working great for me in a current project that uses 1.2.0b3.
This is for my Group class, which has a many-to-many relationship to users.
Code:
private IList<User> _members;
[
NHMA.Bag(1,
Inverse = true,
Lazy = true,
Table = "UserGroups",
Cascade=NHMA.CascadeStyle.SaveUpdate),
NHMA.Key(2, Column = "[Group]"),
NHMA.ManyToMany(3,
Column="[User]",
ClassType=typeof(User))
]
public virtual IList<User> Members
{
get { return _members; }
set { _members = value; }
}
And here's what the flip side of the relationship looks like (this is the Groups property of the User class)
Code:
private ISet<Group> _groups;
[
NHMA.Set(1,
Inverse = false,
Lazy=true,
Table="UserGroups"),
NHMA.Key(2, Column = "[User]"),
NHMA.ManyToMany(3,
Column = "[Group]",
ClassType=typeof(Group)),
NHMA.Cache(4,
Usage=NHMA.CacheUsage.ReadWrite)
]
public virtual ISet<Group> Groups
{
get { return _groups; }
set { _groups = value; }
}
Why did I use an ISet for one side of the relationship and IList for the other? I don't remember. I heard Sets were more efficient to update than Bags, but I could probably use ISet for both properties.