本文介绍了LINQ to XML:查询主体必须以select子句或group子句结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以指导我修复此查询上的错误吗?
Can someone guide me on to repairing the error on this query :
var objApps = from item in xDoc.Descendants("VHost")
where(from x in item.Descendants("Application"))
select new clsApplication
{
ConnectionsTotal = item.Element("ConnectionsTotal").Value
};
它显示一个编译器错误查询主体必须以select子句或group子句结尾".我要去哪里错了?
It displays a compiler error "A query body must end with a select clause or a group clause". Where am I going wrong?
非常感谢您的帮助.
谢谢.
这是我的XML(这里没有关闭标签)...我需要应用程序内部的connectioncount值.
Edit : Here is my XML(haven't closed the tags here)...I need the connectioncount values inside the Application..
- <Server>
<ConnectionsCurrent>67</ConnectionsCurrent>
<ConnectionsTotal>1424182</ConnectionsTotal>
<ConnectionsTotalAccepted>1385091</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>39091</ConnectionsTotalRejected>
<MessagesInBytesRate>410455.0</MessagesInBytesRate>
<MessagesOutBytesRate>540146.0</MessagesOutBytesRate>
- <VHost>
<Name>_defaultVHost_</Name>
<TimeRunning>5129615.178</TimeRunning>
<ConnectionsLimit>0</ConnectionsLimit>
<ConnectionsCurrent>67</ConnectionsCurrent>
<ConnectionsTotal>1424182</ConnectionsTotal>
<ConnectionsTotalAccepted>1385091</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>39091</ConnectionsTotalRejected>
<MessagesInBytesRate>410455.0</MessagesInBytesRate>
<MessagesOutBytesRate>540146.0</MessagesOutBytesRate>
- <Application>
<Name>TestApp</Name>
<Status>loaded</Status>
<TimeRunning>411642.953</TimeRunning>
<ConnectionsCurrent>11</ConnectionsCurrent>
<ConnectionsTotal>43777</ConnectionsTotal>
<ConnectionsTotalAccepted>43135</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>642</ConnectionsTotalRejected>
<MessagesInBytesRate>27876.0</MessagesInBytesRate>
<MessagesOutBytesRate>175053.0</MessagesOutBytesRate>
推荐答案
编译器抱怨这部分
from x in item.Descendants("Application")
在Where
子句中的
.您应该对其进行更改,以便
inside your Where
clause. You should change it so that
- 最后有一个
select
子句, - 它构成一个表达式,对于要保留的
item
个对象,其计算结果为true
.
- there is a
select
clause at the end, and - it makes up an expression that evaluates to
true
foritem
objects that you would like to keep.
这是我对您要执行的操作的最佳猜测(尝试第二次)
Here is my best guess at what you are trying to do (EDIT : attempt number two)
var objApps = from item in xDoc.Descendants("VHost").Descendants("Application")
select new clsApplication {
ConnectionsTotal = item.Element("ConnectionsTotal").Value
};
这篇关于LINQ to XML:查询主体必须以select子句或group子句结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!