# C1.LiveLinq.LiveViews.View-1.AttachAggregationView

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView_" data-uid="C1.LiveLinq.LiveViews.View`1.AttachAggregationView*">AttachAggregationView Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView_" data-uid="C1.LiveLinq.LiveViews.View`1.AttachAggregationView*"></a>
<h4 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView__1_System_Object_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_AggregationView__0___0___" data-uid="C1.LiveLinq.LiveViews.View`1.AttachAggregationView``1(System.Object,System.Func{C1.LiveLinq.LiveViews.View{`0},C1.LiveLinq.LiveViews.AggregationView{`0,``0}})">AttachAggregationView&lt;TResult&gt;(object, Func&lt;View&lt;T&gt;, AggregationView&lt;T, TResult&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>Includes an aggregation subquery into the incremental maintenance mechanism of a view and uniquely identifies it among other subqueries of the same view.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public AggregationView&lt;T, TResult&gt; AttachAggregationView&lt;TResult&gt;(object subqueryId, Func&lt;View&lt;T&gt;, AggregationView&lt;T, TResult&gt;&gt; selector)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function AttachAggregationView(Of TResult)(subqueryId As Object, selector As Func(Of View(Of T), AggregationView(Of T, TResult))) As AggregationView(Of T, TResult)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><span class="parametername">subqueryId</span></td>
      <td><p>A string uniquely specifying this subquery in the view to which it is attached. Can be any string.
The only requirement is that different subqueries attached to the same view, if such exist, must have different subquery ids.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;<a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;T&gt;, <a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;T, TResult&gt;&gt;</td>
      <td><span class="parametername">selector</span></td>
      <td><p>A function to obtain the attached aggregation subview from the view to which it is attached.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;T, TResult&gt;</td>
      <td><p>The attached aggregation subview.</p>
</td>
    </tr>
  </tbody>
</table>
<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">TResult</span></td>
      <td><p>The type of the elements in the aggregation subview.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView__1_System_Object_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_AggregationView__0___0____remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This overload must be used if you have several subviews attached to the same view.
The <i>subqueryId'</i> can be any string as long as it is not repeated for two different subviews attached to the same view.</p>
<p>See the other overload for the explanation of the <b>AttachAggregationView</b> method.</p>
</div>
<h5 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView__1_System_Object_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_AggregationView__0___0____seealso">See Also</h5>
<div class="seealso">
    <div><a class="xref" href="C1.LiveLinq.LiveViews.View-1.AttachView.html#C1_LiveLinq_LiveViews_View_1_AttachView__1_System_Object_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_View___0___">AttachView</a>&lt;TResult&gt;(<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;<a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;T&gt;, <a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;TResult&gt;&gt;)</div>
</div>


<a id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView_" data-uid="C1.LiveLinq.LiveViews.View`1.AttachAggregationView*"></a>
<h4 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView__1_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_AggregationView__0___0___" data-uid="C1.LiveLinq.LiveViews.View`1.AttachAggregationView``1(System.Func{C1.LiveLinq.LiveViews.View{`0},C1.LiveLinq.LiveViews.AggregationView{`0,``0}})">AttachAggregationView&lt;TResult&gt;(Func&lt;View&lt;T&gt;, AggregationView&lt;T, TResult&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>Includes an aggregation subquery into the incremental maintenance mechanism of a view.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public AggregationView&lt;T, TResult&gt; AttachAggregationView&lt;TResult&gt;(Func&lt;View&lt;T&gt;, AggregationView&lt;T, TResult&gt;&gt; selector)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function AttachAggregationView(Of TResult)(selector As Func(Of View(Of T), AggregationView(Of T, TResult))) As AggregationView(Of T, TResult)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;<a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;T&gt;, <a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;T, TResult&gt;&gt;</td>
      <td><span class="parametername">selector</span></td>
      <td><p>A function to obtain the attached aggregation subview from the view to which it is attached.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.LiveLinq.LiveViews.AggregationView-2.html">AggregationView</a>&lt;T, TResult&gt;</td>
      <td><p>The attached aggregation subview.</p>
</td>
    </tr>
  </tbody>
</table>
<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">TResult</span></td>
      <td><p>The type of the elements in the aggregation subview.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView__1_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_AggregationView__0___0____remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Subquery is a query inside a function that is a part of an outer query.
If the outer query is a live view, and its base data changes so it needs to recompute the function,
by default it just evaluates the function, which means creating a new view object for the subquery on every such recomputation.
To improve performance by avoiding repeated creation of subviews, use the <b>AttachAggregationView</b> method to make the
outer view aware of its subview. Then the outer view will cache and reuse subview objects it creates.</p>
<p>If there are more than one subviews attached to a single view, every 
subview must be supplied with a unique <i>subview id</i> by using the <b>AttachAggregationView</b> overload with <i>subviewId</i> parameter.</p>
<example>
<pre><code class="lang-csharp">var productView =
    from p in products
    join s in sales on p.ProductID equals s.ProductID into productSales
    select new
    {
        p.Name,
        ProductTotal = productSales.AttachAggregationView(v =&gt; v.LiveSum(s =&gt; s.Quantity))
    };</code></pre>
</example>
</div>
<h5 id="C1_LiveLinq_LiveViews_View_1_AttachAggregationView__1_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_AggregationView__0___0____seealso">See Also</h5>
<div class="seealso">
    <div><a class="xref" href="C1.LiveLinq.LiveViews.View-1.AttachView.html#C1_LiveLinq_LiveViews_View_1_AttachView__1_System_Func_C1_LiveLinq_LiveViews_View__0__C1_LiveLinq_LiveViews_View___0___">AttachView</a>&lt;TResult&gt;(<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;<a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;T&gt;, <a class="xref" href="C1.LiveLinq.LiveViews.View-1.html">View</a>&lt;TResult&gt;&gt;)</div>
</div>
</div>
