Entity Framework select one of each group by date

后端 未结 4 1173
暖寄归人
暖寄归人 2020-11-30 07:37

I have a table like this (Table name: Posts):

+----+--------------------------+-------+------------+
| id |         content          | type  |    date    |
+         


        
4条回答
  •  迷失自我
    2020-11-30 08:01

    If you want to get the whole Posts. You can try this:

    var query = Posts.GroupBy(p => p.Type)
                      .Select(g => g.OrderByDescending(p => p.Date)
                                    .FirstOrDefault()
                       )
    

提交回复
热议问题