[]
        
(Showing Draft Content)

C1.LiveLinq.LiveViews.View-1.AttachView

AttachView Method

AttachView<TResult>(Func<View<T>, View<TResult>>)

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

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

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

Returns
Type Description
View<TResult>

The attached subview.

Type Parameters
Name Description
TResult

The type of the elements in the subquery view.

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 and population of subviews, use the AttachView 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 AttachView 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,
        SalesByCountry = productSales.AttachView(v =>
            from s in v
            group s by s.Country into countrySales
            select new
            {
                Country = countrySales.Key,
                SaleCount = countrySales.LiveSum(s => s.Quantity).Value
            })
    };
See Also
AttachAggregationView<TResult>(Func<View<T>, AggregationView<T, TResult>>)

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

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

Declaration
public View<TResult> AttachView<TResult>(object subqueryId, Func<View<T>, View<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>, View<TResult>> selector

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

Returns
Type Description
View<TResult>

The attached subview.

Type Parameters
Name Description
TResult

The type of the elements in the subquery view.

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 AttachView method.

See Also