我想选择有关其代码的产品。我将标签列表传递给方法。每个产品可以有一个或多个标签,每个标签可以应用于一个或多个产品。
我无法在LINQ中进行翻译,但在SQL中,查询将是:
SELECT *
FROM products, tagproducts, tags
where products.productId = tagproducts.Product_productId
and tagproducts.Tag_tagId = tags.tagId
and tags.tagId IN (1,2);
我想我必须使用加入,但无法找到获得我想要的方法..任何想法?
答案 0 :(得分:0)
var tagIDs = new List<int> { 1, 2 };
var products = Products.Where(x => x.TagProducts.Any(y => tagIDs.Contains(y.TagID )));
//to get info from the products, . into them
var tagNames = products.TagProducts.Select(x => x.Tags.TagName); //or whatever.