MVC中的Linq抱怨缺少引用

时间:2011-06-30 09:34:06

标签: linq asp.net-mvc-3 linq-to-xml

我正在尝试使用MVC3使用linq从XML文件中提取名称列表。

List<String> firstNames = (from p in x.Descendants("Row")
                           orderby p.Element("id").Value
                           select p.Element("firstName").Value).ToList(); 

编译器一直在抱怨:

Error   1   
   Could not find an implementation of the query pattern for 
   source type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>'.
   'OrderBy' not found.  Are you missing a reference to 'System.Core.dll' or a 
   using directive for 'System.Linq'

我已经检查过,System.Core位于references文件夹中,文件中有一个using System.Linq;语句。

任何人都知道为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

将此添加到您的代码

using System.Xml.Linq;
相关问题