LinQ, GroupBy, C#

Markus Freitag 3,786 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)
            {
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,346 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,667 questions
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,611 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