Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used LinqPad, which uses Linq-to-SQL instead of Linq to Entities, but the concepts should be the same.</p> <p>First, the data I used to test.</p> <pre><code>create table People (PersonID int, Name varchar(100)) create table Skills (SkillID int, Skill varchar(100)) create table PeopleSkills (PeopleSkillsID int, PersonID int, SkillID int) insert People values (1,'Bert'),(2,'Bob'),(3,'Phil'),(4,'Janet') insert Skills values (1,'C#'),(2,'Linq'),(3,'SQL') insert PeopleSkills values (1,1,1),(2,1,2),(3,1,3),(4,2,1),(5,2,3),(6,3,2),(7,3,3),(8,4,1),(9,4,2),(10,4,3) </code></pre> <p>And the solution.</p> <pre><code>//I don't know how you are specifying your list of skills; for explanatory purposes //I just generate a list. So, our test skill set is C#, Linq, and SQL. //int? is used because of LinqToSQL complains about converting int? to int var skills = new List&lt;int?&gt;(){1,2,3}; //This initial query is also a small bow to LinqToSQL; Really I just wanted a plain //List so that the Except and Any clauses can be used in the final query. //LinqToSQL can apparently only use Contains; that may or may not be an issue with //LinqToEntities. Also, its not a bad idea to filter the people we need to look at //in case there are a large number anyway. var peopleOfInterest = PeopleSkills.Where( p =&gt; skills.Contains(p.SkillID)).ToList(); //Final query is relatively simple, using the !x.Except(y).Any() method to //determine if one list is a subset of another or not. var peopleWithAllSkills = //Get a distinct list of people from person in peopleOfInterest.Select( p=&gt;p.PersonID).Distinct() //determine what skills they have let personSkills = peopleOfInterest.Where(x=&gt;x.PersonID == person).Select(x=&gt;x.SkillID) //check to see if any of the skills we are looking for are not skills they have where !skills.Except(personSkills).Any() select person; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload