Is there a way in Fluent NHibernate to specify that a foreign key should be indexed?
MS Sql Server’s default configuration does not index foreign keys. I would like the schema generated by the NHibernate schema generation/update tools to index these keys. When I just use the HasMany or HasManyToMany methods, no such indexes are created. Is this even possible with raw XML mappings?
I think the ‘index’ attribute on a column mapping element is what you are after. If you’re on the latest version of FNH, you can set this for a one-to-many like so:
The same API is not yet available for many-to-many’s, but it is on its way.