title: How can i check if this XElement is not null before adding it to an anonymous object?
body: <p>I'm populating an anonymous object from an XML file. Up until now,</p>
  
  <p><code>commentary.Elements("Commentator")</code> </p>
  
  <p>has always had a value so i've never had to check for null. I've had to remove that though, and now it's failing when it tries to read that line.</p>
  
  <p>I'm looking at the code and I don't know what to change though, because its being selected into a property of an anonymous object.</p>
  
  <pre><code>var genericOfflineFactsheet = new
      {
          Commentary = (from commentary in doc.Elements("Commentary")
                        select new
                        {
                            CommentaryPage = (string)commentary.Attribute("page"),
                            BusinessName = (string)commentary.Attribute("businessName"),
                            Commentator = (from commentator in commentary.Elements("Commentator")
                                           select new CommentatorPanel // ASP.NET UserControl
                                           {
                                               CommentatorName = (string)commentator.Attribute("name"),
                                               CommentatorTitle = (string)commentator.Attribute("title"),
                                               CommentatorCompany = (string)commentator.Attribute("company")
                                           }).FirstOrDefault()
                        }).FirstOrDefault()
  </code></pre>
  
  <p>The thing is, I can't completely remove the line because sometimes <code>commentary.Elements("Commentator")</code> <em>does</em> have a value. I'm sure this issue has been dealt with before, but I can't see what to do. Any ideas?</p>