title: Datatable to XML using LINQ
body: <p>I am writing a method to convert datatable using LINQ. I was able to get straight forward conversion from datatable to XML as below:</p>
  
  <pre><code>XDocument doc = new XDocument(new XDeclaration("1.0","UTF-8","yes"),
     new XElement("pfolios", from p in dt.AsEnumerable()
      select new XElement("pfolio",
          new XAttribute("ID", p.ID), 
          new XAttribute("Date", p.Date),
          new XAttribute("Expired", p.Expiry))));
  </code></pre>
  
  <p>but I  need some help to write a method, that takes datatable with any number of columns as input and write to xml something like this: This lamdba expression does not work but I am looking for a way to simplify this. Thanks in advance for your help</p>
  
  <pre><code>  XElement xe = new XElement("pfolios", from p in dt.AsEnumerable()
               select new XElement("pfolio",dt.AsEnumerable().ToList().ForEach(dc=&gt; dt.Columns) 
  new XAttribute(dc.ColumnName, p[dc.ColumnName])));
  </code></pre>