I have a structure like that:
public class Tag
{
public int TagId { get; set; }
public virtual ICollection<Vacancy> Vacancies { get; set; }
// ...
}
public class Vacancy
{
public int VacancyId { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
// ...
}
These entities are mapped to MS SQL with EF / Code First approach.
After that I fetch somehow from the context (based on user query) a list of tags:
List<Tag> userSelectedTags = ...;
And I want to select all the vacancies which contains all (!) of these tags, something like:
List<Vacancy> vacancies = context.Where(v => v.Tags.Intersect(userSelectedTags)).ToList();
But! The problem is that I may have huge amount of data. And AFAIK Intersect is not the best approach cos it will select all the tags for each vacancy, and then perform Intersect on 'em. I don't want to load SQL Server too much and I'm definitely can write pure sql query for that. But I wonder if LINQ can do it for me? Is there any more gentle way of doing that?