title: Build Linq query in umbraco
body: <p>I am building a web service in C# using Umbraco's uQuery that takes 2 parameters and returns a JSON serialized string containing a list of search results.</p>
  
  <p>I pass in a string array containing the tags for my search e.g. ["red", "blue"]</p>
  
  <pre><code>public string GetResultsHttp(string[] tags)
  {
      IEnumerable&lt;Node&gt; nodes;
  
      // first get all nodes that are of the right content type
      nodes = uQuery.GetNodesByType("MyPage");
  
      // if tags are passed in then limit the results to those tags
      if (tags.Length &gt; 0)
      {
          nodes = nodes.Where(n =&gt; tags.Contains(n.Parent.GetProperty("tags").Value));
      }
  
      // return the node list as a serialized string
  
  }
  </code></pre>
  
  <p>So far so good and that works to return results that contain any of my tags.</p>
  
  <p>now I want to limit the results by date. The dates array looks like this ["201410", "201411"] so it's year followed by month.</p>
  
  <p>I want to further limit my result set to those results that have a myDate property where the month and year matches any of the months and years in my date array.</p>
  
  <p>So my code becomes this:</p>
  
  <pre><code>public string GetResultsHttp(string[] tags, string[] dates)
  {
      IEnumerable&lt;Node&gt; nodes;
  
      // first get all nodes that are of the right content type
      nodes = uQuery.GetNodesByType("MyPage");
  
      // if tags are passed in then limit the results to those tags
      if (tags.Length &gt; 0)
      {
          nodes = nodes.Where(n =&gt; tags.Contains(n.Parent.GetProperty("tags").Value));
      }
  
      if (dates.Length &gt; 0)
      {
          // the format of the incoming date
          string formatString = "yyyyMM";
  
          foreach (string dateTag in dates)
          {
              DateTime dt = DateTime.ParseExact(dateTag, formatString, null);
              nodes = nodes.Where(n =&gt; (dt.Month.Equals(n.GetProperty&lt;DateTime&gt;("myDate").Month)) &amp;&amp; (dt.Year.Equals(n.GetProperty&lt;DateTime&gt;("myDate").Year)));
          }
      }
  
      // return the node list as a serialized string
  
  }
  </code></pre>
  
  <p>The above obviously works fine for 1 date, but if I pass in 2 it stands to reason that one page can't have 2 dates.</p>
  
  <p>Also, I'm sure there is a much simpler way of achieving this :)</p>
  
  <p>Thanks
  Travis</p>