使用 Linq-to-SQL 分组后从多个表中获取结果
我认为答案应该很简单,但我只是在挣扎:
想要在 LINQ 查询中获取来自 2 个表的数据,类似于:
from f in Faults
join af in AvailabilityFaults on f.FaultID equals af.FaultID
join a in Availabilities on new { af.CalendarDay, af.CircuitNumber}
equals new { a.CalendarDay, a.CircuitNumber}
join e in ExternalImportAvailabilities on new { a.CalendarDay, a.CircuitNumber }
equals new { e.CalendarDay, e.CircuitNumber }
where a.CalendarDay.Value.Day != 1
group f by f.FaultID into groupF
select new {groupF, e.CalendarDay}
这里的问题在于它找不到 e.CalendarDay
在选择子句中。
我还尝试过类似的方法: CalendarDay= e.Max(e=>e.CalendarDay)
,但 e 不在当前上下文中。
如何在 select 子句中添加表“e”中的数据?
I think the answer should be easy, but I'm just struggling:
Would like to have data from 2 tables in a LINQ query similar to:
from f in Faults
join af in AvailabilityFaults on f.FaultID equals af.FaultID
join a in Availabilities on new { af.CalendarDay, af.CircuitNumber}
equals new { a.CalendarDay, a.CircuitNumber}
join e in ExternalImportAvailabilities on new { a.CalendarDay, a.CircuitNumber }
equals new { e.CalendarDay, e.CircuitNumber }
where a.CalendarDay.Value.Day != 1
group f by f.FaultID into groupF
select new {groupF, e.CalendarDay}
The problem here comes in that it can't find e.CalendarDay
in the select clause.
I also tried things like: CalendarDay= e.Max(e=>e.CalendarDay)
, but e is not in the current context.
How can I add data from table 'e' in the select clause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的话,这就是你正在寻找的:
If I understood you properly, this is what you are looking for:
如果您希望 e.CalendarDay 出现在您的选择中,那么您通常会将其包含在组中,如下所示
If you want e.CalendarDay in your select, then you normally would include it in the group, as in