我正在尝试在实体框架中使用 DateDiff:
var data = (from e in _context.Employers
join t in _context.Tickets on e.Id equals t.IdEmployer
join i in _context.InfoClients on t.IdConnexion equals i.Id
where t.Etat == "Encours"
select new
{
t.DateCreation,
t.NumTicket,
i.IdConnexion,
datediff = DateTime.Now.Subtract((DateTime)t.DateCreation).TotalDays,
t.SujetPrblm,
t.IdTicket,
e.Nom,
e.Prenom
}).ToList();
但我收到了这个错误:
此函数只能从 linq 调用到实体
我也试过这个但得到同样的错误:
DateDiff = SqlFunction.DateDiff("Hour", t.DateCreation, DateTime.Now)