Papy214 wrote:
Hi,
I need to create an indexed string column.
I don't find the mapping to use. Can you help me please ?
<snip>
J-L
Hi J-L
Indexes are created on the database to help speed up queries. Mostly you just create the index and allow the db to use it. You don't have to do anything else after creating it. Sometimes, when writing SQL SELECT statements, and can give the db a hint on what indexes to use, but the db's query optimisation engine is under no obligation to use the hint! (It also depends on the db whether you can do this.) On the whole however, indexes are a "set and forget" type performance optimisation done on the db.
Keep in mind that indexing a character or string based column is also not generally a good idea, as the indexes are very slow to build and use compared to a more discrete type, such as an Int.
AFAIK, indexes are not used through nHibernate. In each mapping file you do need to have a <id> element, which matches either the primary key or another candidate key. This is done as :
Code:
<id name="ReactionId" column="Reaction_Id" type="Int32" length="4" unsaved-value="0">
<generator class="identity" />
</id>
and of course you can modify the type if your key is a string. But, I would strongly recommend using a surrogate Int type key.
Phil