score:2

Accepted answer

Use ToList() before GroupBy and it will work as expected.

fileMovementRepository.GetAll()
                .Where(fm => repository.GetAll().Select(f => f.Id).Contains(fm.FileId) && fm.TransferredById == userId)
                .Include(f => f.User).Include(f => f.File).ThenInclude(f => f.Category)
                .OrderByDescending(f => f.MovedOn)
                .ToList()
                .GroupBy(f => f.FileId)
                .Select(f=>f.First())
                .ToList();

Related Articles