Looking for a bit of advice on grouping with entity framework and linq.
So i have a table "tbl_ChatLog" that contains userID and sendToUserID etc...and with this data i'm trying to display the "Top 1" from each "SendToUserID"
So in my UI it would look like so:
- 1001 (Contains multiple but show the top 1)
- 1003 (Contains multiple but show the top 1)
- 1008 (Contains multiple but show the top 1)
- 1009 (Contains multiple but show the top 1)
The start of my code below:
public static List<Chat> getChatMessage()
{
var entities = new FreeEntities();
//My ID
Business.User user = Business.User.getUserBySecurityToken();
List<Chat> chatMessages =
(
from cm in entities.tbl_ChatLog
where cm.UserID == user.uid
select new Chat
{
uid = (int)cm.UserID,
sendToUserID = (int)cm.SendToUserID,
message = cm.Message, dateAdded = (DateTime)cm.DateAdded
}
).OrderByDescending(x => x.dateAdded).ToList();
return chatMessages;
}
Hoping you can help me out on this one. Grouping always seems to throw me.
Much appreciated,
Terry