title: Linq to Entities Select clause with lambda
body: <p>I am working on a new project and we are using Entity Framework and the dev lead would like to use lambda queries whenever possible.  One thing we are having a hard time figuring out is how to select two columns specifically.  Also how to select distinct.  We have a table that has multiple entries for a vendor but we want to just get a list of vendors and load to a dictionary object.  It fails because as written it is trying to add a key value that has already been added.  Take the following query.  </p>
  
  <pre><code>Dictionary&lt;int, string&gt; dict = new Dictionary&lt;int, string&gt;();
          dict = GetWamVendorInfo().AsEnumerable()
                      .Where(x =&gt; x.vendor_name != null &amp;&amp; x.vendor_id != null)
                      //.Select(x =&gt; x.vendor_id).Distinct()
                      .Take(2)
                      .ToDictionary(o =&gt; int.Parse(o.vendor_id.ToString()), o =&gt; o.vendor_name);
  </code></pre>
  
  <p>What I would like to do is select just vendor_id and vendor_name so we can get just the distinct records.  </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks,</p>
  
  <p>Rhonda</p>