Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sanderobdeijn opened this issue May 19, 2021 · 1 comment
Closed
Assignees
Labels

Comments

@sanderobdeijn
Copy link

sanderobdeijn commented May 19, 2021

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.

@sanderobdeijn sanderobdeijn changed the title Where throws exceptiong when property name doesn't match enum name Where throws exception when property name doesn't match enum name May 19, 2021
@StefH StefH added the bug label May 19, 2021
@StefH StefH self-assigned this May 19, 2021
@StefH
Copy link
Collaborator

StefH commented May 19, 2021

This seems line a bug. I'll check it.

As a workaround, you can try:
var result = unfilteredList.Where("Test == @0", TestEnum.A).ToList();

@StefH StefH mentioned this issue May 20, 2021
@StefH StefH closed this as completed May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants