复杂的 LINQ SelectMany
我有很多桌子需要加入。表 x、b、c 正常连接,我将其称为 J1。 表 x,d 是另一个普通连接,我称之为 J2。
现在我需要将 J1 和 J2 连接在一起。对于 J1 中的每一行,J2 中可能有多个相关行。表 x 除其他条件外还有一个日期字段(很容易设置并且位于组连接中),但我需要获取最新/最高的 J2 行。表 x 有一个日期字段,基本上对于 J1 中的每一行,我可以在 J2 中拥有多行,并且我需要获取最新的一行。
我已经做好了 J1 的连接。 J2 的联接也已就位,作为 J1 上的 GroupJoin 中的第一个元素。
我完全迷失了两个问题:
有一次我需要按日期过滤掉。 J1*xx 条目必须晚于 比 J1 的(可能有更旧的)。
Select Many 需要采用最新的一个,这会涉及一些排序,但我还没有成功添加排序。我把它放在哪里?我有 GroupJoin,然后是 SelectMany。我应该把 OrderBy 放在哪里?
注意我需要 lambda 语法;我无法将其重写为另一种形式。
感谢帮助
I have a number of tables I need to join. Tables x,b,c join normally and I'll call that J1.
Tables x,d are another normal join that I call J2.
Now I need to join J1 and J2 together. For every row in J1 there may be multiple related rows in J2. Table x has a date field among other conditions (which are easy to set up and are in the group join), but I need to get the latest/highest J2 row. Table x has a date field, and basically for every row in J1 I can have multiple rows in J2, and I need to get the most recent one.
I have the joins for J1 in place. The join for J2 is also in place, as first element in a GroupJoin on J1.
Where I am totally lost are two issues:
At one point I need to filter out by date. J1*x x entry must be later
than J1's (there can be older ones).The Select Many needs to take the most recent one, which would implicate some ordering, but I have not been successful at adding a sort. Where do I put that in? I have the GroupJoin, followed by the SelectMany. Where do I put in the OrderBy?
Note I require lambda syntax; I can not rewrite it to another form.
Help is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
条件:
1) J1(单行)(x,b,c) = J2(多行)(x,d)
2) J2.x 具有用于订购的日期字段
3) J2.x 条目必须晚于 J1.x
4) J2.x 按日期过滤掉
(如果正确)
Conditions:
1) J1 (Single line)(x,b,c) = J2 (Multiple line) (x,d)
2) J2.x has datefield for ordering
3) J2.x entry must be later than J1.x
4) J2.x filter out by date
if its correct