I seem to be having trouble with this. I have a Task table with an ID, and a Tag table, that has a tag field and a foreign key constraint to the task table.
I want to be able to perform AND searches for tasks by tags. So for example, if I search for tasks with the tags "portability" and "testing", I don't want tasks that are tagged with "portability" and not "testing".
I tried the following syntax:
var tasks = (from t in _context.KnowledgeBaseTasks
where t.KnowledgeBaseTaskTags.Any(x => tags.Contains(x.tag))
select KnowledgeBaseTaskViewModel.ConvertFromEntity(t)
).ToList();
This of course does an OR search, not an AND search. I can't figure out how to actually switch this to be an AND search.
Edit I also need to be able to search for 2 out of X tags that a task contains. So if the task is tagged with "bugfix", "portability", "testing" and I search for "testing" and "portability", that task will still show up.