0

I want to create a non clustered but unique index on two columns. I tried:

Map(x => x.Col1).Index("IX").UniqueKey("IX");
Map(x => x.Col2).Index("IX").UniqueKey("IX");

and got non-unique index and additional unique constraint (switching order doesn't help),

or:

Map(x => x.Col1).Index("IX").Unique();
Map(x => x.Col1).Index("IX").Unique();

and got non-unique index and 2 additional unique constraints (switching order doesn't help).

Is there a way to create only the index, but unique?

eitanpo
  • 344
  • 1
  • 10

1 Answers1

2

If I leave out the .Index() and just write

Map(x => x.Col1).UniqueKey("IX");
Map(x => x.Col2).UniqueKey("IX");

I get a unique nonclustered Index in SQL 2008 Express (R2) without any additional constraints. (At least that is displayed when I view the porperties in the SQL Management Studio.)

Florian Lim
  • 5,332
  • 2
  • 27
  • 28
  • Thanks. This generates different SQL script, but the result is almost "identical". You get unique constraint and an additional unique index, instead of just unique index. More info in this [question](http://stackoverflow.com/questions/3978680/constraint-is-key-is-index-is-constraint) – eitanpo Mar 27 '11 at 14:09