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
When using Where() and providing a string with either || or or, more than one property of type string, and using ToLower() on the string, the second string property is treated as a char.
In the example above, Name is of type string, and Description is of type string?, hence the null check. However, I have tested it with two non-nullable reference type strings.
The issue seems to occur primarily due to the use of ToLower(), as when removed, the code works as intended, excluding the case-insensitive search, regardless of the number of properties being searched via || or or.
An example of the code looks as follows:
varfilterExpression=string.Join(" or ",filterableProperties.Select(propertyName =>$"({propertyName} != null && Convert.ToString({propertyName}).ToLower().Contains(\"{filterValue}\"))"));returnquery.Where(filterExpression);
2. Exception
Exception message:
No property or field 'Description' exists in type 'Char' (at index 69)
Stack trace:
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression, String id)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseParenExpression()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values)
at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where(IQueryable source, ParsingConfig config, String predicate, Object[] args)
at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, ParsingConfig config, String predicate, Object[] args)
at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, String predicate, Object[] args)
3. Fiddle or Project
Unavailable
4. Any further technical details
The intended use is to query an EF Core entity and be able to search multiple property types (strings, ints, etc.) by converting them to strings prior to comparing them to the filter value. If there are better ways to perform case-insensitive comparison of different property types using DynamicLinq, I'm open to suggestions.
The text was updated successfully, but these errors were encountered:
1. Description
When using
Where()
and providing astring
with either||
oror
, more than one property of typestring
, and usingToLower()
on thestring
, the secondstring
property is treated as achar
.(Name != null && Convert.ToString(Name).ToLower().Contains("someword")) or (Description != null && Convert.ToString(Description).ToLower().Contains("someword"))
In the example above,
Name
is of typestring
, andDescription
is of typestring?
, hence thenull
check. However, I have tested it with two non-nullable reference typestring
s.The issue seems to occur primarily due to the use of
ToLower()
, as when removed, the code works as intended, excluding the case-insensitive search, regardless of the number of properties being searched via||
oror
.An example of the code looks as follows:
2. Exception
3. Fiddle or Project
Unavailable
4. Any further technical details
The intended use is to query an EF Core entity and be able to search multiple property types (strings, ints, etc.) by converting them to strings prior to comparing them to the filter value. If there are better ways to perform case-insensitive comparison of different property types using DynamicLinq, I'm open to suggestions.
The text was updated successfully, but these errors were encountered: