作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试选择论坛类别和每个类别中的最后一篇文章。我已经能够使用 OUTER APPLY 在 SQL 中完成此操作,但无法成功将其转换为 LINQ。
在 SQL 中产生所需的结果:
SELECT fc.CategoryID, fc.CategoryName, fc.PostCount, ft.Title, ft.LastPost, ft.LastPostId, ft.TopicId
FROM ForumCategory AS fc
OUTER APPLY
(
SELECT TOP (1) *
FROM ForumTopic
WHERE ForumTopic.CategoryID = fc.CategoryID
ORDER BY ForumTopic.lastpost DESC
) ft
Dim query = From fc In ctx.ForumCategories _
Join ft In ctx.ForumTopics On fc.CategoryID Equals ft.CategoryID _
Select New With {
fc.CategoryID,
fc.CategoryName,
fc.PostCount,
ft.Title,
ft.LastPostId,
ft.LastPost.OrderByDescending().First()
}
最佳答案
你写成这样:
var q = from fc in ctx.ForumCategories
from ft in (from x in ctx.ForumTopic
where x.CategoryID == fc.CategoryID
order by x.lastpost desc
select new
{
x.Title,
x.LastPost,
x.LastPostId,
x.TopicId
}).Take(1).DefaultIfEmpty()
select new
{
fc.CategoryID,
fc.CategoryName,
fc.PostCount,
ft.Title,
ft.LastPost,
ft.LastPostId,
ft.TopicId
};
关于sql - Linq to sql - 加入 2 个表,从右表中选择 1 行,具有 1 对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16040805/
目前我正在使用 [self presentModalViewController :newVC animated:YES] 。我想从左/右/顶部/底部呈现带有推送效果的 newViewcontroll
我正在尝试实现“带有上一个和下一个的部分幻灯片”。这些部分的标记如下: Section 1 Section 2 Section 3 Prev Next 除具有 acti
我的问题与此处提出的问题几乎相同:question 不同的是,我想从右边切换第 2 位和第 4 位数字,而不是像另一个问题中那样从左边切换。所以在我的例子中最右边的数字是 1。示例:283926.67
我是一名优秀的程序员,十分优秀!