I have these structures: Ticket has a lot of CustomFormFieldItemsInTicket. The relationship is one to many.
And I want to create linq which group ticket by CustomFormFieldItemsInTicket but I want to set which items from the collection will be used.
In sql it is something like this:
SELECT COUNT(*)
FROM [beta4].[dbo].[Tickets] as t
INNER JOIN [beta4].[dbo].[CustomFormFieldsInTickets] as cfit
ON cfit.TicketId = t.Id
WHERE cfit.CustomFormFieldId = 5 // I set the value
GROUP by cfit.SelectedCustomFormFieldItemId
I tried something like this. But did not work for me.
query.GroupBy(gr => gr.ticket.CustomFormFieldsInTicket.Where(wh => wh.CustomFormFieldId == 5).Select(sl => sl.SelectedCustomFormFieldItemId));