选择EFCore SUM和ROUND

时间:2019-11-10 15:52:45

标签: c# ef-core-2.2 ef-core-3.0

我有这个查询

SELECT 
    ROUND(SUM(u.position / f.duration) / COUNT(DISTINCT c.id)) as seenRate
FROM Parent c
LEFT JOIN seen_content u ON u.parent_id = c.id
LEFT JOIN files f ON f.id = u.file_id
WHERE 
    u.date_update - u.date_activate >= u.position AND
    u.position >= f.duration * 0.9
GROUP BY c.id 

到目前为止,提出了这个查询

from c in dataContext.Set<ParentEntity>()
from u in dataContext.Set<SeenContentEntity>().Where(u => u.ParentId == c.Id)
from f in dataContext.Set<FileEntity>().Where(f => u.FileId == f.Id)
where
    EF.Functions.DateDiffMinute(u.DateUpdate, u.DateActivate) > u.Position &&
    u.Position >= f.Duration * 0.9
select new
{
    c,
    u,
    f
}

但是,我正在努力使用ROUNDSUM进行选择。我想避免子查询,最后查询应该至少与原始查询类似。

0 个答案:

没有答案