Distinct List of ShortDates from Linq Query?
Posted: Mon 13 Feb 2012 15:10
I need to fill a dropdown with a distinct list of ShortDates from a Linq query to an Oracle table but I haven't quite got it. Here's what I have come up with so far:
This first part gives me a list of distinct DateTimes down to the minute and second which is more detail than I want.
Then this second part gives me a list of short dates but they are not distinct and I'm not finding where and how to get that distinct list.
Could someone please help a nube with the correct syntax for what seems like it should be a fairly common need?
Thanks!
This first part gives me a list of distinct DateTimes down to the minute and second which is more detail than I want.
Code: Select all
var dates = (from those in db.RTPCR_CNDATs
select those.UPLOADDATE).Distinct().OrderByDescending(d => d.Value).AsQueryable();
Returns:
...
{1/24/2012 12:54:15 PM}
{1/24/2012 12:54:14 PM}
{1/18/2012 3:50:56 PM}
{1/18/2012 3:50:55 PM}
... etc.
Then this second part gives me a list of short dates but they are not distinct and I'm not finding where and how to get that distinct list.
Code: Select all
var dateResults = from d in dates.ToList()
select new { d.Value }.Value.ToShortDateString();
Returns:
...
"1/24/2012"
"1/24/2012"
"1/18/2012"
"1/18/2012"
... etc.
Thanks!