Last active
December 18, 2015 16:29
-
-
Save hoganlong/5811644 to your computer and use it in GitHub Desktop.
Full source solution for http://stackoverflow.com/questions/17180657/linq-to-entity-for-table-by-parametrs-in-dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test load full file in LinqPad, set to program and hit the run button.