Ingimar Andresson
Ingimar Andresson

Reputation: 1945

How to select category 1 and 6 in LINQ

I need to select 2 different categories from same table using EF with LINQ in C#

Like:

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

this works if I do use != to filer these categories from another list selected from the same table..just not able to select only these two categories. Can anybody help??

Upvotes: 1

Views: 49

Answers (1)

MarcinJuraszek
MarcinJuraszek

Reputation: 125650

There is no way for a category to have ID == 1 AND ID == 6 at the same time. Use OR instead:

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

Upvotes: 3

Related Questions