Hi, I have the follow implementation:

public class ReferenceEntity: AbstractEntity
    [Field(Nullable = true)]
public string Identifier { get;  set; }

[Index("Name", Unique = true]
[Index("Identifier", Unique = true]
public class AddressType : ReferenceEntity
    [Field(Nullable = true)]
public string Name { get;  set; }

The index of the field 'Name' would be set, but the index on the field 'Identifier' which is a property of the base class would not be set. I have read some similar issues on the forum but I could not find out if this one was solved. Or is there a workaround for this?

thanks and regards Marco Leonardi

asked Jan 04 '11 at 05:59

MarcoLeonardi's gravatar image


edited Jan 04 '11 at 16:05

Sergey's gravatar image


One Answer:

Hi Marco, I'd imagine that you have to declare the Index-Attribute on the class that contains the Field that is to be indexed. Depending on your chosen type of hierarchy mapping, those two Entities could end up in completely different tables and you couldn't declare an SQL index on a field of table A in a related table B either.

answered Jan 04 '11 at 08:08

Sebastian%20Hauer's gravatar image

Sebastian Hauer

Yes exactly, those two entities are represented as two tables on the SQL - Server. To set the index on the base entity is only a solution if the index is set over only one field. I have to set also the follow Index:

[Index("Identifier","Name", Unique = true]

Each Entity which is derived from 'ReferenceEntity' can have a different index.

(Jan 04 '11 at 10:19) MarcoLeonardi MarcoLeonardi's gravatar image


  • You can use only declared fields in indexes in case with table per class mapping (the default one).
  • As far as I remember, all fields can be used with two other types of hierarchy mapping (table per hierarchy, table per concrete class). At least, there should be no any strong limitations for this.
(Jan 04 '11 at 15:50) Sergey Sergey's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA