Select Xml Node using Linq to XML

前端 未结 4 1501
遥遥无期
遥遥无期 2020-12-19 07:40

my Xml file :




        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 08:09

    Your problem is that Descendents and Where return an IEnumerable not a single XElement which is what you're after. You can fix this like this:

    XElement toEdit = doc.Descendants("ArrayOfCustomer")
                         .Descendants("Customer")
                         .Where(x => Guid.Parse(x.Descendants("CustomerId").Single().Value) == customer.CustomerId)
                         .FirstOrDefault();
    

提交回复
热议问题