and i want to get the following result
this means that i need to put the list of job in the header with Linq / C# , can you guys help with it ? i hope that my question is clear :)
and i want to get the following result
this means that i need to put the list of job in the header with Linq / C# , can you guys help with it ? i hope that my question is clear :)
Acually you're looking for PIVOT
MS SQL function check this answer for example.
You can do it without PIVOT
like this:
SELECT
p.PersonName,
SUM(CASE WHEN j.IdJob IS NULL THEN 0 ELSE 1 END ) [IT],
SUM(CASE WHEN j1.IdJob IS NULL THEN 0 ELSE 1 END ) [Teacher],
SUM(CASE WHEN j2.IdJob IS NULL THEN 0 ELSE 1 END ) [Doctor]
FROM Person p
LEFT OUTER JOIN Job j ON j.IdJob = p.IdJob AND j.JobName = 'IT'
LEFT OUTER JOIN Job j1 ON j1.IdJob = p.IdJob AND j1.JobName = 'Teacher'
LEFT OUTER JOIN Job j2 ON j2.IdJob = p.IdJob AND j2.JobName = 'Doctor'
GROUP BY p.PersonName
Anyway there is no simple clear way to make PIVOT
table without enumerating all column names.