I have a message table like this:
Id Message Column1
--------------------------
1 asdasdd 1
2 dsfsfsf 1
3 safsafs 2
4 afewfff 3
5 adw qwd 2
I want to get last records of every distinct value on Column1, which means rows 2,4 and 5 via this code:
Messages.OrderByDescending(a => a.Id).GroupBy(a => a.Column1).Select(a => a.Key).ToList();
I only needs ids of rows, but nothing returns. I've done it with sql, but couldn't convert to EF lambda.
select max(Id) as Id from [Messages]
group by Column1
order by Id DESC