如何为DbFunctions.DiffMinutes使用group by函数

时间:2016-04-18 07:27:15

标签: linq

我有这个Linq查询。我想一起显示ab.InTime和DbFunctions值

var sdv = (from ab in db.Attendances
                       where ab.Employee == 63 && ab.InTime.Value.Year == 2015 && ab.InTime.Value.Month == 8
                       select ab.InTime,DbFunctions.DiffMinutes(ab.InTime, ab.OutTime) / 60);

1 个答案:

答案 0 :(得分:1)

也许,您可以使用select new{...}。请试试这个:

var sdv = (from ab in db.Attendances
           where ab.Employee == 63 && ab.InTime.Value.Year == 2015 && ab.InTime.Value.Month == 8
           select new{
                      InTime=ab.InTime,
                      Minutes=DbFunctions.DiffMinutes(ab.InTime, ab.OutTime) / 60)
                     };