Entity Framework select one of each group by date

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

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

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


        
4条回答
  •  情话喂你
    2020-11-30 07:55

    I suppose you can group your Posts rows by type and then select first content from descending ordered by date collection of that type

    from row in Posts 
    group row by row.type 
    into g
    select new
    {       
        Content  = (from row2 in g orderby row2.date descending select row2.content).FirstOrDefault(),
        Type = g.Key
    }
    

提交回复
热议问题