简体   繁体   English

SQL查询到LINQ表达式

[英]SQL query to LINQ expression

How can I translate this SQL query to a LINQ expression? 如何将此SQL查询转换为LINQ表达式?

select NoteDate, SUM( DurationInHours ) from Note 
where IDUser = '2933FB9C-CC61-46DA-916D-57B0D5EF4803' and 
      NoteDate > '2013-07-01'
group by NoteDate

I tried it, but it didn't work 我试过了,但是没用

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)}
var id = new Guid("2933FB9C-CC61-46DA-916D-57B0D5EF4803");
var date = new DateTime(2013, 7, 1);

var query = from n in db.Notes
            where n.IDUser == id && n.NoteDate > date
            group n by n.NoteDate into g
            select new {
                NoteDate = g.Key,
                Sum = g.Sum(x => x.DurationInHours)
            };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM