那是因为你的
log
变量包含的集合
BillingLog
对象,而不是
BillingItem
. 你必须做如下的事情:
foreach( BillingLog l in log )
{
foreach( BillingItem item in l.items )
{
Console.WriteLine( ... );
}
}
或者,如果您最初的目的是选择全部
比林项
S,无视父母
广告日志
完全可以这样重写查询:
var log =
from l in xdoc.Elements("BillingLog")
from j in l.Descendants("BillingItem")
select new BillingItem
{
Date = (string)j.Element("date-and-time"),
ApplicationName = (string)j.Element("application-name"),
Severity = (string)j.Element("severity"),
ProcessId = (int)j.Element("process-id"),
Description = (string)j.Element("description"),
Detail = (string)j.Element("detail")
}
这会给你一个简单的收藏
BillingItems
从“全部”下选择
广告日志
S,而
广告日志
S本身将被完全丢弃。