title: C# Output XML from Linq to Response.OutputStream
body: <p>Is there a simpler way to output a Linq to SQL table to XML (eventually to a web page?)  Unfortunately, I am not using MVC, but I could put a reference to it in my aspx C# page.</p>
  
  <p>I have this:</p>
  
  <pre><code>var myView = (from x in db.myTable 
                where x.Name.Contains("Bob") 
                select new person {Name = x.Name, Job = x.Job).Take(100);
  </code></pre>
  
  <p>and want to output something similar to this (doesn't have to be exact for now):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; 
  &lt;myView xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; 
      &lt;person&gt;&lt;Name&gt;Bob Smith&lt;/Name&gt;&lt;Job&gt;Machinist&lt;/Job&gt;&lt;/person&gt;
      &lt;person&gt;&lt;Name&gt;Bob Smithers&lt;/Name&gt;&lt;Job&gt;Cartoonist&lt;/Job&gt;&lt;/person&gt;
      &lt;person&gt;&lt;Name&gt;Rebob Wilson&lt;/Name&gt;&lt;Job&gt;Mason&lt;/Job&gt;&lt;/person&gt;
  &lt;/myView&gt; 
  </code></pre>
  
  <p>I tried doing this:</p>
  
  <pre><code>TextWriter myTW = new StreamWriter( Response.OutputStream, Encoding.UTF8);
  XmlTextWriter xmlTW = new XmlTextWriter(myTW);
  XmlSerializer myS = new XmlSerializer( typeof( person));
  myS.Serialize( xmlTW, myView);
  </code></pre>
  
  <p>But I get a "Cannot serialize iQueryable".  However, I tried ToArray, ToList, AsEnumerable, etc. and simply get "An error occured" with myS.Serialize().</p>
  
  <p>Any thoughts?  Hopefully there is a way like return XML(myView);</p>