mihaifm / linq

linq.js - LINQ for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C# Linq: assigning variables during join

raiken-mf opened this issue · comments

The console returns unexpected "." on line 68 in linq.js if I use linq like this:

Enumerable.from(a).join(b, "l1 => l1.ArticleId", "l2 => l2.Id", "(l1, l2) => { l1.Article = l2; return l1; }").toArray();

To allow assigning variables during the join the line 68 in linq.js:

f = new Function(expr[1], "return " + expr[2]);

must be changed to this:

f = new Function(expr[1], (expr[2].includes("return") ? expr[2] : "return " + expr[2]));

The C# equivalent as follows:

a.Join(b,
l1 => l1.ArticleId, l2 => l2.Id, (l1, l2) =>
{
	l1.Article = l2;
	return l1;
}).ToArray();

This makes sense, thanks for the solution.