结束我有这样一个xml:错误:查询体必须与SELECT子句或group子句
<countries>
<country ID="MX">
<idea ID="Valor1">nota1</idea>
<idea ID="Valor2">nota2</idea>
<idea ID="Valor3">nota3</idea>
<idea ID="Valor4">nota4</idea>
</country>
<country ID="US">
<idea ID="Valor1">nota1</idea>
<idea ID="Valor2">nota2</idea>
<idea ID="Valor3">nota3</idea>
<idea ID="Valor4">nota4</idea>
</country>
</countries>
使用LINQ到XML我怎么能得到特定类型的列表?我想是这样的:
我创建了一个类:
public class Ideas
{
public string Country { get; set; }
public List<ListItem> ListIdeas { get; set; }
}
然后我使用这个类做一个列表:
XDocument xdoc = XDocument.Load(this.Server.MapPath("~/config/ideas.xml"));
var cat = from p in xdoc.Descendants("countries")
.Elements("country")
.Select(m => new Ideas
{
Country = m.Attribute("ID").Value,
ListIdeas = m.Elements("idea")
.Select(c =>
new ListItem
{
Text = c.Attribute("ID").Value ,
Value = c.Value
}).ToList()
});
,但我得到了一个错误:
A query body must end with a select clause or a group clause
The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
国际海事组织,一个好的答案应该使用查询语法或扩展方法的语法,他们中的一个,而不是一个组合。 – abatishchev