title: Linq to XML: create an anonymous object with element attributes and values
body: <p>I'm new to Linq and I'm trying to query a XML document to find a list of account managers for a particular user. (I realize it might make more sense to put this in a database or something else, but this scenario calls for a XML document).</p>
  
  <pre><code>&lt;user emailAddress='user@fabrikam.com'&gt;
      &lt;accountManager department='Customer Service' title='Manager'&gt;manager@fabrikam.com&lt;/accountManager&gt;
      &lt;accountManager department='Sales' title='Account Manager'&gt;manager@fabrikam.com&lt;/accountManager&gt;
      &lt;accountManager department='Sales' title='Account Manager'&gt;manager@fabrikam.com&lt;/accountManager&gt;
  &lt;/user&gt;
  </code></pre>
  
  <p>I trying to create a list of objects (anonymous type?) with properties consisting of both XElement attributes (department, title) and values (email). I know that I can get either of the two, but my problem is selecting both. </p>
  
  <p>Here is what I'm trying:</p>
  
  <pre><code>var managers = _xDoc.Root.Descendants("user")
                 .Where(d =&gt; d.Attribute("emailAddress").Value == "user@fabrikam.com")
                 .SelectMany(u =&gt; u.Descendants("accountManager").Select(a =&gt; a.Value));
  
  foreach (var manager in managers)
  {
       //do stuff
  }
  </code></pre>
  
  <p>I can get at <code>a.Value</code> and <code>a.Attribute</code> but I can't figure out how to get both <em>and</em> store them in an object. I have a feeling it would wind up looking something like:</p>
  
  <pre><code>select new { 
      department = u.Attribute("department").Value,
      title = u.Attribute("title").Value,
      email = u.Value
  };
  </code></pre>