# C1.LiveLinq.Indexing.Subindex-2

## Content

<div class="doc-site-dotnet-api-container">



  <h1 id="C1_LiveLinq_Indexing_Subindex_2" data-uid="C1.LiveLinq.Indexing.Subindex`2" class="text-break">Subindex&lt;T, TKey&gt; Class
</h1>
  <div class="markdown level0 summary"><p>Defines a subindex, an index definition subordinate to another index definition, its parent.</p>
</div>
  <div class="markdown level0 conceptual"></div>
  <div class="inheritance">
    <h5>Inheritance</h5>
    <div class="level0"><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
    <div class="level1"><a class="xref" href="C1.LiveLinq.Indexing.IndexDefinition-1.html">IndexDefinition</a>&lt;T&gt;</div>
    <div class="level2"><a class="xref" href="C1.LiveLinq.Indexing.Subindex-1.html">Subindex</a>&lt;T&gt;</div>
    <div class="level3"><span class="xref">Subindex&lt;T, TKey&gt;</span></div>
  </div>
  <h6><strong>Namespace</strong>: <a class="xref" href="C1.LiveLinq.Indexing.html">C1.LiveLinq.Indexing</a></h6>
  <h6><strong>Assembly</strong>: C1.LiveLinq.4.8.dll</h6>
  <h5 id="C1_LiveLinq_Indexing_Subindex_2_syntax">Syntax</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public abstract class Subindex&lt;T, TKey&gt; : Subindex&lt;T&gt;</code></pre>
  </div>
  <div class="codewrapper">
    <pre><code class="lang-vbnet hljs">Public MustInherit Class Subindex(Of T, TKey)
    Inherits Subindex(Of T)</code></pre>
  </div>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td><p>The type of the elements of the collection to index.</p>
</td>
      </tr>
      <tr>
        <td><span class="parametername">TKey</span></td>
        <td><p>The type of the index key.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 id="C1_LiveLinq_Indexing_Subindex_2_remarks"><strong>Remarks</strong></h5>
  <div class="markdown level0 remarks"><p>An index (<a class="xref" href="C1.LiveLinq.Indexing.Index-2.html">Index&lt;T, TKey&gt;</a>) can have subindexes. Subindexes are optional,
not required for any indexing tasks, but can provide additional optimization and help minimize memory requirements when a collection is 
indexed by multi-level (multi-field) keys.</p>
<p>
Suppose we want to index a Customers table by two fields, (City, Rating), perhaps for speeding up queries like
<pre><code class="lang-csharp">from c in Customers where c.City == "London" &amp;&amp; c.Rating == 1 select c</code></pre>
We can do it by defining an index with key selector <code>c =&gt; new { c.City, c.Rating }</code> , that will index the table by two fields, creating a multi-field index.
Such index will suffice for optimizing the query above, but it will not optimize, for example, the following query:
<pre><code class="lang-csharp">from c in Customers where c.City == "London" &amp;&amp; c.Rating &gt; 2 select c</code></pre>
Also, multi-field indexes occupy more memory than necessary because they have to store repeated field values.

<p>
Subindexes provide a better alternative for optimizing multi-field searches. In the example above, we can define an index by City
and create a subindex of that index, by Rating. Using subindexes becomes even more effective when, as it is often happens,
we also need queries to search by additional fields, like, for example, if we need to search by ContactTitle inside a city
in addition to the search by Rating inside a city:
<pre><code class="lang-csharp">from c in Customers where c.City == "London" &amp;&amp; c.ContactTitle == "Owner" select c</code></pre>
All we have to do now is to add a second subindex to the index by City, a subindex by ContactTitle.

</div>
  <h3 id="properties">Properties
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_LiveLinq_Indexing_Subindex_2_KeySelector" data-uid="C1.LiveLinq.Indexing.Subindex`2.KeySelector">
          <a class="xref" href="C1.LiveLinq.Indexing.Subindex-2.KeySelector.html#C1_LiveLinq_Indexing_Subindex_2_KeySelector">KeySelector</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the expression used to obtain key value from an element of the indexed collection.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h3 id="extensionmethods">Extension Methods</h3>
  <div>
      <a class="xref" href="C1.LiveLinq.Hints.Indexed.html#C1_LiveLinq_Hints_Indexed__1___0_">Hints.Indexed&lt;T&gt;(T)</a>
  </div>
  <div>
      <a class="xref" href="C1.LiveLinq.Hints.Indexed.html#C1_LiveLinq_Hints_Indexed__1___0_C1_LiveLinq_IndexingHintAction_">Hints.Indexed&lt;T&gt;(T, IndexingHintAction)</a>
  </div>

</div>
