views:

274

answers:

1

Is there any way to specify that a foreign key should also be indexed using fluent nhibernate? MS Sql Server does not by default index foreign keys, and I would like the schema generated by the nhibernate schema generation/update tools to create these. When I just use the HasMany or HasManyToMany methods, no such indexes are created. Is this even possible with raw xml mappings?

Thanks for the help!

+3  A: 

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:

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

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

Paul Batum
Great - thx - that's what I was looking for. Looks like the version of FNH that I have (1.0 RTM) does not yet have that option - is this only available for a version that must be built from source?
Krazzy
You don't have to build from source. The download page has the latest builds. revision 595 should have this change. http://fluentnhibernate.org/downloads
Paul Batum
Ok - now I see the builds. Guess I should have scrolled down a few pixels instead of clicking on the first thing that said download that I saw :)
Krazzy