[]
Creates a new index and adds it to the collection of indexes.
public Index<T, TKey> Add<TKey>(Expression<Func<T, TKey>> keySelector)
Type | Name | Description |
---|---|---|
Expression<Func<T, TKey>> | keySelector | Key selector expression of the index, see KeySelector. |
Type | Description |
---|---|
Index<T, TKey> | The new index added to the collection of indexes. |
Name | Description |
---|---|
TKey | The type of the index key. |
Creates a new index and adds it to the collection of indexes.
public Index<T, TKey> Add<TKey>(Expression<Func<T, TKey>> keySelector, bool keyIsUnque)
Type | Name | Description |
---|---|---|
Expression<Func<T, TKey>> | keySelector | Key selector expression of the index, see KeySelector. |
bool | keyIsUnque | true if a unique index must be created. |
Type | Description |
---|---|
Index<T, TKey> | The new index added to the collection of indexes. |
Name | Description |
---|---|
TKey | The type of the index key. |
A unique index occupies less memory and performs better than a non-unique index (although the difference isn't dramatic). Therefore, for unique keys, it's recommended to specify the corresponding index as unique.
But do that only if you are sure that the key is indeed unique, as it imposes a uniqueness constraint on the indexed collection. An attempt to modify the indexed collection violating the uniqueness throws an InvalidOperationException.