How to index foreign keys using Fluent NHibernate and SchemaUpdate.Execute ()?

Is there a way in Fluent NHibernate to indicate that a foreign key should be indexed?

MS Sql server configuration does not index foreign keys by default. I would like for the schema generated by the NHibernate schema generation / update tools to index these keys. When I just use methods HasManyor HasManyToMany, such indexes are not created. Is this possible with raw XML mappings?

+3
source share
1 answer

I think the 'index' attribute for the column mapping element is what you need. If you are using the latest version of FNH, you can set this to one-to-many, for example:

HasMany(x => x.Components)
       .KeyColumns.Add("ProductId", c => c.Index("someIndex");

The same API is not yet available for many-to-many, but it is on its way.

+6
source

Source: https://habr.com/ru/post/1723721/


All Articles