title: How to get only unique nodes from a collection - IEnumerable<XNode>
body: <p>I'm querying a XML column in a SQL database from code behind in C#. I'm trying to get a list of only unique nodes.</p>
  
  <p>In the table, there's many ItemCodes(PK) each with a corresponding <code>ItemAttribute</code> which is the XML type column. </p>
  
  <p>Say there's 10 rows and 3 nodes in the XML document. I get 30 results from the method I use below. I only want unique nodes returned, but because there's unique data in each node, I get any number of results returned depending on the uniqueness of a value in a node.</p>
  
  <pre><code>var data = (from x in Ctx.ItemAttributeDatas 
              select x).ToList();
  
  var xml = from x in data
            where x.AttributeData.Descendants() != null
            select x.AttributeData as XElement;
  
  IEnumerable&lt;XNode&gt; nodes = (from x in xml.Nodes()
                              select x);
  </code></pre>
  
  <p>How can this be done? I tried using <code>.Distinct()</code> but problem as above had same results.</p>
  
  <p>Also, is there a cleaner way I can get the data to xml to nodes?</p>