I have the following DB (simplified)
Image - ImageTag - Tag
ImageTag is a joining table to form the many to many relationship.
I want to make a method which returns all images which contain x tags, this is what I have started with:
public static IQueryable<Image> WithTags(this IQueryable<Image> qry, IEnumerable<Tag> tags)
{
return from i in qry //uhhhh
}
But as you can see, I am a little stumped!
I know how I would do it with normal SQL but I am a little stumped with the LINQ syntax for this, any ideas?
--
Edit
It should match any image having any of the tags
So for example, if in the "qry" variable, there is an image with tags 1,2,3.... if you pass in the tags variable 1 and 2, it will match
Similary, if you passed 1,2,4 - It should still match even though it doesnt have 4
If you passed 3 and 4, it would also match
Edit 2
If it could order the images returned by the number of matches, that would be amazing. So for instance if you passed in 3 tags and an image had all 3 tags, it would be higher up than an image which only matched 1