0
如何将此SQL查询转换为LINQ表达式?对LINQ表达式的SQL查询
select NoteDate, SUM(DurationInHours) from Note
where IDUser = '2933FB9C-CC61-46DA-916D-57B0D5EF4803' and
NoteDate > '2013-07-01'
group by NoteDate
我尝试过,但没有奏效
var lastMonth = DateTime.Today.AddMonths(-1);
var userNotes = GetNotesByUser(idUser);
var b = from note in userNotes
group note by new {note.IDUser, note.NoteDate, note.DurationInHours} into g
where g.Key.NoteDate > lastMonth
select new {g.Key.NoteDate, TotalHours = g.Sum(a => a.DurationInHours)}
那你试试? – algreat
这是学习LINQ查询的好地方。 http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b –
var lastMonth = DateTime.Today.AddMonths(-1); var userNotes = GetNotesByUser(idUser); VAR B =从音符在userNotes 组通过新的{note.IDUser,note.NoteDate,note.DurationInHours} 注入克 其中g.Key.NoteDate> lastMonth 选择新的{g.Key.NoteDate,TotalHours = g.Sum(a => a.DurationInHours)} 我试过了,但没有工作。我看到这个例子@CamBruce,但我有一些紧迫感。我用更多的时间研究它!谢谢。 – gog