In NHibernate 3.2 mapping by code, you can index a given field like so:
mapper.Class<Customer>(map =>
{
map.Property(x => x.Address, m => m.Index("AddressIndex"));
});
I'd like to create an index covering the following fields:
- Address
- FirstName
- LastName
I see no Index method on the 'map' object, nor do I see an overload on the property specific Index method that allows you to specify additional columns. How can I accomplish this?
Edit, I found that if I do the following:
mapper.Class<Customer>(map =>
{
map.Property(x => x.Address, m => m.Index("AddressIndex"));
map.Property(x => x.FirstName, m => m.Index("AddressIndex"));
map.Property(x => x.LastName, m => m.Index("AddressIndex"));
});
An index is created covering all 3 columns, but not in the order I specified. Is there a way to specify the column order in the index?
If order does matter then one option is to create and execute a script after your schema has been generated.
I remember reading this about composite indexes and it seems order might or might NOT matter!