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

Error when trying to access an object declared on another lambda #173

Closed
VAdri opened this issue Jun 9, 2018 · 2 comments
Closed

Error when trying to access an object declared on another lambda #173

VAdri opened this issue Jun 9, 2018 · 2 comments

Comments

@VAdri
Copy link

VAdri commented Jun 9, 2018

Trying to parse a dynamic linq expression with multiple lambdas, when accessing an object declared on a parent lambda, throws an error:

context.Companies.Where("Employees.Any(e => e.Salary < it.MinimumSalary)");
System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'MinimumSalary' exists in type 'Employee'

The parser ignores the identifiers (e and it) and uses automatically the last lambda that was declared, which leads to an error when trying to access the Company object inside the Employee lambda.

However, this behavior works as expected on a regular linq expression:

context.Companies.Where(c => c.Employees.Any(e => e.Salary < c.MinimumSalary));
@StefH
Copy link
Collaborator

StefH commented Sep 7, 2018

The code will not work at all?

You should use something like:

context.Companies.Where("Employees.Any(Salary < 1000)");
// or
context.Companies.Where("Employees.Any(Salary < @0)", 1000);

See also https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Any.cs#L36

@StefH
Copy link
Collaborator

StefH commented Oct 19, 2018

Closing. If you still have an issue. Comment here or open new.

@StefH StefH closed this as completed Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants