MVC 中的 Linq 抱怨缺少引用

发布于 2024-11-18 00:05:42 字数 734 浏览 3 评论 0原文

我正在尝试使用 linqMVC3 中从 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 位于引用文件夹中,并且文件中有一个 using System.Linq; 语句。

有谁知道为什么会发生这种情况?

I'm trying to work in MVC3 using linq to extract a list of names from an XML file.

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

The compiler keeps complaining:

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'

I've checked and the System.Core is in the references folder and there is a using System.Linq; statement in the file.

Anyone know why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-11-25 00:05:42

将其添加到您的代码中

using System.Xml.Linq;

add this to your code

using System.Xml.Linq;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文