2011-06-30 161 views
1

我試圖使用linq從XML文件中提取名稱列表中MVC3工作。中的LINQ MVC抱怨缺少引用

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是在引用文件夾並沒有在文件中using System.Linq;聲明。

任何人都知道爲什麼發生這種情況?

回答

1

添加到您的代碼

using System.Xml.Linq; 
相關問題