开发者

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 开发者_Go百科a configuration that will be run after the schema is created/updated ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜