【发布时间】:2014-08-05 18:03:22
【问题描述】:
由于Cannot convert lambda expression to delegate type,我无法获取答案属性。这些是我的课程和我的查询:
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; }
}
我的 XML 如下所示:
<?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>
如何获取答案的属性?
【问题讨论】:
标签: c# xml linq linq-to-xml