title: C# LINQ query from datatable
body: <p>I'm trying to implement a LINQ query on a search page we're working with.  The data coming back from the initial query  is laid out as follows:</p>
  
  <pre><code>ListID ListName TagId TagValue
  1      Name1    1     Tag1
  1      Name1    2     Tag2
  2      Name2    3     Tag3
  </code></pre>
  
  <p>Basically the lists are search categories and the tags are search terms.  What I'm trying to do is bring back this list, separate it into unique lists, and then display the related tags on the page.  </p>
  
  <p>I have the data loaded into a dataTable, now I'm trying to get the list names into my SearchCategories object:</p>
  
  <pre><code>public class SearchCategories
  {
      public int SearchCategoryId { get; set; }
  
      public string SearchCategoryName { get; set; }
  
      public SearchTags searchTags { get; set; }
  
      public List&lt;SearchTags&gt; lstSearchTags= new List&lt;SearchTags&gt;();
  }
  </code></pre>
  
  <p>and the SearchTag class:</p>
  
  <pre><code>public class SearchTags
  {
      public int SearchTagId { get; set; }
  
      public string SearchTagValue { get; set; }
  }
  </code></pre>
  
  <p>and then the tags into the object's related list.  </p>
  
  <p>Here's the code I'm working with:</p>
  
  <pre><code>dtLists.Load(reader);
  
  var distinctValues = dtLists.AsEnumerable()
     .Select(row =&gt; new SearchCategories
     {
     SearchCategoryId = row.Field&lt;int&gt;("ListNameID"),
     SearchCategoryName = row.Field&lt;string&gt;("listName")
     })
     .Distinct();
  </code></pre>
  
  <p>Newer to LINQ but think this should be easier.  Thanks in advance.</p>