0

i want all products to be available under current category including all child categories. my code is something like this :

int[] toCheck =new int[2];

toCheck[0] = 1;
toCheck[1] = 2;
toCheck[2] = 3;

var products = db.Products.Include(x => x.categoryByProductID).Where(x => x.CategoryID in ?);

here categoryByProductID = all child categories, ? = how can i use toCheck[] array

or any other solution to check CategoryID with predefined values !!!

any help appreciable ...

0

2 Answers 2

1

You want to look at it slightly the other way up- does the list of categories contain the category of this product?

var products = db.Products.Include(x => x.categoryByProductID).Where(x => toCheck.Contains(x.CategoryID)); 
Sign up to request clarification or add additional context in comments.

1 Comment

Contains works in .NET 4.0 but not in 3.5 SP1 blogs.msdn.com/b/alexj/archive/2009/03/26/…
1
var products = db.Products.Include(x => x.categoryByProductID).Where(x => toCheck.Any(y => y == x.CategoryID));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.