gpt4 book ai didi

javascript - 将 linq 查询转换为 linqjs

转载 作者:行者123 更新时间:2023-11-28 05:53:17 26 4
gpt4 key购买 nike

一段时间以来我一直在尝试通过将一些旧的 Linq 查询转换为 LinqJs 查询来学习 LinQJS。

这是 Linq 查询。

(from y in class1
join x in class2 on y.Id equals x.Name
group y by new { y.Date, x.Number } into xy
select new class3()
{
}).ToList();

这是我目前的尝试(已被重写很多次)。我想我只是不太理解语法。

var example = Enumerable.from(this.class1)
.join(
this.class2,
"y => y.Id",
"x => x.Name",
" "
)
.groupBy("x.Date", "y.Number")
.select(xy= new Class3(), { })
.ToArray();

最佳答案

嗯,你可以做这样的事情

首先是连接部分。

var res = Enumerable.From(class1)
.Join(
class2,
"x => x.Id",
"y => y.Name",
//I flattened all to make things more readable, you could also choose (x, y) => {c1:x, c2:y} for example
"(x, y) => {dte:x.Date, id:x.Id, name:y.Name, nb:y.Number, val:y.val} "

).ToArray();

然后按部分分组(当然你可以全部完成)

        var res2 = Enumerable.From(res)
.GroupBy("p => {Date:p.dte, Number:p.nb}",
"p=> p",
//that's the "select" part, so put what you need in it
"(p, grouping) => {key: p, values: grouping.source}")
.ToArray();

然后您可以选择您需要的内容。

遗憾的是,似乎(或者我不知道如何做到这一点)由多个字段组成的组无法正常工作(它返回多个记录)。

虽然 .GroupBy("p => p.dte}", 按预期工作。

关于javascript - 将 linq 查询转换为 linqjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37921617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com