Linq Conversion Failure

1 posts, 0 answers
  1. Richard
    Richard avatar
    1 posts
    Member since:
    Apr 2011

    Posted 07 Jun 2012 Link to this post

    The following VB function does not convert to C#
    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 ).singleOrdefault,
                                       .SelectedAnswerIds =If(.QuestionKindId = 2,
                                                              (From a4 As Answer In .Answers
                                                               Where a4.IsSelected = True
        Return questions
    End Function
Back to Top