我需要将此查询转换为 C# LINQ,但我不知道如何开始。感谢您的时间。
SELECT s.TextId, s.Title, s.CategoryId, s.Name, s.DateSent, Row
FROM
(SELECT t.TextId, t.Title, t.CategoryId, c.Name, t.DateSent,
ROW_NUMBER() OVER (PARTITION BY t.CategoryId ORDER BY t.datesent DESC) AS Row
FROM Concept_Text t
JOIN Concept_Text_Categories c
ON t.CategoryId = c.CategoryId
JOIN Concept_Text_CategoryToPlugin cp
ON c.CategoryId = cp.CategoryId
JOIN Concept_Text_Plugins p
ON cp.PluginId = p.PluginId
WHERE p.type = 12 AND (t.IsPublished = 'True') AND (Visible = 'True')
GROUP BY t.TextId, t.Title, t.CategoryId, c.Name, t.DateSent) s
WHERE Row <=12
在帮助下,到目前为止,我得到了这个
(from t in Concept_Text
join c in Concept_Text_Categories on t.CategoryId equals c.CategoryId
join cp in Concept_Text_CategoryToPlugin on c.CategoryId equals cp.CategoryID
join p in Concept_Text_Plugins on cp.PluginID equals p.PluginID
where p.Type == 12 && t.IsPublished && t.Visible
group cp by new { t.TextId, t.Title, t.CategoryId, c.Name, t.DateSent } into gr
orderby gr.Key.DateSent descending
select new
{
gr.Key.TextId,
gr.Key.Title,
gr.Key.CategoryId,
gr.Key.Name,
gr.Key.DateSent
})
现在唯一的问题是我们需要获得每个类别的 12 个条目。