I have a program where there is a topic (like a forum), people can react to that topic.
USER:
TOPIC:
REACTION:
Code:
List<USER> ListOfAllUsers = new List<USER>();
var AllReactions = from r in db.REACTIONs
where r.topic_id == _topic_id
select r;
foreach (var itemX in AllReactions)
{
ListOfAllUsers.Add(itemX.USER);
}
//Distinct the list of duplicates
var ListOfUsers = ListOfAllUsers.Distinct().ToList();
Now, the "distinct" list still has some duplicates, how do I distinct the list based on the user id's? Or maybe there is another better way to do this. Thanks in advance.
You can use GroupBy to achieve that
var ListOfUsers = ListOfAllUsers.GroupBy(x => x.Id)
.Select(g => g.First())
.ToList();