/// <summary>Adds a query filter to the filter context associated with the specified key.</summary> /// <typeparam name="T">The type of elements of the query.</typeparam> /// <param name="key">The filter key.</param> /// <param name="filter">The filter.</param> /// <returns>The query filter added to the filter context associated with the specified ke .</returns> public AliasBaseQueryFilter AddFilter <T>(object key, Func <IQueryable <T>, IQueryable <T> > filter) { #if EF6 var queryFilter = new QueryDbSetFilter <T>(this, filter); #else var queryFilter = new QueryFilter <T>(this, filter); #endif Filters.Add(key, queryFilter); return(queryFilter); }
/// <summary> /// Creates and return a filter associated with the specified key added for the context. /// </summary> /// <typeparam name="T">The type of elements of the query.</typeparam> /// <param name="key">The filter key associated to the filter.</param> /// <param name="queryFilter">The query filter to apply to the the context.</param> /// <param name="isEnabled">true if the filter is enabled.</param> /// <returns>The filter created and added to the the context.</returns> public static AliasBaseQueryFilter Filter <T>(object key, Func <IQueryable <T>, IQueryable <T> > queryFilter, bool isEnabled = true) { AliasBaseQueryFilter filter; if (!GlobalFilters.TryGetValue(key, out filter)) { #if EF6 filter = new QueryDbSetFilter <T>(null, queryFilter) { IsDefaultEnabled = isEnabled }; #else filter = new QueryFilter <T>(null, queryFilter) { IsDefaultEnabled = isEnabled }; #endif GlobalFilters.Add(key, filter); } return(filter); }