我有一条如下的选择语句。
SELECT Doc_Id term
FROM [Inverted_Index]
我如何使用实体框架和linq做类似以下语句的操作?
select max(count(term))
from inverted_index
where doc_id = Given_doc_id
group by doc_id, term
Given_doc_id:已知并由应用程序传递。
我试图通过创建以下视图并选择max(freq)作为解决方法来解决此问题
CREATE VIEW [dbo].[Terms_Freq_Per_Doc]
AS (SELECT Doc_Id, term, count(term) freq
FROM [Inverted_Index]
group by Doc_Id, term);
...但是也没有成功,因为我无法将视图添加到实体图.edmx,因为将视图添加到.edmx的限制
请帮助解决这个问题,如何获得max(count(term))?
先感谢您。
希望下面的代码可以为您提供帮助:
int maxTerm = (from o in db.Inverted_Index
where o.Doc_Id == Given_doc_id
group o by new { o.Doc_Id, o.term } into g
select g).Max(p => p.Select(o => o.term).Count());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句