如何选择持续时间作为实体框架中两个字段之间的差异。以下是相应的 SQL 查询:
SELECT InitiateTime, StartTime, EndTime, Ano,Bno, datediff(s,StartTime,EndTime) as duration
FROM [NEPALIVR2].[dbo].[CDR]
WHERE StartTime >= startDate and StartTime <= endDate order by StartTime desc
LINQ
from u in db.CDRs
where u.InitiateTime >= startDate && u.InitiateTime <= endDate
orderby u.InitiateTime descending
select new
{
InitiateTime = u.InitiateTime,
StartTime = u.StartTime,
EndTime = u.StartTime,
Ano = u.Ano,
Bno = u.Bno,
Duration = (SqlFunctions.DateDiff("mi", u.StartTime, u.EndTime))/360,
};
这将返回错误:
无法将类型隐式转换
'System.Linq.IQueryable<AnonymousType#1>'
为'System.Linq.IQueryable<IVRControlPanel.Models.CDR>'
. 存在显式转换(您是否缺少演员表?)