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

Select Linq not working with more than one parameter #259

Closed
sachindevtomar opened this issue Oct 1, 2022 · 3 comments · Fixed by #260
Closed

Select Linq not working with more than one parameter #259

sachindevtomar opened this issue Oct 1, 2022 · 3 comments · Fixed by #260

Comments

@sachindevtomar
Copy link

Hello Team,

I want to use following expression but it is throwing error "UnknownIdentifierException 'visualCount' ". Following expression is fine fine when select linq has only single property i.e. pageName or visualCount.

var options = InterpreterOptions.Default | InterpreterOptions.LambdaExpressions; 
var interpreter = new Interpreter(options).SetVariable("courseList", courseList);

string expression = @"courseList.Select(x =>  new { pageName = x.PageName , visualCount = 5 })";

Lambda parsedExpression = interpreter.Parse(expression);
var result = parsedExpression.Invoke();

Note: I have tried every property, each time it worked for single property but not for multiple properties.

Please resolve this issue as I am currently blocked.

@davideicardi
Copy link
Member

Thank you @sachindevtomar for the bug report. This is a free and open source project, we cannot guarantee any kind of support, but any contribution and help is appreciated.

@metoule
Copy link
Contributor

metoule commented Oct 3, 2022

I'm surprised it even works with a single property, because anonymous types are not supported (see #75).
Can you share an example where it's working?

@metoule
Copy link
Contributor

metoule commented Oct 3, 2022

I managed to reproduce, and it's indeed a bug with the way we determine where the body of a lambda expression ends:

[Test]
public void Lambda_Issue_259()
{
	var options = InterpreterOptions.Default | InterpreterOptions.LambdaExpressions;
	var interpreter = new Interpreter(options);
	interpreter.SetVariable("courseList", new[] { new { PageName = "Test" } });
	interpreter.Reference(typeof(PageType));

	var results = interpreter.Eval<IEnumerable<PageType>>(@"courseList.Select(x => new PageType() { PageName = x.PageName, VisualCount = 5 })");
	Assert.AreEqual(1, results.Count());

	var result = results.Single();
	Assert.AreEqual("Test", result.PageName);
	Assert.AreEqual(5, result.VisualCount);
}

public class PageType
{
	public string PageName { get; set; }
	public int VisualCount { get; set; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants