Linq to XML,其中值为 null
我的代码有一些问题,
public IQueryable<PageItems> GetPageById(Guid Id)
{
var xml = Utility.LoadXmlFile("Pages/" + Id);
var q = (from f in xml.Descendants("Page")
where (Guid)f.Element("id") == Id
select new PageItems
{
Title = f.Element("Title").Value,
Content = f.Element("Content").Value,
PublishDate = f.Element("PublishDate").Value,
}).AsQueryable();
return q;
}
我收到此错误:
Value cannot be null.
Parameter name: element
Line 63: where (Guid)f.Element("id") == Id
xml 文件:
<Page id="235487c9-f706-4550-831e-cc504e99d3c5">
<Title>Test</Title>
<Content>Test</Content>
<PublishDate>Test</PublishDate>
<Url>about/contact</Url>
</Page>
I have some problem with my code
public IQueryable<PageItems> GetPageById(Guid Id)
{
var xml = Utility.LoadXmlFile("Pages/" + Id);
var q = (from f in xml.Descendants("Page")
where (Guid)f.Element("id") == Id
select new PageItems
{
Title = f.Element("Title").Value,
Content = f.Element("Content").Value,
PublishDate = f.Element("PublishDate").Value,
}).AsQueryable();
return q;
}
I get this error:
Value cannot be null.
Parameter name: element
Line 63: where (Guid)f.Element("id") == Id
The xml file:
<Page id="235487c9-f706-4550-831e-cc504e99d3c5">
<Title>Test</Title>
<Content>Test</Content>
<PublishDate>Test</PublishDate>
<Url>about/contact</Url>
</Page>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已要求提供 id 元素,但您需要属性:
将其作为
IQueryable
返回的任何原因,由方式?You've asked for the id element, but you want the attribute:
Any reason for returning it as an
IQueryable<T>
, by the way?