1

実行時に次のエラーが発生します。

例外の詳細: System.InvalidOperationException: 未処理のバインディング タイプ: ListBinding

  • Choice_A、_b、_C は文字列です
  • 「選択肢」はリスト

  var qs = (from questions in dc.Survey_Questions
                      where questions.Survey_ID == surveyid                     
                      select new SQuestions
                      {
                          QuestionID = questions.Question_ID,                          
                          Description = questions.Description,
                          Choice_A = questions.Choice_A,  
                          Choice_B = questions.Choice_B,  
                          Choice_C = questions.Choice_C,
                         **Choices =  {questions.Choice_A, questions.Choice_B,
          questions.Choice_C}**
   }).ToList();

基本的に、Choice_A、Choice_B、Choice_C の List Choices 値に割り当てる方法を知りたいです。前もって感謝します。

4

2 に答える 2

4

これを試すことができます。すでに次の 2 つのクラスがある場合

public class Question
{
    public int Question_ID { get; set; }
    public int Survey_ID { get; set; }

    public String Description { get; set; }
    public String Choice_A { get; set; }
    public String Choice_B { get; set; }
    public String Choice_C { get; set; }
}

public class SQuestions
{
    public int QuestionID { get; set; }
    public String Description { get; set; }
    public String Choice_A { get; set; }
    public String Choice_B { get; set; }
    public String Choice_C { get; set; }

    public List<String> Choices { get; set; }
}

次に、LINQクエリは次のようになります

var qs = (from question in dc.Survey_Questions
where question.Survey_ID == surveyid
select new SQuestions
{
   QuestionID = question.Question_ID,
   Description = question.Description,
   Choice_A = question.Choice_A,
   Choice_B = question.Choice_B,
   Choice_C = question.Choice_C,
   Choices = new List<string>(new String[] { question.Choice_A,question.Choice_B, question.Choice_C })
}).ToList();
于 2012-07-26T19:41:37.103 に答える
0

LINQ to Entities は、このバインド構文をサポートしていません。ただし、これを行うことができるはずです:

qs = (from questions in dc.Survey_Questions
                  where questions.Survey_ID == surveyid                     
                  select new SQuestions
                  {
                      QuestionID = questions.Question_ID,                          
                      Description = questions.Description,
                      Choice_A = questions.Choice_A,  
                      Choice_B = questions.Choice_B,  
                      Choice_C = questions.Choice_C,
                     Choices = new List<string> {questions.Choice_A, questions.Choice_B,
      questions.Choice_C}
}).ToList();
于 2012-07-26T19:10:49.123 に答える