title: Select all distinct values of variable in object array using lambda expression
body: <p>I have an array of objects with the property of <code>ProductId</code>. I would like to use a lambda expression to select all the distinct values of <code>ProductId</code> that are within my object array <code>products</code>.</p>
  
  <p>Here I get the products</p>
  
  <pre><code>var products = Database.SqlQuery&lt;StructuredProduct&gt;("query").ToArray();
  </code></pre>
  
  <p>And I can group by distinct values of ProductId, but it still returns an array of objects, rather than an array of ProductIds</p>
  
  <pre><code>var productIds= products.GroupBy(p =&gt; p.ProductId).Select(group =&gt; group.First()).ToArray();
  </code></pre>
  
  <p>Any idea on how to use a Lambda Expression on the <code>products</code> array to get all distinct values of <code>ProductIds</code>?</p>