Skip to content

Instantly share code, notes, and snippets.

@hoganlong
Last active December 18, 2015 16:29
Show Gist options
  • Save hoganlong/5811644 to your computer and use it in GitHub Desktop.
Save hoganlong/5811644 to your computer and use it in GitHub Desktop.
void Main()
{
Dictionary<int,int> skillList = new Dictionary<int,int>();
skillList.Add(1,1);
skillList.Add(2,2);
skillList.Add(3,1);
skillList.Add(4,1);
DataTable userSkills = new DataTable();
userSkills.Columns.Add("UserSkillId", typeof(int));
userSkills.Columns.Add("UserId", typeof(int));
userSkills.Columns.Add("SkillId", typeof(int));
userSkills.Columns.Add("SkillLevelId", typeof(int));
userSkills.Rows.Add(1, 1, 1, 1);
userSkills.Rows.Add(2, 1, 2, 2);
userSkills.Rows.Add(3, 1, 3, 1);
userSkills.Rows.Add(4, 1, 4, 1);
userSkills.Rows.Add(5, 2, 1, 3);
userSkills.Rows.Add(6, 2, 2, 3);
userSkills.Rows.Add(7, 2, 3, 3);
userSkills.Rows.Add(8, 2, 4, 3);
userSkills.Rows.Add(9, 3, 1, 1);
userSkills.Rows.Add(10, 3, 2, 2);
userSkills.Rows.Add(11, 3, 3, 1);
userSkills.Rows.Add(12, 3, 4, 1);
var result = userSkills.AsEnumerable()
.GroupBy(userRow => userRow.Field<int>("UserId"))
.Where(userGroup => userGroup
.Join(skillList,
user => new { sID = user.Field<int>("SkillId"), slID = user.Field<int>("SkillLevelId") },
skill => new { sID = skill.Key, slID = skill.Value },
(user, skill) => true).Count() == skillList.Count())
.Select(match => new { userID = match.Key });
result.Dump();
}
@hoganlong
Copy link
Author

To test load full file in LinqPad, set to program and hit the run button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment