-
Notifications
You must be signed in to change notification settings - Fork 147
Changing case sensitivity
Ricardo da Verdade Silva edited this page Oct 29, 2015
·
3 revisions
If you are using a case-sensitive provider (e.g. Linq To Objects) but you would like case-insensitive queries, you can use the code at the following Gist to apply a transform to your IQueryable
-
Install-package QueryInterceptor (https://www.nuget.org/packages/QueryInterceptor/)
-
From the gist copy IQueryableCaseExtensions and SetComparerExpressionVisitor into your web project, so the Controller with the DataTableResult action can use them.
-
Change your controller code to something like this:
@using QueryInterceptor
...
public DataTablesResult<TDataTableRow> GetDataTableData(DataTablesParam dataTableParam)
{
var originalQueryable = ... some code to get your IQueryable<TDataTableRow> ...;
var caseInsenstitiveQueryable = originalQueryable.InterceptWith(new SetComparerExpressionVisitor(StringComparison.CurrentCultureIgnoreCase));
return DataTablesResult.Create(caseInsenstitiveQueryable, dataTableParam);
}