This is a migrated thread and some comments may be shown as answers.

Linq Conversion Failure

0 Answers 43 Views
Code Converter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard
Top achievements
Rank 1
Richard asked on 07 Jun 2012, 01:34 PM
The following VB function does not convert to C#
Private
Function GetQuestions(orgId As Integer, personId As Integer) As IEnumerable(Of Question)
    Dim ds As DataSet = GetActualDataSet(orgId, personId)
    Dim dtQuestions As DataTable = ds.Tables("Questions")
    Dim dtAnswers As DataTable = ds.Tables("Answers")
    Dim childQuestions As DataTable = ds.Tables("AnswerChildQuestions")
    'Build all the questions
    Dim questions As IEnumerable(Of Question) =
        (From q In dtQuestions
         Group Join a In dtAnswers On q.Field(Of Integer)("question_type_id") Equals a.Field(Of Integer)("question_type_id") Into Group
         Select New Question With {.Id = q.Field(Of Integer)("question_type_id"),
                                   .SeqNum = q.Field(Of Integer)("sequence_no"),
                                   .IsChild = q.Field(Of Boolean)("isChildQuestion"),
                                   .EktronContentKey = q.Field(Of String)("ektron_content_key"),
                                   .Text = q.Field(Of String)("description"),
                                   .QuestionKindId = q.Field(Of Integer)("question_kind_type_id"),
                                   .Answers = (From a2 In Group
                                               Select New Answer With {.Id = a2.Field(Of Integer)("answer_type_id"),
                                                                       .SequenceNum = a2.Field(Of Integer)("sequence_no"),
                                                                       .EktronContentKey = a2.Field(Of String)("ektron_content_key"),
                                                                       .Text = a2.Field(Of String)("description"),
                                                                       .IsSelected = a2.Field(Of Boolean)("isSelected"),
                                                                       .ImageKey = If(q.Field(Of Integer)("question_type_id") = 2, "", If(.Id Mod 2 = 0, "heating-gas-modern.png", "heating-gas-condensing.png")),
                                                                       .ChildQuestionIds =
                                                                          (From r In childQuestions
                                                                           Where r.Field(Of Integer)("answer_type_id") = .Id
                                                                           Select r.Field(Of Integer)("question_type_id")).ToArray}).ToArray,
                                   .SelectedAnswerId = If(.QuestionKindId = 1,
                                                          (From a3 As Answer In .Answers
                                                           Where a3.IsSelected = True
                                                           Select a3.id ).singleOrdefault,
                                                          0),
                                   .SelectedAnswerIds =If(.QuestionKindId = 2,
                                                          (From a4 As Answer In .Answers
                                                           Where a4.IsSelected = True
                                                           Select a4.id).toArray,{})
                                  }
         )
    Return questions
End Function
Tags
Code Converter
Asked by
Richard
Top achievements
Rank 1
Share this question
or