I built a code that seems a bit cumbersome to me and I believe it can be optimized in linq
I have a table of all the users who liked the article- At first I did a search of all the likes of the article, I then made a loop that checks the user id and added it to a new list.
Users cUser = new Users ();
List <Users> allUsers = new List <Users> ();
List <Likes> allLikes = await _context.Likes.Where (x => x.AfazaId == id) .ToListAsync ();
foreach (Likes item in allLikes)
{
cUser = await _context.User.Where (x => x.Id == item.Id).FirstOrDefaultAsync ();
allUsers.Add (cUser);
}
Although it works, but I think it is possible to shorten the code .. Anyone have any advice?