LINQ to XML : A query body must end with a select clause or a group clause

前端 未结 6 1129
广开言路
广开言路 2021-01-20 01:31

Can someone guide me on to repairing the error on this query :

       var objApps = from item in xDoc.Descendants(\"VHost\") 
                          where         


        
6条回答
  •  花落未央
    2021-01-20 02:11

    The compiler is complaining about this part

    from x in item.Descendants("Application")
    

    inside your Where clause. You should change it so that

    • there is a select clause at the end, and
    • it makes up an expression that evaluates to true for item 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
                  };
    

提交回复
热议问题