Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a multi-column index with Fluent NHibernate

The goal here is have my complete database configuration and schema generation handled by fluent nhibernate.

Is there a way to to specify a multi-column index with Fluent nhibernate?

I understand that you can specify an index on a single property/column

like so :

mapping.Map(x => x.ItemDt).Index("IX_DataTransferLog_ItemDt");

how can I specify multiple columns?

If that isn't possible, is there a way to add raw SQL statements to a configuration that will be run after the schema is created/updated ?

like image 516
Lance Avatar asked Nov 06 '10 21:11

Lance


1 Answers

In XML-mappings this can be achieved by adding index with same name to all the properties that needs to be in the index:

<property name="Name" index="MyIndex" />
<property name="RunTimeInMinutes" index="MyIndex" />

Unfortunately I do not have any project currently using Fluent NHibernate that I could test this on, but I think this works in Fluent NHibernate the same way:

mapping.Map(x => x.Name).Index("MyIndex");
mapping.Map(x => x.RunTimeInMinutes).Index("MyIndex");

If this doesn't work, you can add the raw SQL required to create the index in database-object in mapping. NHibernate will execute the SQL when database is created using SchemaExport. I don't know if there is Fluent version for mapping database-objects but you can map database-object using XML and add the mapping file to Fluent NHibernate's configuration.

like image 52
Ultor Avatar answered Sep 20 '22 13:09

Ultor