Hello.
IQueryable extension method ToDataSourceResult currently creates query like
myQuery.Where(x=>x.SearchField.Contains(searchString))
when using Contains operator.
Unfortunately I'm using no-sql database RavenDb and its linq provider doesn't support contains method. Instead it offers extension for IQueryable called Search.
So when doing full-text search I should write myQuery.Search(x=>x.SearchField, searchString) instead Where clause. That's why I'm curious is there any opportunity to override default predicate builder?
Right now I'm doing it so (it's very basic implementation):
Is it correct workaround? Or there is more obvious solution that I couldn't find in docs?
IQueryable extension method ToDataSourceResult currently creates query like
myQuery.Where(x=>x.SearchField.Contains(searchString))
when using Contains operator.
Unfortunately I'm using no-sql database RavenDb and its linq provider doesn't support contains method. Instead it offers extension for IQueryable called Search.
So when doing full-text search I should write myQuery.Search(x=>x.SearchField, searchString) instead Where clause. That's why I'm curious is there any opportunity to override default predicate builder?
Right now I'm doing it so (it's very basic implementation):
public
static
IQueryable<TEntity> ApplyFiltering<TEntity>(
this
IQueryable<TEntity> queryable, IList<IFilterDescriptor> filters) where TEntity:
class
{
foreach
(var filter
in
filters.Cast<FilterDescriptor>()){
var pe = Expression.Parameter(
typeof
(TEntity),
"x"
);
var left = Expression.Property(pe,
typeof
(TEntity).GetProperty(filter.Member));
queryable = queryable.Search(Expression.Lambda<Func<TEntity,
object
>>(left,
new
ParameterExpression[] { pe }), filter.Value.ToString());
}
filters.Clear();
return
queryable;
}
//And controller code:
public
ActionResult Data_Read([DataSourceRequest] DataSourceRequest request)
{
var query = repository.GetQueryable();
query = query.ApplyFilters(request.Filters);
return
Json(query.ToDataSourceResult(request));
}