Skip to content

Where throws exception when property name doesn't match enum name #513

Closed
@sanderobdeijn

Description

@sanderobdeijn

1. Description

Where throws an exception when property name doesn't match enum name.

2. Exception

Message:

System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'TestEnum' exists in type 'TestClass'
  Stack Trace: 
    ExpressionParser.ParseMemberAccess(Type type, Expression expression)
    ExpressionParser.ParseIdentifier()
    ExpressionParser.ParsePrimaryStart()
    ExpressionParser.ParsePrimary()
    ExpressionParser.ParseUnary()
    ExpressionParser.ParseMultiplicative()
    ExpressionParser.ParseAdditive()
    ExpressionParser.ParseShiftOperator()
    ExpressionParser.ParseComparisonOperator()
    ExpressionParser.ParseLogicalAndOrOperator()
    ExpressionParser.ParseIn()
    ExpressionParser.ParseAndOperator()
    ExpressionParser.ParseOrOperator()
    ExpressionParser.ParseLambdaOperator()
    ExpressionParser.ParseNullCoalescingOperator()
    ExpressionParser.ParseConditionalOperator()
    ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
    DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
    DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
    DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values)
    DynamicQueryableExtensions.Where(IQueryable source, ParsingConfig config, String predicate, Object[] args)
    DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, ParsingConfig config, String predicate, Object[] args)
    DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, String predicate, Object[] args)
    DynamicLinqEnumTest.WhereFails() line 19

3. Fiddle or Project

https://dotnetfiddle.net/nChrvb

4. Any further technical details

When adding a second property to the class with the same name as the enum the where succeeds.

public class TestClass
{
	public TestEnum Test { get; set; }
	public TestEnum TestEnum { get; set; }
}

At first, I thought in this case it would maybe filter on the TestEnum instead of the Test property but after testing this doesn't seem to be the case.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions