1

I have a Fluent NHibernate mapping override that I am using to create a HasMany component. Is there a way to have NH create a clustered index on the FK column in the component table? In my example below I am wanting a clustered index on the ItemDetailFk column. Thanks!

public class ItemDetailMap : IAutoMappingOverride<ItemDetail>
{
    public void Override(AutoMapping<ItemDetail> mapping)
    {
        mapping.HasMany<ItemDetailUDF>(x => x.UserDefinedFields)
            .Table("ItemUDF")
            .KeyColumn("ItemDetailFk")
            .Not.LazyLoad()
            .Fetch.Subselect()
            .Component(udfObj =>
            {
                udfObj.Map(x => x.UDFSequence);
                udfObj.Map(x => x.String0);
                udfObj.Map(x => x.String1);
                udfObj.Map(x => x.String2);

            });
    }
}
SkipHarris
  • 2,334
  • 1
  • 25
  • 31
  • Possible duplicate of http://stackoverflow.com/questions/4869586/fluent-nhibernate-how-to-create-a-clustered-index-on-a-many-to-many-join-table and http://stackoverflow.com/questions/1356467/how-can-you-create-clustered-indexes-with-fluent-nhibernate – Stefan Steinegger Aug 11 '11 at 06:11

1 Answers1

6

By default the PK is created as the clustered index. For clustered index there is more work, see links in Stefan Steinegger's comment. But there is a way to define an index.

mapping.HasMany<ItemDetailUDF>(x => x.UserDefinedFields)
    .Table("ItemUDF")
    .KeyColumns.Add("ItemDetailFk", c => c.Index("myindex"))
Firo
  • 30,626
  • 4
  • 55
  • 94