How do I write the following query in Linq:
SELECT s.displayname AS Skill,
CASE
WHEN us.skillid IS NULL THEN '0'
ELSE '1'
END AS HasSkill
FROM skills s
LEFT JOIN userskills us
ON s.id = us.skillid
I've been at it for a couple of hours and I genuinely cannot get my head around the structure of these queries. They seem overwhelming and too complicated for what the plain SQL query otherwise seems to be doing for me.
var skills = _context.Skills.ToList();
var userSkills = _context.UserSkills.ToList();
var result = skills.GroupJoin(userSkill, skill => skill.ID, skill => userSkill , (userSkill, skill) => new {
Key = userSkill,
Skills = skill
});