我得到了一个taf SQL查询,应该使用最新的postgres提供程序在最新版本的entity-framework core(dotnet core 2)中运行:
SELECT
date_trunc('day', "StartTime") AS DAY
, sum("AnswerTime" - "StartTime")
, count("AnswerTime" != "ReleaseTime")
FROM "Cdrs"
GROUP BY DAY
ORDER BY DAY;
我部分可以解决它,但我无法完成整个查询。主要是计算值的总和我不知道如何解决。
还算一个条件,不知道如何在EF核心
我试图用这样的linq来解决它(不确定这是否会起作用):
[SuppressMessageAttribute("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "dateValue")]
[DbFunctionAttribute("date_trunc")]
public extern static DateTimeOffset? date_trunc(string what, DateTimeOffset? dateValue);
var x = (from c in ef.Cdrs
group c by date_trunc("day", c.StartTime) into day
//group c by (c.AnswerTime - c.StartTime) into g
select new { day.Count( })
任何提示如何将SQL上面带入实体框架核心(dotnet 2)是值得赞赏的。
尝试类似的东西;
var query = ef.Cdrs
.GroupBy(x => new { Day = date_trunc("d", x.StartTime) })
.Select(x => new
{
Day = x.Key.Day,
Sum = x.Sum(s => s.AnswerTime - s.StartTime),
Count = x.Count(c => c.AnswerTime != c.ReleaseTime)
});