LinQ, GroupBy, C#

Markus Freitag 3,791 Reputation points
2020-11-25T15:04:27.063+00:00

Hello,
I have a Master Detail relationship.

Master 1:n Detail
1:n Detail (List)

Via LinQ I would like to group it.
That works too. But I can't reach the ResultView. See the green marker.
What should the query be called?

Thanks in advance for tipps and samples.

The code

   var qryPanelIndex = CurrentPanel.MainList[0].ListDetailBoards.GroupBy(info => info.PanelIndex)
                    .Select(group => new
                    {
                        PanelIndex = group.Key,
                        CountOccurrences = group.Count()
                    })
                    .OrderBy(x => x.PanelIndex).ToList();

            var qryPanelIndex2 = CurrentPanel.MainList[0].ListDetailBoards.GroupBy(info => info.PanelIndex).ToList();

            foreach(var item in qryPanelIndex2)
            {
Developer technologies Windows Presentation Foundation
Developer technologies .NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,651 Reputation points
    2020-11-26T05:50:55.39+00:00

    Hi Markus Freitag,
    >>I can't reach the ResultView
    According to my understanding, do you want to reach the value of ListPosition in resultView of qryPanelIndex.
    If so, you can add this line in the select statement.

    .Select(group => new  
                         {  
                             PanelIndex = group.Key,  
                             CountOccurrences = group.Count(),  
                              ListPosition=group.ToArray()  
                         })  
    

    If not, please explain in detail.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.