Creates a new index and adds it to the collection of indexes.

Namespace:  C1.LiveLinq.Indexing
Assembly:  C1.LiveLinq (in C1.LiveLinq.dll)

Syntax

C#
public IIndexScanner<T, TKey> Add<TKey>(
	Expression<Func<T, TKey>> keySelector,
	bool keyIsUnique
)
Visual Basic
Public Function Add(Of TKey) ( _
	keySelector As Expression(Of Func(Of T, TKey)), _
	keyIsUnique As Boolean _
) As IIndexScanner(Of T, TKey)

Parameters

keySelector
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'T, TKey>)>)>>)>)>
Key selector expression of the index, see KeySelector.
keyIsUnique
Type: System..::..Boolean
Specifies whether the key used in this index is a unique key for the indexed collection (default: false).

Type Parameters

TKey
The type of the index key.

Return Value

The new index added to the collection of indexes.

Remarks

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.

See Also