I can't obtain the answer attribute due to Cannot convert lambda expression to delegate type. These are my classes and my query :
var file = XDocument.Load("QuestionsTest.xml");
var questions = from answers in file.Root.Elements("Question").Elements("Answers").Elements("Answer")
select new Answer
{
Text = (string)answers,
Correct = (string)answers.Elements("Answer").Single(answer=>(string)answer.Attribute("Correct"))
};
public class Answer
{
public int AnswerID { get; set; }
public string Text { get; set; }
public string Correct { get; set; }
public int Stats { get; set; }
public int QuestionID { get; set; }
}
public class Question
{
public virtual List<Answer> Answers { get; set; }
}
My XML looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<Questions Subject="ADO.NET">
<Question NumberOfAnswers="1">
<Text>Which class should you use to manage multiple tables and relationships among them?</Text>
<Answers>
<Answer>DataRow</Answer>
<Answer>DataView</Answer>
<Answer>DataTable</Answer>
<Answer Correct="Yes">DataSet</Answer>
</Answers>
</Question>
</Questions>
How can I get the answer's attribute?