I have following expression
var list = techlinks.GetItems().Where(p => p.Status == 1).ToList();
I want to change this so that I want to select the earliest date value for example
var list = techlinks.GetItems().Where(p =>p.Date is earliest && p.Status == 1).ToList();
Please let me know what to insert for p.Date is earliest
Thanks
Here's another way.
It slightly depends on what
GetItems()
oftechLinks
does, but something like that should work:If
GetItems()
method actually hits the database, you can store its result first and use it twice:If there might be multiple items all with the earliest date:
you can use
OrderBy
orOrderByDescending()
to sort them on Date this way:and:
If you only want 1 you could go with
otherwise I'd break it up into two statements
also be aware of how your dates are inserted, DateTime.Now will add time components so might have to do something gnarly like this