如何正确编写 WHERE 子句?

How can I correctly write the WHERE clause?

我有一个 XML 文件,其结构如下:

<root>
   <State state="AZ" stateName="Arizona" stateKey="Arizona" >
      <menuVirtualPageName>Arizona.html</menuVirtualPageName>
      <Region regionKey="GreaterPhoenix" >
         <pageName>Phoenix.html</pageName>
      </Region>
   </State>
</root>

我一直在尝试 select 一个状态,使用 regionKey 值。鉴于我已经有了 "thisState" 的正确值,我编写了以下 Linq 查询

Dim stateQuery = (From dataStates In dataStatesXML...<Region> Where dataStatesXML...<State>.@stateKey = thisState Select New With {.virtualPageName = dataStates.<menuVirtualPageName>.Value.ToString(), .stateName = dataStates.@stateName.ToString()})

但我总是得到一个空的查询结果:(非常感谢任何想法或建议!!!

试试这个:-

Dim state As String = (From x In xdoc.Descendants("Region") _
                    Where x.Attribute("regionKey").Value = "GreaterPhoenix" _
                    Select x.Parent.Attribute("state").Value).FirstOrDefault()

我得到 AZ 作为输出。

编辑:

刚刚注意到您还想获取 stateNamevirtualPageName,这是针对该问题的查询:-

Dim result = (From x In xdoc.Descendants("Region") _
   Where x.Attribute("regionKey").Value = "GreaterPhoenix"
   Select New With {.virtualPageName = x.Parent.Element("menuVirtualPageName").Value, _
                    .stateName = x.Parent.Attribute("stateName").Value}).ToList()