如何在LINQ中选择类别1和6

时间:2014-03-18 22:07:23

标签: linq entity-framework c#-4.0

我需要在C#

中使用EF和LINQ从同一个表中选择2个不同的类别

喜欢:

 _tour.Products.Where(na => na.ProductCategory.ProductCategoryID == 1 && na.ProductCategory.ProductCategoryID == 6);

如果我使用!=来从同一个表中选择的另一个列表中提取这些类别,这是有效的。不能只选择这两个类别。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

某个类别无法同时拥有ID == 1 AND ID == 6。改为使用 OR

 _tour.Products.Where(na => na.ProductCategory.ProductCategoryID == 1 || na.ProductCategory.ProductCategoryID == 6);