获取按日期排序的不同列
我有以下两个表:
Job Title | PostDate | CompanyId
Assitant | 12/15/10 | 10
Manager | 12/1/10 | 11
Developer | 12/31/10 | 10
Assitant | 12/1/10 | 13
PM | 11/29/10 | 12
CompanyId | Name
10 | Google
11 | Yahoo
12 | Microsoft
13 | Oracle
现在我想要 3 家不同的公司,其职位按发布日期排序。结果表如下:
Job Title | PostDate | CompanyName
Developer | 12/31/10 | Google
Manager | 12/1/10 | Yahoo
Assitant | 12/1/10 | Oracle
如何使用 linq 查询实现这一点?任何帮助将不胜感激...
I have these following two tables:
Job Title | PostDate | CompanyId
Assitant | 12/15/10 | 10
Manager | 12/1/10 | 11
Developer | 12/31/10 | 10
Assitant | 12/1/10 | 13
PM | 11/29/10 | 12
CompanyId | Name
10 | Google
11 | Yahoo
12 | Microsoft
13 | Oracle
Now i would like to get 3 different companies with the jobs sorted by post date. The result table would be following:
Job Title | PostDate | CompanyName
Developer | 12/31/10 | Google
Manager | 12/1/10 | Yahoo
Assitant | 12/1/10 | Oracle
How can I achieve that using a linq query? Any help will be appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这会是这样的:
先进行连接然后再进行分组有点奇怪 - 我们可以先进行 GroupJoin,然后丢弃空选项:
编辑:请注意,这不仅仅需要前三名的结果。使用
query = query.Take(3);
仅获取前三个结果。I think that would be something like:
It's a little odd to do a join and then a group - we could do a GroupJoin instead, but then discard empty options:
EDIT: Note that doesn't just take the top three results. Use
query = query.Take(3);
to just get the first three results.