Getting rid of entries in a list where one value is a duplicate of another

Viewed 26

I have this function that queries the database to get all the boards (inner list) and adds it to that entry in the list of logs (outer list). This works fine but i'm wondering if there is a way to eliminate entries in the inner list that have the same board.XcpLE value or not add the board with a duplicate board.XcpLE. LogBoard and LogBoardArchive are both tables in my database

Query function:

        private async Task<List<List<Board>>> QueryPatternsAsync<T>(IQueryable<T> query)
        {
            return query switch
            {
                IQueryable<LogBoard> q => await q.GroupBy(board => board.BoardsResultID)
                                                .Select(boards => boards.Select(board => 
                                                                            new Board(board.BoardType, 
                                                                            (int)(board.NomThickness / 25.4 / 1000), 
                                                                            (int)(board.NomWidth / 25.4 / 1000), 
                                                                            board.XcpLE, board.GreenWidth, 
                                                                            board.GreenThickness, 
                                                                            board.BoardsResultID))
                                                                        .ToList())
                                                .ToListAsync(),
                IQueryable<LogBoardArchive> q => await q.GroupBy(board => board.BoardsResultArchiveID)
                                                        .Select(boards => boards.Select(board => 
                                                                                    new Board(board.BoardType, 
                                                                                    (int)(board.NomThickness / 25.4 / 1000), 
                                                                                    (int)(board.NomWidth / 25.4 / 1000), 
                                                                                    board.XcpLE, 
                                                                                    board.GreenWidth, 
                                                                                    board.GreenThickness, 
                                                                                    board.BoardsResultArchiveID))
                                                                                .ToList())
                                                        .ToListAsync(),
                _ => new List<List<Board>>()
            };
        }

How i'm currently removing them:

        private async Task<List<List<Board>>> RemoveDuplicatesAsync(List<List<Board>> logs)
        {
            for (int i = 0; i < logs.Count; i++)
            { 
                var reduced = logs[i].DistinctBy(b => b.XcpLE)
                                    .ToList();
                logs[i] = reduced;
            }

            return logs;  
        }
0 Answers
Related