Convert SQL into Linq query

前端 未结 2 1171
清歌不尽
清歌不尽 2021-01-21 06:31

I\'m quite new at Linq queries, I just want to convert my DB query into Linq.

Here is my simple SQL query:

var query = \"SELECT EnrollmentDate, COUNT(*)          


        
相关标签:
2条回答
  • 2021-01-21 06:48
    var result = db.Person
                   .Where(r=> r.EnrollmentDate != null)
                   .GroupBy(r=> r.EnrollmentDate)
                   .Select( group=> new 
                                  {
                                     EnrollmentDate = group.Key, 
                                     Count = group.Count()
                                   });
    
    0 讨论(0)
  • 2021-01-21 06:57
    var query = from row in db.Person
                where row.EnrollmentDate != null
                group row by row.EnrollmentDate into grp
                select new {
                    EnrollmentDate = grp.Key,
                    Count = grp.Count()
                };
    
    0 讨论(0)
提交回复
热议问题