gpt4 book ai didi

c# - LINQ 子查询、分组依据和计数

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:13 28 4
gpt4 key购买 nike

我刚刚开始使用 LINQ 编写查询,这就是我对它不是很熟悉的原因。我的查询在 SQL 中运行良好,但我想在其 LINQ 表达式中替换它。

SELECT DISTINCT Libelle
FROM Question, Connaissance
WHERE Question.ID_Q = Connaissance.ID_Question and ID_Q = (SELECT ID_Question
FROM Connaissance
GROUP BY ID_Question
HAVING COUNT(ID_Reponse) >= ALL(SELECT COUNT(ID_Reponse)
FROM Connaissance
GROUP BY ID_Question))

(Libelle是Question表中Question的名称)

我试过类似的东西:

var question = from q in dc.Question
join a in dc.Connaissance on q.ID_Q equals a.ID_Question
group q by a.ID_Question into grp
where grp.Count() >= ???

问题是我不知道如何转换这部分:>= ALL(SELECT COUNT(ID_Reponse)。我试图在 Internet 上搜索类似的东西,但没有找到任何东西。

如果有人能帮助我,我将不胜感激......

最佳答案

这样可以吗?

var question =
from q in dc.Question
join a in dc.Connaissance on q.ID_Q equals a.ID_Question
group q by a.ID_Question into grp
where grp.Count() >= dc.Connaissance.Select(y => y.ID_response).Distinct().Count()

关于c# - LINQ 子查询、分组依据和计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42315508/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com