我需要在C#
中使用EF和LINQ从同一个表中选择2个不同的类别喜欢:
_tour.Products.Where(na => na.ProductCategory.ProductCategoryID == 1 && na.ProductCategory.ProductCategoryID == 6);
如果我使用!=来从同一个表中选择的另一个列表中提取这些类别,这是有效的。不能只选择这两个类别。任何人都可以帮忙吗?
答案 0 :(得分:3)
某个类别无法同时拥有ID == 1
AND ID == 6
。改为使用 OR :
_tour.Products.Where(na => na.ProductCategory.ProductCategoryID == 1 || na.ProductCategory.ProductCategoryID == 6);