【问题标题】:Question about Linq to xml from a tutorial I am following我正在关注的教程中关于 Linq to xml 的问题
【发布时间】:2011-04-06 17:30:30
【问题描述】:

我关注 this tutorial

var groups = from sharePointGroup in groupsXml.Root.Elements("Group")

                select new

                {

                    Name = sharePointGroup.Attribute("Name").Value,

                    Owner = sharePointGroup.Attributes("Owner").Any() ? sharePointGroup.Attribute("Owner").Value : null,

                    Description = sharePointGroup.Attributes("Description").Any() ? sharePointGroup.Attribute("Description").Value : string.Empty,

                    PermissionLevel = sharePointGroup.Attributes("PermissionLevel").Any() ? sharePointGroup.Attribute("PermissionLevel").Value : null,

                    Users = sharePointGroup.Elements("User").Any() ? sharePointGroup.Elements("User") : null

                };

他们有这个:groupsXml.Root.Elements("Group") 但是当我尝试这样做时,我得到一个错误

错误 3 找不到 查询模式的实现 对于源类型 'System.Collections.Generic.IEnumerable'。 未找到“选择”。你错过了一个 引用“System.Core.dll”或 使用“System.Linq”指令

当我查看我的参考资料时,我看不到 System.Linq(仅 System.Xml.Linq;和 SharePoint.linq)

当我查看 msdn 时,我发现它接受的是“Xname”而不是字符串

【问题讨论】:

  • 在 System.Linq 的类文件的顶部有 using 语句吗?使用 System.Linq;

标签: xml linq sharepoint sharepoint-2010 linq-to-xml


【解决方案1】:
  1. Xname 有一个接受字符串的构造函数,所以这是正确的。
  2. 如果没有using System.Linq;,则需要添加。
  3. 您不需要为您的项目添加任何引用。命名空间System.Linq 在System.Core.dll 程序集中定义,默认引用。

【讨论】:

  • 别担心,必须等到我被允许将答案标记为“答案”
猜你喜欢
  • 2011-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多