I have the following 2 entitys in my db.
public class Article
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
// Some code removed for brevity
public virtual ICollection<Tag> Tags { get; set; }
}
public class Tag
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
// Some code removed for brevity
public virtual ICollection<Article> Articles { get; set; }
}
I need to filter these articles based on the tag IDs that are passed into my action.
public ActionResult FindAll(List<int> tags)
{
//
// I need to return all articles which have ALL the tags passed into this method
//
var query = ApplicationDbContext.Articles...
}
For example, if I passed in 1, 2, 3 into the action, only articles which had these 3 tags or more would be returned.
How can I achieve this?
Thanks for the great response!
All your answers produced the correct result so I did some quick, basic profiling in sql and this was the results based on your queries.