[]
        
(Showing Draft Content)

C1.LiveLinq.LiveViews.View-1.AttachAggregationView

AttachAggregationView Method

AttachAggregationView<TResult>(object, Func<View<T>, AggregationView<T, TResult>>)

Includes an aggregation subquery into the incremental maintenance mechanism of a view and uniquely identifies it among other subqueries of the same view.

Declaration
public AggregationView<T, TResult> AttachAggregationView<TResult>(object subqueryId, Func<View<T>, AggregationView<T, TResult>> selector)
Parameters
Type Name Description
object subqueryId

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.

Func<View<T>, AggregationView<T, TResult>> selector

A function to obtain the attached aggregation subview from the view to which it is attached.

Returns
Type Description
AggregationView<T, TResult>

The attached aggregation subview.

Type Parameters
Name Description
TResult

The type of the elements in the aggregation subview.

Remarks

This overload must be used if you have several subviews attached to the same view. The subqueryId' can be any string as long as it is not repeated for two different subviews attached to the same view.

See the other overload for the explanation of the AttachAggregationView method.

See Also
AttachView<TResult>(object, Func<View<T>, View<TResult>>)

AttachAggregationView<TResult>(Func<View<T>, AggregationView<T, TResult>>)

Includes an aggregation subquery into the incremental maintenance mechanism of a view.

Declaration
public AggregationView<T, TResult> AttachAggregationView<TResult>(Func<View<T>, AggregationView<T, TResult>> selector)
Parameters
Type Name Description
Func<View<T>, AggregationView<T, TResult>> selector

A function to obtain the attached aggregation subview from the view to which it is attached.

Returns
Type Description
AggregationView<T, TResult>

The attached aggregation subview.

Type Parameters
Name Description
TResult

The type of the elements in the aggregation subview.

Remarks

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 AttachAggregationView method to make the outer view aware of its subview. Then the outer view will cache and reuse subview objects it creates.

If there are more than one subviews attached to a single view, every subview must be supplied with a unique subview id by using the AttachAggregationView overload with subviewId parameter.

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 => v.LiveSum(s => s.Quantity))
    };
See Also
AttachView<TResult>(Func<View<T>, View<TResult>>)