Reputation: 47
I'm getting this error at running time:
Exception Details: System.InvalidOperationException: Unhandled binding type: ListBinding
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();
Basically I'd like to know how I assign to List Choices values of Choice_A,Choice_B, Choice_C. Thanks in advance.
Upvotes: 1
Views: 407
Reputation: 3277
You can try this. If you already have the following two classes
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; }
}
Then the LINQ Query will be
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();
Upvotes: 4
Reputation: 156614
LINQ to Entities does not support this binding syntax. You should be able to do this, though:
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();
Upvotes: 0