title: Entity framework distinct but not on all columns
body: <p>I'd like to make a query through entity framework that unions contacts from two different tables, remove duplicates and orders by date. The issue I'm having is around the different dates making the same contact appear as unique. I don't want to include the date in the distinct but I do need it afterwards for the ordering. I can't do the ordering first, remove the date and then perform the distinct, because the distinct changes the ordering. Neither can I order before the union because that doesn't ensure ordering after the union.</p>
  
  <p>I would like to distinct all fields except the date, which is only required for the ordering.</p>
  
  <p>Ideally I would pass a comparer to the distinct but EF can't translate this to SQL.</p>
  
  <pre><code>db.Packages.Select(p =&gt; new Recent()
  {
      Name = p.Attention, Address1 = p.Address1, ... , Date = ShippingDate
  })
  .Concat(db.Letters.Select(l =&gt; new Recent()
  {
      Name = l.AddressedTo, Address1 = p.Address1, ..., Date = MarkedDate
  })
  .Distinct()
  .OrderByDescending(r =&gt; r.Date);
  </code></pre>
  
  <p>OR the problem in SQL</p>
  
  <pre><code>SELECT DISTINCT Attention, Address1, ShippingDate
  FROM Packages
  UNION ALL
  SELECT AddressedTo, Address1, MarkedDate
  FROM Letters
  ORDER BY ShipmentDate DESC
  </code></pre>