I need to select random questions per category
private int[] categoryId = {1, 2, 3, 4, 5, ...};
private int[] questionsPerCategory = {3, 1, 6, 11, 7, ...};
Before linq i achieved it by using
SELECT TOP (@questionsPerCategory) * From Questions WHERE CategoriesID = @categoryId AND
InTest ='1' ORDER BY NEWID()
Which also was not correct, since i had to call this for every categoryId.
How can i have the desired results with linq in a single query? All i need is fetch
- 3 random questions, with categoryId = 1 and InTest = true,
- 1 random question, with categoryId = 2 and InTest = true,
- 6 random questions, with categoryId = 3 and InTest = true
and so on..