public class StoreMap : ClassMap<Store>
{
public StoreMap()
{
Id(x => x.Id);
Map(x => x.Name);
HasMany(x => x.Staff)
.Inverse()
.Cascade.All();
HasManyToMany(x => x.Products)
.Cascade.All()
.Table("StoreProduct");
}
}
You've also just got your first taste of the fluent interface Fluent NHibernate provides. The HasMany
method has a second call directly from it's return type (Inverse()
), and HasManyToMany
has Cascade.All()
and Table
; this is called method chaining, and it's used to create a more natural language in your configuration.
Inverse
onHasMany
is an NHibernate term, and it means that the other end of the relationship is responsible for saving.Cascade.All
onHasManyToMany
tells NHibernate to cascade events down to the entities in the collection (so when you save theStore
, all theProduct
s are saved too).Table
sets the many-to-many join table name.
https://github.com/jagregory/fluent-nhibernate/wiki/Database-configuration