score:3
Accepted answer
I'd use Any()
in the first case:
public IQueryable<Candidate> GetMatchingCandidates(Job job)
{
return from candidate in _db.Candidates
where (candidate.CandidateSkills.Any(c => job.JobPreferredSkills.Any(j => j.SkillId == c.SkillId)))
select candidate;
}
Then use All()
for your second case (all skills have to be in the preferred skills)
public IQueryable<Candidate> GetMatchingCandidates(Job job)
{
return from candidate in _db.Candidates
where (candidate.CandidateSkills.All(c => job.JobPreferredSkills.Any(j => j.SkillId == c.SkillId)))
select candidate;
}
Source: stackoverflow.com
Related Articles
- LINQ to SQL: How to check if any item in one entity collection exists in another entity collection?
- How can I check whether an item of an Entity's child collection exists in another collection with LINQ to Entities?
- Is it right a LINQ query to check whether atleast one entity exists in string collection with a matching criteria (rownum<=1)
- Using LINQ to select a list of every item in a collection, except if it exists in another collection
- Efficiently check if record exists in database using Entity framework LINQ
- Check if a value from one array exists in another array using linq
- Linq select where entity property value matches value of property of any item in another List
- Entity Framework LINQ Get all items part of another collection
- SharePoint 2010: Linq to Objects, Check if User is in another List and use of current Item
- LINQ check if a list contains any item from another list mysql syntax error
- Get the item from a collection that contains another collection using linq
- c# Linq - Check if composite key exists in another list
- Check if database entry exists Entity and Linq
- how to get a list of item in object from another table using linq and entity framework in C#?
- Linq code to select one item
- C# Linq to XML check if element exists
- Using LINQ to Objects to find items in one collection that do not match another
- Linq to update a collection with values from another collection?
- LINQ Query problem. Need to check if exists
- check whether a List<string> contains an element in another List<string> using LINQ
- How to add an item in a collection using Linq and C#
- LINQ to check if ID exists in List
- C# check an element exists while using LINQ to XML
- LINQ WHERE method alters source collection
- LINQ select List where sub-list contains item from another list
- Check if a value is in a collection with LINQ
- Change item in collection with LINQ
- Easiest way to check record is exist or not in Linq to Entity Query
- LINQ Query: Determining if object in one list exists in another based on key
- Best way to check if value exists for a key in ILookup<string, string> using linq
- Missing GetTable<TEntity>() in database context
- Linq Intersect bool query and performance
- How do I translate this Sql Statement to Linq
- SQLite DB: Create a SQL Statement with LINQ that uses the same table twice but without CROSS JOIN
- Which versions of SQL Server does LINQ to SQL support?
- Implementing method in a functional style
- How can I get a SUM of the items in my grouped query?
- C# LINQ translation for a SQL query with RIGHT JOIN
- Query to extract data based upon time stamp conditions
- How to find Row number of an object in a List
- How to iterate over grouped LINQ data in MVC view
- Accessing foreign keys through LINQ
- Combine linq queries together
- Linq c# sum any objects from list > int
- How do I create an Expression out of another Expression in C#?
- How to use Include to include an Entity not related to another entity
- Queryable variable cannot be found in the context
- Why can't I enumerate X509Store.Certificates
- How to pull a SQL Server table into memory in order to run queries against it
- How to filter with types of generic interfaces in Linq?