Several unique keys in nhibernate

I need the constraints created as follows:

CONSTRAINT [IX_Unique_1] UNIQUE NONCLUSTERED 
(
    [Ordering] ASC,
    [Description] ASC
),
CONSTRAINT [IX_Unique_2] UNIQUE NONCLUSTERED 
(
    [Description] ASC
)

I have the following nHibernate mapping:

<property name="Description" column="Description" type="String" unique-key="IX_Seed_Template_Fields_Result" />

<property name="Ordering" column="Ordering" type="Int32" unique-key="IX_Seed_Template_Fields_Result" />

So, how can I add a separate unique constraint only for the Description column?

+3
source share
2 answers

If you do not need the index names in the database, you can map them as follows:

<property 
  name="Description" 
  column="Description" 
  type="String" 
  unique-key="Description, Ordering_Description" />

<property 
  name="Ordering" 
  column="Ordering" 
  type="Int32" 
  unique-key="Ordering_Description" />

you can provide a comma-separated list of index names. All columns that have the same name in the list are added to the same index.

+4
source

Use <database-object>to create additional indexes.

5.6. Database Helper Objects

+2

Source: https://habr.com/ru/post/1771896/


All Articles