I\'m struggling a bit here so I thought why not ask:
Every entity in my system has a list of tags (a list of strings), and I want to be able to search for multiple t
From here, this is some sql that will work for you:
SELECT entityID
FROM tags
WHERE tagID in (...) --taglist
GROUP BY entityID
HAVING COUNT(DISTINCT tagID) = ... --tagcount
Now the trick is getting Linq to produce it... Here's some LinqToSql code:
public List GetEntityIds(List tagIds)
{
int tagCount = tagIds.Count;
CustomDataContext myDC = new CustomDataContext();
List entityIds = myDC.Tags
.Where(t => tagIds.Contains(t.TagId))
.GroupBy(t => t.entityId)
.Where(g => g.Select(t => t.TagId).Distinct().Count() == tagCount)
.Select(g => g.Key)
return entityIds;
}
A few caveats apply: