Skip to content

DynamicExpressionParser.ParseLambda cannot parse a Method which accepts an expression as parameter #288

@wertzui

Description

@wertzui

I have a Method that accepts an Expression as Parameter. However the Parser does not recognize q and instead tries to find Foo on it.

The Exception is

System.Linq.Dynamic.Core.Exceptions.ParseException: No property or field 'Foo' exists in type 'QueryStart'

Here is a Test to verify the Problem

    [TestClass]
    public class QueryParserTests
    {
        [TestMethod]
        public void Parse_can_Select()
        {
            // Arrange
            var query = "Start.Select(q => q.Foo).ToListAsync()";

            // Act
            var exp = DynamicExpressionParser.ParseLambda<QueryStart, Task>(ParsingConfig.Default, false, query);

            // Assert no error was thrown
            Assert.IsNotNull(exp);
        }

        private class QueryTest
        {
            public int Foo { get; set; }
        }

        private class QueryStart
        {
            public IMyQuery<QueryTest> Start { get; set; }
        }

        private interface IMyQuery<T>
        {
            IMyQuery<Tnew> MySelect<Tnew>(Expression<Func<T, Tnew>> exp);

            Task<List<T>> ToListAsync();
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions