ערוך

שתף באמצעות


QueryableFilterUserControl.GetQueryable(IQueryable) Method

Definition

Gets the transformed IQueryable object from the source IQueryable object.

public:
 abstract System::Linq::IQueryable ^ GetQueryable(System::Linq::IQueryable ^ source);
public abstract System.Linq.IQueryable GetQueryable (System.Linq.IQueryable source);
abstract member GetQueryable : System.Linq.IQueryable -> System.Linq.IQueryable
Public MustOverride Function GetQueryable (source As IQueryable) As IQueryable

Parameters

source
IQueryable

The source IQueryable object.

Returns

The transformed IQueryable object from the source IQueryable object.

Examples

This method is implemented to transform the source IQueryable object into the target IQueryable object. Examples of IQueryable expressions that you might want to implement include order by, range, or search.

The following example shows how to implement the GetQueryable method for a Boolean filter that is derived from QueryableFilterUserControl.

public override IQueryable GetQueryable(IQueryable source) {  
    if (String.IsNullOrEmpty(DropDownList1.SelectedValue)) {  
        return source;  
    }  

    bool value = Convert.ToBoolean(DropDownList1.SelectedValue);  

    ParameterExpression parameterExpression =   
        Expression.Parameter(source.ElementType, "item");  
    Expression body = BuildQueryBody(  
        parameterExpression, value);  

    LambdaExpression lambda = Expression.Lambda(body,   
        parameterExpression);  
    MethodCallExpression whereCall = Expression.Call(  
        typeof(Queryable),   
        "Where",   
        new Type[] { source.ElementType },   
        source.Expression, Expression.Quote(lambda));  
    return source.Provider.CreateQuery(whereCall);  
}  
Public Overloads Overrides Function GetQueryable(ByVal source As IQueryable) As IQueryable   
    If [String].IsNullOrEmpty(DropDownList1.SelectedValue) Then   
        Return source   
    End If   

    Dim value As Boolean = Convert.ToBoolean(DropDownList1.SelectedValue)   

    Dim parameterExpression As ParameterExpression = Expression.Parameter(source.ElementType, "item")   
    Dim body As Expression = BuildQueryBody(parameterExpression, value)   

    Dim lambda As LambdaExpression = Expression.Lambda(body, parameterExpression)   
    Dim whereCall As MethodCallExpression = Expression.[Call](GetType(Queryable), "Where", _  
         New Type() {source.ElementType}, source.Expression, Expression.Quote(lambda))   
    Return source.Provider.CreateQuery(whereCall)   
End Function  

Remarks

You must implement this method if you derive a control from QueryableFilterUserControl.

Applies to