There are several collection types available for use in relationships with Fluent NHibernate.
The collection type you've used in your entity will affect how Fluent NHibernate maps that property. If you're using an ISet
from Iesi.Collections then the collection will be mapped as a set
, otherwise it will default to using a bag
.
You can explicitly set what kind of collection you want to use with several methods we've provided.
HasMany(x => x.Customers) .AsList(); HasMany(x => x.Customers) .AsSet(); HasMany(x => x.Customers) .AsBag(); HasMany(x => x.Customers) .AsMap(); HasMany(x => x.Customers) .AsArray();
Also, if you're using a custom collection type, Fluent NHibernate will automatically inform NHibernate of it; however, if you're using a custom type that's hidden behind an interface, then you'll still have to specify it with CollectionType
.
HasMany(x => x.Customers) .CollectionType<CustomCollectionType>();