Does anyone know how to create queryable collections in VB without using LINQ? I am working on creating a dynamic questionnaire system and need some help. Here's some background:
The system needs to support parent/child questionnaires. I have the database model created, as well as a query that returns all the questions for a group of questionnaires, sorted and grouped, first by the questionnaire sort order, and then by the question sort order.
Example:
[B]questionid, questionName, questionType, questionOrder, questionnaireOrder, questionnaireid[/B]
1, Favorite Color, Dropdown, 100, 100, 3
2, Zip Code, TextBox, 200, 100, 3
3, Email, TextBox, 100, 200, 4
I have a question class, with a collection of answers. The questionnaire class has a collection of the questions.
On the output control, I want to be able to loop through the child questionnaires, and then query the collection to get only the questions associated with the current child questionnaire.
I know this can be done with LINQ, but my company is still on VB8, so I don't have that as an option.
Here's what I am doing now:
'Get the questions from the questionnaire
Dim dsQuestions As New AppName.BLL.Questionnaires.QuestionCollection
'If this questionnaire is a parent of other questionnaires, get the ParentChildQuestions Collection
If Me.ParentChildQuestions.Count > 0 Then
dsQuestions = Me.ParentChildQuestions
Else
dsQuestions = Me.Questions
End If
'Loop through the questions
For Each q As AppName.BLL.Questionnaires.Question In dsQuestions
'If this is a parent/child questionnaire, and this is a new section, create the section header
If Me.ParentChildQuestions.Count > 0 And (Not q.Questionnaireid = questionnaireid) Then
CreateChildQuestionnaireElement(...)
End If
'Update the questionnaireid variable
questionnaireid = q.Questionnaireid
'Do a whole bunch of crap to output the questions
Next
I don't really like this method because it's too many steps and just seems inefficient.
What I would like to do is something like this:
Dim dsChildren As New AppName.BLL.Questionnaire.ChildCollection
dsChildren = questionnaireDataService.GetChildren(_Questionnaireid)
For Each child As AppName.BLL.Questionnaire.Child In dsChildren
CreateChildQuestionnaireElement(...)
'Query questions collection to get the questions for this specific child
Next