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

前端 未结 6 1157
广开言路
广开言路 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:16

    I like the procedural way of linq which can be more linear in its approach; I believe you want

    var result =   xDoc.Descendants("VHost")
                       .Descendants("ConnectionsTotal")
                       .Select(ele => ele.Value )
                       .Select( value => new clsApplication
                               {
                                   ConnectionsTotal = value
                               })
                             ;
    

    --- Test in LinqPad ---

    string xml = @"
    
    
      67 
      1424182 
      1385091 
      39091 
      410455.0 
      540146.0 
     
     
      _defaultVHost_ 
      5129615.178 
      0 
      67 
      1424182 
      1385091 
      39091 
      410455.0 
      540146.0 
     
     
      TestApp 
      loaded 
      411642.953 
      11 
      43777 
      43135 
      642 
      27876.0 
      175053.0
      ";
    
    
      var XDoc = XDocument.Parse(xml);
    
      XDoc.Descendants("VHost")
          .Descendants("ConnectionsTotal")
          .Select (ele => ele.Value )
          .Dump();  
    

提交回复
热议问题