You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The datatype of Filter.Value needs to be of type string instead of 'object'. The reason behind this is when we post the data from the kendo-ui grid to asp.net controller's DataSourceRequest parameter, the value field gets populated with a string[1](array of strings with length=1). Thus when executing the query into SQL it throws below error:
Operator '=' incompatible with operand types 'String' and 'String[]'
If the 'Filter.Value' is of type string, it works just as expected.
The text was updated successfully, but these errors were encountered:
To resolve ERROR GlobalExceptionHandling.OnException - Operator '!=' incompatible with operand types 'Guid' and 'String' (at index 10)
I have changed the values to typed values through ConvertType
`
private static IQueryable Filter(IQueryable queryable, Filter filter)
{
if (filter != null && filter.Logic != null)
{
// Collect a flat list of all filters
var filters = filter.All();
// Get all filter values as array (needed by the Where method of Dynamic Linq)
var values = filters.Select(f => ConvertType<T>(f.Value, f.Field)).ToArray();
// Create a predicate expression e.g. Field1 = @0 And Field2 > @1
string predicate = filter.ToExpression(filters);
// Use the Where method of Dynamic Linq to filter the data
queryable = queryable.Where(predicate, values);
}
return queryable;
}
private static object ConvertType<T>(string value, string field)
{
var type = typeof(T).GetProperty(field).PropertyType;
return TypeDescriptor.GetConverter(type).ConvertFromString(value);
}
The datatype of Filter.Value needs to be of type string instead of 'object'. The reason behind this is when we post the data from the kendo-ui grid to asp.net controller's DataSourceRequest parameter, the value field gets populated with a string[1](array of strings with length=1). Thus when executing the query into SQL it throws below error:
Operator '=' incompatible with operand types 'String' and 'String[]'
If the 'Filter.Value' is of type string, it works just as expected.
The text was updated successfully, but these errors were encountered: