I want to add a distinct to the code below. I cannot figure out the exact syntax. Thanks in advance.
var testdates = (from o in db.FMCSA_ME_TEST_DATA
orderby o.DATE
select new
{
RequestDate = o.DATE
});
Use the Distinct()
extension method.
Note that Distinct()
may negate the existing orderby
(I've noticed this in LINQ to SQL), so you may want to use the OrderBy()
method afterwards.
var testdates = (from o in db.FMCSA_ME_TEST_DATA
select new
{
RequestDate = o.DATE
}).Distinct().OrderBy(x => x.RequestDate);
var testdates = (from o in db.FMCSA_ME_TEST_DATA
orderby o.DATE
select new
{
RequestDate = o.DATE
}).Distinct();
The trick is to wrap your query in parenthesis so you can call the distinct method, which you already did, so all you needed was to tack on the method call at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With