[]
        
(Showing Draft Content)

C1.LiveLinq.Indexing.IndexCollection-1.Add

Add Method

Add<TKey>(Expression<Func<T, TKey>>)

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

Declaration
public Index<T, TKey> Add<TKey>(Expression<Func<T, TKey>> keySelector)
Parameters
Type Name Description
Expression<Func<T, TKey>> keySelector

Key selector expression of the index, see KeySelector.

Returns
Type Description
Index<T, TKey>

The new index added to the collection of indexes.

Type Parameters
Name Description
TKey

The type of the index key.

Add<TKey>(Expression<Func<T, TKey>>, bool)

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

Declaration
public Index<T, TKey> Add<TKey>(Expression<Func<T, TKey>> keySelector, bool keyIsUnque)
Parameters
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.

Returns
Type Description
Index<T, TKey>

The new index added to the collection of indexes.

Type Parameters
Name Description
TKey

The type of the index key.

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.